LSOF

Section: Maintenance Commands (8)
Updated: PUCC
Index Return to Main Contents
 

NAME

lsof - list open files  

SYNOPSIS

lsof [ -d ] [ -h ] [ -l ] [ -n ] [ -N ] [ -p l ] [ -s ] [ -t ] [ -u l ] [ -U ] names  

DESCRIPTION

Lsof lists information about files opened by processes for the following operating systems:

        AIX 3.1.3, 3.1.5 and 3.1.7 for the IBM RISC/System 6000
        Dynix 3.0.12 and 3.1.2 for the Sequent Symmetry S81
        HP-UX 7.x for the Hewlett Packard 9000/300 and 9000/800
        HP-UX 8.x for the Hewlett Packard 9000/300, 9000/700 and 9000/800
        NeXTStep 2.0 and 2.1 for the NeXT Work Station
        SunOS 4.1.1

An open file may be a regular file, a directory, a character special file, or a network file (Internet socket, NFS file or Unix domain socket.) A specific file may be selected by its path name.  

OPTIONS

In the absence of any options, lsof lists all open files belonging to all active processes.

If any list request option is specified, all other lists must be specifically requested - e. g., if -n is specified for the listing of Internet network files, NFS files won't be listed unless -N is also specified; or if a user list is specified with the -u option, Internet network files and Unix domain socket files belonging to users not in the list won't be listed unless the -n and -U options are also specified.

-d
This option selects the production of error messages about unreadable subdirectories of the /dev directory. Under SunOS, for example, the /dev/lpd subdirectory is unreadable for security reasons. When building its cache of names and device numbers for devices, lsof skips unreadable subdirectories silently unless -d is specified.
-h
This option selects a brief usage (help) output list.
-l
This option inhibits the conversion of user ID numbers to login names.
-n
This option selects the listing of Internet network files.
-N
This option selects the listing of NFS files.
-p l
This option selects the listing of files for the processes whose ID numbers are in the comma-separated list `l' - e. g., ``123'' or ``123,456''. (There should be no spaces in the list.)
-s
This option removes the SIZE column from the output, shortening output lines by nine characters.
-t
This option specifies that lsof should produce terse output with process identifiers only and no header - e. g., so that the output may be piped to kill(1).
-u l
This option selects the listing of files for the user whose login names or user ID numbers are in the comma-separated list `l' - e. g., ``abe'', or ``548,root''. (There should be no spaces in the list.)
-U
This option selects the listing of Unix domain socket files.
names
These are path names of specific files to list. Symbolic links are resolved before use.
If a name is the mount point of a file system or the device of the mount point of a file system, lsof will list all the files open on the file system. If a name is the base name of a family of multiplexed files - e. g, AIX's /dev/pts - lsof will list all the associated multipled files on the device that are open - e. g., /dev/pts/1, /dev/pts/2, etc.
If a name is none of the above, lsof will list any open files whose device and inode match that of the specified path name.
 

OUTPUT

Lsof lists for each open file:
COMMAND
contains the first nine characters of the name of the Unix command associated with the process.
PID
is the Process IDentification number of the process.
USER
is the user ID number or login name of the user to whom the process belongs. (See the -l option.)
FD
is the File Descriptor number of the file or ``cwd'' if it is the current working directory of the process. FD is followed by these characters for file locks:
       r for read lock on part of the file;

       R for a read lock on the entire file;

       w for a write lock on part of the file;

       W for a write lock on the entire file.
TYPE
is the type of the vnode associated with the file (see <sys/vnode.h>);
or ``inet'' for an Internet domain socket;
or ``unix'' for a Unix domain socket.
DEVICE
contains the major and minor device numbers for a character special, block special, regular, directory or NFS file (an HP-UX minor device number is listed in hexadecimal);
or the protocol control block address of a Unix or Internet domain file (the number that appears in netstat(1)'s -A output).
SIZE
is the size of the file in bytes, when it is known. This column may be removed from the output by specifying the -s option.
INODE
is the inode number of a local file;
or the inode number of an NFS file in the server host;
or the Internet protocol type - e. g, ``TCP''.
NAME
is the name of the mount point and file system on which the file resides;
or the name of a file specified in the names option (after any symbolic links have been resolved);
or the name of a character special or block special device;
or the local and remote Internet addresses of a network file;
or the address of a Unix domain socket;
or the local and remote mount point names of an NFS file.
 

DIAGNOSTICS

Errors are identified with messages on the standard error file.

Lsof returns a one (1) if any error was detected, including the failure to locate any names. It returns a zero (0) if no errors were detected and if it was able to list information about all the specified names.  

EXAMPLES

To list all open files, use:
lsof

To list all open Internet and Unix domain files, use:

lsof -n -U

To list all open files for login name ``abe'', user ID 1234, process 123, process 456 and process 789, use:

lsof -p 789,456,123 -u 1234,abe

To list all open files on device /dev/hd4, use:

lsof /dev/hd4

To find the process that has /u/abe/foo open, use:

lsof /u/abe/foo

To send a SIGHUP to the processes that have /u/abe/bar open, use:

kill -HUP `lsof -t /u/abe/bar`
 

BUGS

Since lsof reads kernel memory in its search for open files, rapid changes in kernel memory may produce unpredictable results.

Absence of hardware or software configurations for some operating systems - e. g., HP-UX 7.x and 8.x and Sequent Dynix 3.1.2 - means that lsof has not been fully tested on them.

The lock status character (following the file descriptor) is derived under AIX from a test of only the first filock structure of the gnode (see <sys/flock.h> and <sys/gnode.h>).

Lsof can't search for any file by name unless it is installed with root set-UID permission. Otherwise it is restricted to searching for files to which its user or its set-GID group (if any) have access.

Lsof startup time is long on systems where scanning the /dev directory is a slow operation.

Output lines are sometimes greater than eighty characters - e. g., for completed Internet connections or NFS files - causing the output listing to be irregularly spaced. The -s option may be specified to remove the SIZE column, shortening output lines by nine characters.

If there are files or subdirectories in /dev that lsof can't stat(2) or read, it will ignore them without complaint, unless the -d option is selected. Whether lsof complains or not, it is unable to report major and minor device numbers for the entries it can't access.  

FILES

/dev/drum      system paging device
/dev/kmem      kernel virtual memory device
/dev/mem       physical memory device
/dev/swap      system paging device
 

AUTHORS

Lsof was written by Victor A. Abell of the Purdue University Computing Center
(PUCC), based on the fstat and ofiles programs. He acknowledges his debt to the work of Dan Bernstein, Michael ``Ford'' Ditto, Tom Dunigan, Alexander Dupuy, Vik Lall, Ray Moody, C. Spencer, Michael Spitzer and those who wrote Berkeley's fstat program, all contributors to lsof's predecessors. He thanks Doug McKenzie for his HP-UX proctor program and Rich Kulawiec for pointing it out. Finally, he is grateful to Jim Cooper, J. Nelson Howell, Markus Lautenbacher, Wendy Lin, Andreas Luik, Fletcher Mattox, Michael Mackenzie, Jeff Stewart and Patrick Wolfe for their help in developing and improving lsof.  

SEE ALSO

ff(1), fstat(8), fuser(1), kill(1), netstat(1), ofiles(8L), ps(1). lsof.8


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
OUTPUT
DIAGNOSTICS
EXAMPLES
BUGS
FILES
AUTHORS
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 06:20:09 GMT, December 12, 2024