lsof (LiSt Open Files) is to me undoubtedly the greatest UNIX/Linux command ever.
Use it to easily see which files, directories, and sockets your running processes are 
holding open.
e.g.
Have you ever tried to umount a file system, only to find that some process was still 
using it?

[EMAIL PROTECTED]: ~# umount  /mnt
umount : /mnt : device is busy

To hunt down what processes are still using /mnt try the lsof tool:

[EMAIL PROTECTED]: ~# lsof  /mnt
COMMAND  PID    USER   FD   TYPE DEVICE SIZE  MODE NAME 
bash    30951  sekidde cwd  DIR    7,0  1024   2   /mnt

Apparently sekidde is cd’d to  /mnt (since his bash process has set it as its cwd).

lsof will open files, directories, libraries, sockets and devices associated with a 
particular process.

To show files associated with a PID use the – p switch

[EMAIL PROTECTED]: ~# lsof  -p 30563

To specify the process by name; use – c

[EMAIL PROTECTED]: ~# lsof  -c syslogd

To specify devices on the command line. For example let’s see what the users on 
pts/0 is up to

[EMAIL PROTECTED]: ~# lsof  /dev/pts/0

If you need to specify multiple switches, they are ORed with each other by default. To 
require all switches (that is to AND them) include the - a flag on each switch you 
want to AND.

e.g.
To see all of the open files associated with vi process that sekidde is running, try 
this

[EMAIL PROTECTED]: ~# lsof -u sekidde –ac vi 

If you’d like to examine open sockets and their associated process (like a netstat 
–p), try the – i switch

[EMAIL PROTECTED]: ~ # lsof –i

Note
You must be root to run lsof for many functions, including retrieving open sockets 
information. 
lsof is a complex and very flexible tool, giving you as much (or as little) detail as 
you need about what files are in use by every running process in your system.
The latest version of lsof can be downloaded at 
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/


__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455


---------------------------------------------
This service is hosted on the Infocom network
http://www.infocom.co.ug

Reply via email to