Jun 30, 2005

Lsof - LiSt Open File

Lsof lists open files for running UNIX processes.

It has been tested recently on these UNIX dialects:
  • AIX 5.[123]
  • Apple Darwin 7.7.0 for Power Macintosh Systems
  • BSDI BSD/OS 4.3.1 for x86-based systems
  • FreeBSD 4.[2-9], 4.1[01], 5.[012] and 6.0 for x86-based systems
  • FreeBSD 5.[01234] and 6.0 for Alpha, AMD64 and Sparc64 based systems
  • HP-UX 11.00, 11.11 and 11.23
  • Linux 2.1.72 and above for x86-based systems
  • NetBSD 1.[456] and 2.x for Alpha, x86, and SPARC-based systems
  • NEXTSTEP 3.[13] for NEXTSTEP architectures
  • OpenBSD 2.[89] and 3.[0123456] for x86-based systems
  • OpenStep 4.x
  • SCO OpenServer Release 5.0.6 for x86-based systems
  • SCO|Caldera UnixWare 7.1.4 for x86-based systems
  • Solaris 2.6, 8, 9 and 10
  • Tru64 UNIX 5.1

Please download source code from ftp://vic.cc.purdue.edu/pub/tools/unix/lsof

Example of Making Lsof on RedHat9
$ cd lsof_4.75_src
$ ./Configure linux
$ make

Example of Using Lsof
Finding Processes Blocking Umount

When you need to unmount a file system with the umount command,
you may find the operation blocked by a process that has a file
open on the file systems. Lsof may be able to help you find the
process. In response to:

$ lsof

Lsof will display all open files on the named file system. It
will also set its exit code zero when it finds some open files
and non-zero when it doesn't, making this type of lsof call
useful in shell scripts. (See section 16.)

Consult the output of the df command for file system names.

See the caveat in the preceding section about file references
that persist in the kernel without open file traces. That
situation may hamper lsof's ability to help with umount, too.

More example please see 00QUICKSTART, you will know it might be very helpful to you.