lsof [ -?abChKlnNOPRtUvVX ]
[ ±r [t[mfmt ]] ]
[ -A A ] [ -c c ] [ +c c ] [ ±d d ] [ ±D D ] [ ±e s ]
[ ±f [cfgGn] ] [ -F [f] ] [ -g [s] ] [ -i [i] ] [ -k k ] [ ±L [l] ] [ ±m m ] [ ±M ]
[ -o [o] ] [ -p s ] [ -s [p:s] ] [ -S [t] ] [ -T [t] ] [ -u s ] [ ±w ]
[ -x [fl] ] [ -z [z] ] [ -Z [Z] ]
[ -- ] [names]
An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a
library, a stream or a network file (Internet socket, NFS file or UNIX domain socket). (
A specific file or all the files in a file system may be selected by path.
Runs continuously in repeat mode,
By default lists all open files belonging to all active processes.
lsof | more
lsof -i -utonysproduces a listing of all network(internet) files OR those belonging to processes owned by user
^prefix), are applied without ORing or ANDing and take effect before any other selection criteria are applied.
-a ANDs the selections.
lsof -a -unetprgmr -U produces a listing of
files that belong to processes owned by
netprgmr and are UNIX socket files .
Caution: causes all "list selection"s to be ANDed
Items of the same selection set: command names, file descriptors, network addresses, process identifiers, user identifiers, zone
names, security contexts are joined in a single ORed set and applied before the result participates in ANDing.
lsof -email@example.com -firstname.lastname@example.org -a -ume,you will select the listing of files that :
belong to either login
AND have network connections to either host
Grouping options together is permitted following a
- for example:
-a -b -C may be stated as
±f, -F, -g, -i, ±L, -o, ±r, -s, -S, -T, -xand
-Fnmight represent the
-noptions, or it might represent the
nfield identifier character following
--. For example:
-F -- fname.
- prefix may be applied to a group of options.
Options that don't take on separate meanings for each prefix , For example:
-i (which has no + option) may be grouped under either prefix.
+M -i may be stated as
When one or more options in the group does take on separate meanings under different prefixes avoid grouping. FOr example
+M; -iM is not the same as
Use separate options with appropriate prefixes for clarity.
AFS Lsof supports the recognition of AFS files for these dialects (and AFS versions): AIX 4.1.4 (AFS 3.4a) HP-UX 9.0.5 (AFS 3.4a) Linux 1.2.13 (AFS 3.3) Solaris 2. (AFS 3.4a) It may recognize AFS files on other versions of these dialects, but has not been tested there. Depending on how AFS is implemented, lsof may recognize AFS files in other dialects, or may have difficulties recognizing AFS files in the supported dialects. Lsof may have trouble identifying all aspects of AFS files in supported dialects when AFS kernel support is implemented via dynamic modules whose addresses do not appear in the kernel's variable name list. In that case, lsof may have to guess at the identity of AFS files, and might not be able to obtain volume information from the kernel that is needed for calculating AFS volume node numbers. When lsof can't compute volume node numbers, it reports blank in the NODE column. The -A A option is available in some dialect implementations of lsof for specifying the name list file where dynamic module kernel addresses may be found. When this option is available, it will be listed in the lsof help output, presented in response to the -h or -? See the lsof FAQ (The FAQ section gives its location.) for more information about dynamic modules, their symbols, and how they affect lsof options. Because AFS path lookups don't seem to participate in the kernel's name cache operations, lsof can't identify path name components for AFS files.
\[bfrnt]&form; the control character `^' form (e.g.,
^@&); or hexadecimal leading
\xab&). Space is non-printable in the COMMAND column (
\x20&) and printable elsewhere. For some dialects - if HASSETLOCALE is defined in the dialect's machine.h header file - lsof will print the extended 8 bit characters of a language locale. The lsof process must be supplied a language locale environment variable (e.g., LANG) whose value represents a known language locale in which the extended characters are considered printable by isprint(3). Otherwise lsof considers the extended characters non-printable and prints them according to its rules for non-printable characters, stated above. Consult your dialect's setlocale(3) man page for the names of other environment variables that may be used in place of LANG - e.g., LC_ALL, LC_CTYPE, etc. Lsof's language locale support for a dialect also covers wide characters - e.g., UTF-8 - when HASSETLOCALE and HASWIDECHAR are defined in the dialect's machine.h header file, and when a suitable language locale has been defined in the appropriate environment variable for the lsof process. Wide characters are printable under those conditions if iswprint(3) reports them to be. If HASSETLOCALE, HASWIDECHAR and a suitable language locale aren't defined, or if iswprint(3) reports wide characters that aren't printable, lsof con- siders the wide characters non-printable and prints each of their 8 bits according to its rules for non-printable characters, stated above. Consult the answers to the "Language locale support" questions in the lsof FAQ (The FAQ section gives its location.) for more informa- tion. Lsof dynamically sizes the output columns each time it runs, guaranteeing that each column is a minimum size. It also guarantees that each column is separated from its predecessor by at least one space.
namefs&file system, allowing one file to be attached to another with fattach(3C), lsof will add
(FA:to the NAME column.
Lsof may add two parenthetical notes to the NAME column for open Solaris 10 files:
(?)& if lsof considers the path name of questionable accuracy; and
(deleted)& if the -X option has been specified and lsof detects the open file's path name has been deleted.
Consult the lsof FAQ (The FAQ section gives its location.) for more information on these NAME column additions.
Moreover, when a process holds several byte level locks on a file, lsof only reports the status of the first lock it encounters. If it is a byte level lock, then the lock character will be reported in lower case - i.e., `r', `w', or `x' - rather than the upper case equivalent reported for a full file lock.
Generally lsof can only report on locks held by local processes on local files. When a local process sets a lock on a remotely mounted (e.g., NFS) file, the remote server host usually records the lock state. One exception is Solaris - at some patch levels of 2.3, and in all versions above 2.4, the Solaris kernel records information on remote locks in local structures.
Lsof has trouble reporting locks for some UNIX dialects. Consult the BUGS section of this manual page or the lsof FAQ (The FAQ sec- tion gives its location.) for more information.
lsofwill produce output that can be parsed by other programs with
-Fe.g, an awk or Perl script, or a C program.
Each unit of information is output in a field that is identified with a leading character and terminated by a NL (012) (or a NUL (000) if the 0 (zero) field identifier character is specified.) The data of the field follows immediately after the field identification character and extends to the field terminator.
It is possible to think of field output as process and file sets. A process set begins with a field whose identifier is `p' (for process IDentifier (PID)). It extends to the beginning of the next PID field or the beginning of the first file set of the process, whichever comes first. Included in the process set are fields that identify the command, the process group IDentification (PGID) num- ber, the task (thread) ID (TID), and the user ID (UID) number or login name.
A file set begins with a field whose identifier is `f' (for file descriptor). It is followed by lines that describe the file's access mode, lock state, type, device, size, offset, inode, protocol, name and stream module names. It extends to the beginning of the next file or process set, whichever comes first.
When the NUL (000) field terminator has been selected with the 0 (zero) field identifier character, lsof ends each process and file set with a NL (012) character.
Lsof always produces one field, the PID (`p') field. All other fields may be declared optionally in the field identifier character
list that follows the -F option. When a field selection character identifies an item lsof does not normally list - e.g., PPID,
selected with -R - specification of the field character - e.g.,
-FR& - also selects the listing of the item.
It is entirely possible to select a set of fields that cannot easily be parsed - e.g., if the field descriptor field is not selected, it may be difficult to identify file sets. To help you avoid this difficulty, lsof supports the -F option; it selects the output of all fields with NL terminators (the -F0 option pair selects the output of all fields with NUL terminators). For compatibility reasons neither -F nor -F0 select the raw device field.
These are the fields that lsof will produce. The single character listed first is the field identifier.
a file access mode c process command name (all characters from proc or user structure) C file structure share count d file's device character code D file's major/minor device number (0x
) f file descriptor F file structure address (0x ) G file flaGs (0x ; names if +fg follows) g process group ID i file's inode number K tasK ID k link count l file's lock status L process login name m marker between repeated output n file name, comment, Internet address N node identifier (ox o file's offset (decimal) p process ID (always selected) P protocol name r raw device number (0x ) R parent process ID s file's size (decimal) S file's stream identification t file's type T TCP/TPI information, identified by prefixes (the `=' is part of the prefix): QR= QS= SO= (not all dialects) SS= (not all dialects) ST= TF= (not all dialects) WR= (not all dialects) WW= (not all dialects) (TCP/TPI information isn't reported for all supported UNIX dialects. The -h or -? help output for the -T option will show what TCP/TPI reporting can be requested.) u process user ID z Solaris 10 and higher zone name Z SELinux security context (inhibited when SELinux is disabled) 0 use NUL field terminator character in place of NL 1-9 dialect-specific field identifiers (The output of -F? identifies the information to be found in dialect-specific fields.)
You can get on-line help information on these characters and their descriptions by specifying the -F? option pair. (Escape the `?' character as your shell requires.) Additional information on field content can be found in the OUTPUT section.
As an example,
-F pcfn& will select the process ID (`p'), command name (`c'), file descriptor (`f') and file name (`n') fields with
an NL field terminator character;
-F pcfn0& selects the same output with a NUL (000) field terminator character.
Lsof doesn't produce all fields for every process or file set, only those that are available. Some fields are mutually exclusive: file device characters and file major/minor device numbers; file inode number and protocol name; file name and stream identification; file size and offset. One or the other member of these mutually exclusive sets will appear in field output, but not both.
Normally lsof ends each field with a NL (012) character. The 0 (zero) field identifier character may be specified to change the field terminator character to a NUL (000). A NUL terminator may be easier to process with xargs (1), for example, or with programs whose quoting mechanisms may not easily cope with the range of characters in the field output. When the NUL field terminator is in use, lsof ends each process and file set with a NL (012). Three aids to producing programs that can process lsof field output are included in the lsof distribution. The first is a C header file, lsof_fields.h, that contains symbols for the field identification characters, indexes for storing them in a table, and explana- tion strings that may be compiled into programs. Lsof uses this header file. The second aid is a set of sample scripts that process field output, written in awk, Perl 4, and Perl 5. They're located in the scripts subdirectory of the lsof distribution. The third aid is the C library used for the lsof test suite. The test suite is written in C and uses field output to validate the correct operation of lsof. The library can be found in the tests/LTlib.c file of the lsof distribution. The library uses the first aid, the lsof_fields.h header file.
Lsof attempts to break these blocks with timers and child processes, but the techniques are not wholly reliable. When lsof does man- age to break a block, it will report the break with an error message. The messages may be suppressed with the -t and -w options.
The default timeout value may be displayed with the -h or -? option, and it may be changed with the -S [t] option. The minimum for t is two seconds, but you should avoid small values, since slow system responsiveness can cause short timeouts to expire unexpectedly and perhaps stop lsof before it can produce any output.
When lsof has to break a block during its access of mounted file system information, it normally continues, although with less infor- mation available to display about open files.
Lsof can also be directed to avoid the protection of timers and child processes when using the kernel functions that might block by specifying the -O option. While this will allow lsof to start up with less overhead, it exposes lsof completely to the kernel situa- tions that might block it. Use this option cautiously.
First, using this option usually requires that your system supply alternate device numbers in place of the device numbers that lsof would normally obtain with the lstat(2) and stat(2) kernel functions. See the ALTERNATE DEVICE NUMBERS section for more information on alternate device numbers.
Second, you can't specify names for lsof to locate unless they're file system names. This is because lsof needs to know the device and inode numbers of files listed with names in the lsof options, and the -b option prevents lsof from obtaining them. Moreover, since lsof only has device numbers for the file systems that have alternates, its ability to locate files on file systems depends com- pletely on the availability and accuracy of the alternates. If no alternates are available, or if they're incorrect, lsof won't be able to locate files on the named file systems.
Third, if the names of your file system directories that lsof obtains from your system's mount table are symbolic links, lsof won't be able to resolve the links. This is because the -b option causes lsof to avoid the kernel readlink(2) function it uses to resolve sym- bolic links.
Finally, using the -b option causes lsof to issue warning messages when it needs to use the kernel functions that the -b option directs it to avoid. You can suppress these messages by specifying the -w option, but if you do, you won't see the alternate device numbers reported in the warning messages.
You can assist this process if your mount table is supported with an /etc/mtab or /etc/mnttab file that contains an options field by
dev=xxxx& field for mount points that do not have one in their options strings. Note: you must be able to edit the file -
i.e., some mount tables like recent Solaris /etc/mnttab or Linux /proc/mounts are read-only and can't be modified.
You may also be able to supply device numbers using the +m and +m m options, provided they are supported by your dialect. Check the output of lsof's -h or -? options to see if the +m and +m m options are available.
xxxx& portion of the field is the hexadecimal value of the file system's device number. (Consult the st_dev field of the output of the lstat(2) and stat(2) functions for the appropriate values for your file systems.) Here's an example from a Sun Solaris 2.6
/etc/mnttab for a file system remotely mounted via NFS:
There's an advantage to having
dev=xxxx& entries in your mount table file, especially for file systems that are mounted from remote
NFS servers. When a remote server crashes and you want to identify its users by running lsof on one of its clients, lsof probably
won't be able to get output from the lstat(2) and stat(2) functions for the file system. If it can obtain the file system's device
number from the mount table, it will be able to display the files open on the crashed NFS server.
Some dialects that do not use an ASCII /etc/mtab or /etc/mnttab file for the mount table may still provide an alternative device num-
ber in their internal mount tables. This includes AIX, Apple Darwin, FreeBSD, NetBSD, OpenBSD, and Tru64 UNIX. Lsof knows how to
obtain the alternative device number for these dialects and uses it when its attempt to lstat(2) or stat(2) the file system is
If you're not sure your dialect supplies alternate device numbers for file systems from its mount table, use this lsof incantation to
see if it reports any alternate device numbers:
Look for standard error file warning messages that begin
assuming "dev=xxxx" from ...&.
Lsof reports the complete paths it finds in the NAME column. If lsof can't report all components in a path, it reports in the NAME column the file system name, followed by a space, two `-' characters, another space, and the name components it has located, separated by the `/' character.
When lsof is run in repeat mode - i.e., with the -r option specified - the extent to which it can report path name components for the same file may vary from cycle to cycle. That's because other running processes can cause the kernel to remove entries from its name cache and replace them with others.
Lsof's use of the kernel name cache to identify the paths of files can lead it to report incorrect components under some circum- stances. This can happen when the kernel name cache uses device and node number as a key (e.g., SCO OpenServer) and a key on a rapidly changing file system is reused. If the UNIX dialect's kernel doesn't purge the name cache entry for a file when it is unlinked, lsof may find a reference to the wrong entry in the cache. The lsof FAQ (The FAQ section gives its location.) has more information on this situation. Lsof can report path name components for these dialects: FreeBSD HP-UX Linux NetBSD NEXTSTEP OpenBSD OPENSTEP SCO OpenServer SCO|Caldera UnixWare Solaris Tru64 UNIX Lsof can't report path name components for these dialects: AIX If you want to know why lsof can't report path name components for some dialects, see the lsof FAQ (The FAQ section gives its loca- tion.)
Consequently, lsof normally maintains an ASCII text file of cached /dev (or /devices) information (exception: the /proc-based Linux lsof where it's not needed.) The local system administrator who builds lsof can control the way the device cache file path is formed, selecting from these options: Path from the -D option; Path from an environment variable; System-wide path; Personal path (the default); Personal path, modified by an environment variable.
Consult the output of the -h, -D? , or -? help options for the current state of device cache support. The help output lists the default read-mode device cache file path that is in effect for the current invocation of lsof. The -D? option output lists the read-only and write device cache file paths, the names of any applicable environment variables, and the personal device cache path format.
Lsof can detect that the current device cache file has been accidentally or maliciously modified by integrity checks, including the computation and verification of a sixteen bit Cyclic Redundancy Check (CRC) sum on the file's contents. When lsof senses something wrong with the file, it issues a warning and attempts to remove the current cache file and create a new copy, but only to a path that the process can legitimately write.
The path from which a lsof process may attempt to read a device cache file may not be the same as the path to which it can legiti-
mately write. Thus when lsof senses that it needs to update the device cache file, it may choose a different path for writing it from
the path from which it read an incorrect or outdated version.
If available, the -Dr option will inhibit the writing of a new device cache file. (It's always available when specified without a
path name argument.)
When a new device is added to the system, the device cache file may need to be recreated. Since lsof compares the mtime of the device
cache file with the mtime and ctime of the /dev (or /devices) directory, it usually detects that a new device has been added; in that
case lsof issues a warning message and attempts to rebuild the device cache file.
Whenever lsof writes a device cache file, it sets its ownership to the real UID of the executing process, and its permission modes to
0600, this restricting its reading and writing to the file's owner.
LSOF PERMISSIONS THAT AFFECT DEVICE CACHE FILE ACCESS
Two permissions of the lsof executable affect its ability to access device cache files. The permissions are set by the local system
administrator when lsof is installed.
The first and rarer permission is setuid-root. It comes into effect when lsof is executed; its effective UID is then root, while its
real (i.e., that of the logged-on user) UID is not. The lsof distribution recommends that versions for these dialects run
HP-UX 11.11 and 11.23
The second and more common permission is setgid. It comes into effect when the effective group IDentification number (GID) of the
lsof process is set to one that can access kernel memory devices - e.g.,
An lsof process that has setgid permission usually surrenders the permission after it has accessed the kernel memory devices. When it
does that, lsof can allow more liberal device cache path formations. The lsof distribution recommends that versions for these
dialects run setgid and be allowed to surrender setgid permission.
AIX 5. and 5.3-ML1
Apple Darwin 7.x Power Macintosh systems
FreeBSD 4.x, 4.1x, 5.x and .x for x86-based systems
FreeBSD 5.x and .x for Alpha, AMD64 and Sparc64-based
NetBSD 1., 2.x and 3.x for Alpha, x86, and SPARC-based
NEXTSTEP 3. for NEXTSTEP architectures
OpenBSD 2. and 3.[0-9] for x86-based systems
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
(Note: lsof for AIX 5L and above needs setuid-root permission if its -X option is used.)
Lsof for these dialects does not support a device cache, so the permissions given to the executable don't apply to the device cache
DEVICE CACHE FILE PATH FROM THE -D OPTION
The -D option provides limited means for specifying the device cache file path. Its ? function will report the read-only and write
device cache file paths that lsof will use.
When the -D b, r, and u functions are available, you can use them to request that the cache file be built in a specific location
(b[path]); read but not rebuilt (r[path]); or read and rebuilt (u[path]). The b, r, and u functions are restricted under some condi-
tions. They are restricted when the lsof process is setuid-root. The path specified with the r function is always read-only, even
when it is available.
The b, r, and u functions are also restricted when the lsof process runs setgid and lsof doesn't surrender the setgid permission.
(See the LSOF PERMISSIONS THAT AFFECT DEVICE CACHE FILE ACCESS section for a list of implementations that normally don't surrender
their setgid permission.)
A further -D function, i (for ignore), is always available.
When available, the b function tells lsof to read device information from the kernel with the stat(2) function and build a device
cache file at the indicated path.
When available, the r function tells lsof to read the device cache file, but not update it. When a path argument accompanies -Dr, it
names the device cache file path. The r function is always available when it is specified without a path name argument. If lsof is
not running setuid-root and surrenders its setgid permission, a path name argument may accompany the r function.
When available, the u function tells lsof to attempt to read and use the device cache file. If it can't read the file, or if it finds
the contents of the file incorrect or outdated, it will read information from the kernel, and attempt to write an updated version of
the device cache file, but only to a path it considers legitimate for the lsof process effective and real UIDs.
DEVICE CACHE PATH FROM AN ENVIRONMENT VARIABLE
Lsof's second choice for the device cache file is the contents of the LSOFDEVCACHE environment variable. It avoids this choice if the
lsof process is setuid-root, or the real UID of the process is root.
A further restriction applies to a device cache file path taken from the LSOFDEVCACHE environment variable: lsof will not write a
device cache file to the path if the lsof process doesn't surrender its setgid permission. (See the LSOF PERMISSIONS THAT AFFECT
DEVICE CACHE FILE ACCESS section for information on implementations that don't surrender their setgid permission.)
The local system administrator can disable the use of the LSOFDEVCACHE environment variable or change its name when building lsof.
Consult the output of -D? for the environment variable's name.
SYSTEM-WIDE DEVICE CACHE PATH
The local system administrator may choose to have a system-wide device cache file when building lsof. That file will generally be
constructed by a special system administration procedure when the system is booted or when the contents of /dev or /devices) changes.
If defined, it is lsof's third device cache file path choice.
You can tell that a system-wide device cache file is in effect for your local installation by examining the lsof help option output -
i.e., the output from the -h or -? option.
Lsof will never write to the system-wide device cache file path by default. It must be explicitly named with a -D function in a
root-owned procedure. Once the file has been written, the procedure must change its permission modes to 0644 (owner-read and
owner-write, group-read, and other-read).
PERSONAL DEVICE CACHE PATH (DEFAULT)
The default device cache file path of the lsof distribution is one recorded in the home directory of the real UID that executes lsof.
Added to the home directory is a second path component of the form .lsof_hostname.
This is lsof's fourth device cache file path choice, and is usually the default. If a system-wide device cache file path was defined
when lsof was built, this fourth choice will be applied when lsof can't find the system-wide device cache file. This is the only time
lsof uses two paths when reading the device cache file.
The hostname part of the second component is the base name of the executing host, as returned by gethostname(2). The base name is
defined to be the characters preceding the first `.' in the gethostname(2) output, or all the gethostname(2) output if it contains no
The device cache file belongs to the user ID and is readable and writable by the user ID alone - i.e., its modes are 0600. Each dis-
tinct real user ID on a given host that executes lsof has a distinct device cache file. The hostname part of the path distinguishes
device cache files in an NFS-mounted home directory into which device cache files are written from several different hosts.
The personal device cache file path formed by this method represents a device cache file that lsof will attempt to read, and will
attempt to write should it not exist or should its contents be incorrect or outdated.
The -Dr option without a path name argument will inhibit the writing of a new device cache file.
The -D? option will list the format specification for constructing the personal device cache file. The conversions used in the for-
mat specification are described in the 00DCACHE file of the lsof distribution.
MODIFIED PERSONAL DEVICE CACHE PATH
If this option is defined by the local system administrator when lsof is built, the LSOFPERSDCPATH environment variable contents may
be used to add a component of the personal device cache file path.
The LSOFPERSDCPATH variable contents are inserted in the path at the place marked by the local system administrator with the
conversion in the HASPERSDC format specification of the dialect's machine.h header file. (It's placed right after the home directory
in the default lsof distribution.)
Thus, for example, if LSOFPERSDCPATH contains
LSOF&, the home directory is
/Homes/abe&, the host name is
due.edu&, and the HASPERSDC format is the default (
%h/%p.lsof_%L&), the modified personal device cache file path is:
The LSOFPERSDCPATH environment variable is ignored when the lsof process is setuid-root or when the real UID of the process is root.
Lsof will not write to a modified personal device cache file path if the lsof process doesn't surrender setgid permission. (See the
LSOF PERMISSIONS THAT AFFECT DEVICE CACHE FILE ACCESS section for a list of implementations that normally don't surrender their setgid
If, for example, you want to create a sub-directory of personal device cache file paths by using the LSOFPERSDCPATH environment vari-
able to name it, and lsof doesn't surrender its setgid permission, you will have to allow lsof to create device cache files at the
standard personal path and move them to your subdirectory with shell commands.
The local system administrator may: disable this option when lsof is built; change the name of the environment variable from LSOFPERS-
DCPATH to something else; change the HASPERSDC format to include the personal path component in another place; or exclude the personal
path component entirely. Consult the output of the -D? option for the environment variable's name and the HASPERSDC format specifi-
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 command names, file names, Internet addresses or
files, login names, NFS files, PIDs, PGIDs, or UIDs it was asked to list. If the -V option is specified, lsof will indicate the
search items it failed to list.
It returns a zero (0) if no errors were detected and if it was able to list some information about all the specified search arguments.
When lsof cannot open access to /dev (or /devices) or one of its subdirectories, or get information on a file in them with stat(2), it
issues a warning message and continues. That lsof will issue warning messages about inaccessible files in /dev (or /devices) is indi-
cated in its help output - requested with the -h or >B -? options - with the message:
Inaccessible /dev warnings are enabled.
The warning message may be suppressed with the -w option. It may also have been suppressed by the system administrator when lsof was
compiled by the setting of the WARNDEVACCESS definition. In this case, the output from the help options will include the message:
Inaccessible /dev warnings are disabled.
Inaccessible device warning messages usually disappear after lsof has created a working device cache file.
all open files:
Internet, x.25 (HP-UX), and UNIX domain files:
lsof -i -U
IPv4 network files in use by the process whose PID is 1234:
lsof -i 4 -a -p 1234
IPv6 network files: lsof -i 6
files using any protocol on ports 513, 514, or 515 of host wonderland.cc.purdue.edu, use:
lsof -i @wonderland.cc.purdue.edu:513-515
any protocol on any port of this host :
lsof -i `hostname`
> lsof -i @`hostname` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ssh 1401 dgerman 3u IPv4 0x976a838ec8af3acf 0t0 TCP smackerpro.germans:50978->real-world-systems.com:ssh (ESTABLISHED)to Another host
ftp> !lsof -i @real-world-systems.com COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ssh 1621 dgerman 3u IPv4 0x976a838edb41aeaf 0t0 TCP smackerpro.germans:51186->real-world-systems.com:ssh (ESTABLISHED) ftp 1650 dgerman 3u IPv4 0x976a838ec8af55b7 0t0 TCP smackerpro.germans:51194->real-world-systems.com:ftp (ESTABLISHED)
for login name
abe&, or user ID 1234, or process 456, or process 123, or process 789:
lsof -p 456,123,789 -u 1234,abe
on device /dev/hd4
find the process that has
send SIGHUP to the processes that have
kill -HUP `lsof -t /u/abe/bar`
including an open UNIX domain socket file, with the name
find processes with open files on the NFS file system named
/nfs/mount/point whose server is inaccessible, and presuming your mount
table supplies the device number for
lsof -b /nfs/mount/point
suppress warning messages :
lsof -bw /nfs/mount/point
ignore the device cache file:
obtain PID and command name field output for each process, file descriptor, file device number, and file inode number for each file
of each process:
list the files at descriptors 1 and 3 of every process running the lsof command for login ID
abe& every 10 seconds:
lsof -c lsof -a -d 1 -d 3 -u abe -r10
list the current working directory of processes running a command that is exactly four characters long and has an 'o' or 'O' in
character three, use this regular expression form of the
lsof -c /^..o.$/i -a -d cwd
an IP version 4 socket file by its associated numeric dot-form address:
find an IP version 6 socket file (when the UNIX dialect supports IPv6) by its associated numeric colon-form address:
IP version 6 socket file (when the UNIX dialect supports IPv6) by an associated numeric colon-form address that has a run
of zeroes in it - e.g., the loop-back address:
obtain a repeat mode marker line that contains the current time: lsof -rm====%T====
add spaces to the previous marker line:
lsof -r "m==== %T ===="
When a file has multiple record locks, the lock status character (following the file descriptor) is derived from a test of the first lock structure, not from any combination of the individual record locks that might be described by multiple lock structures.
Lsof can't search for files with restrictive access permissions by name unless it is installed with root set-UID permission. Otherwise it is limited to searching for files to which its user or its set-GID group (if any) has access permission.
The display of the destination address of a raw socket (e.g., for ping) depends on the UNIX operating system. Some dialects store the destination address in the raw socket's protocol control block, some do not.
Lsof can't always represent Solaris device numbers in the same way that ls(1) does. For example, the major and minor device numbers that the lstat(2) and stat(2) functions report for the directory on which CD-ROM files are mounted (typically /cdrom) are not the same as the ones that it reports for the device on which CD-ROM files are mounted (typically /dev/sr0). (Lsof reports the directory numbers.)
The support for /proc file systems is available only for BSD and Tru64 UNIX dialects, Linux, and dialects derived from SYSV R4 - e.g., FreeBSD, NetBSD, OpenBSD, Solaris, UnixWare.
Some /proc file items - device number, inode number, and file size - are unavailable in some dialects. Searching for files in a /proc file system may require that the full path name be specified.
No text (txt) file descriptors are displayed for Linux processes. All entries for files other than the current working directory, the root directory, and numerical file descriptors are labeled mem descriptors.
Lsof can't search for Tru64 UNIX named pipes by name, because their kernel implementation of lstat(2) returns an improper device number for a named pipe.
Lsof can't report fully or correctly on HP-UX 9.01, 10.20, and 11.00 locks because of insufficient access to kernel data or errors in the kernel data. See the lsof FAQ (The FAQ section gives its location.) for details.
The AIX SMT file type is a fabrication. It's made up for file structures whose type (15) isn't defined in the AIX
/usr/include/sys/file.h header file. One way to create such file structures is to run X clients with the DISPLAY variable set to
The ±f[cfgGn] option is not supported under /proc-based Linux lsof, because it doesn't read kernel structures from kernel memory.
LANG defines a language locale. See setlocale e.g., LC_ALL, LC_TYPE, etc.
LSOFDEVCACHE the path to a device cache file. See the DEVICE CACHE PATH FROM AN ENVIRONMENT VARIABLE section for more
LSOFPERSDCPATH the middle component of a modified personal device cache file path. See the MODIFIED PERSONAL DEVICE CACHE
PATH section for more information.
00FAQfile of the lsof distribution. That file is also available via anonymous ftp from pftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
/dev/kmemkernel virtual memory device
/dev/memphysical memory device
/dev/swapsystem paging device
.lsof_hostnamelsof's device cache file (The suffix, hostname, is the first component of the host's name returned by gethostname(2).) AUTHORS Lsof was written by Victor A. Abell
Seeaccess(2), awk(1), crash(1), fattach(3C), ff(1), fstat(8), fuser(1), gethostname(2), isprint(3), kill(1), localtime(3), lstat(2), modload(8), mount(8), netstat(1), ofiles(8L), perl(1), ps(1), readlink(2), setlocale(3), stat(2), strftime(3), time(2), uname(1).
lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME UserEvent 204 dgerman 7u IPv4 0x5c086aaa24351191 0t0 UDP *:* SystemUIS 213 dgerman 7u IPv4 0x5c086aaa24350439 0t0 UDP *:* sharingd 231 dgerman 12u IPv4 0x5c086aaa24350809 0t0 UDP *:* ssh 5246 dgerman 3u IPv4 0x5c086aaa256a0e69 0t0 TCP 10.0.0.11:49769->real-world-systems.com:ssh (CLOSED) ssh 19420 dgerman 3u IPv4 0x5c086aaa39cb4e69 0t0 TCP slammerfox.germans:61435->real-world-systems.com:ssh (CLOSED) ssh 37304 dgerman 3u IPv4 0x5c086aaa2b76ce69 0t0 TCP smackerpro.germans:63625->real-world-systems.com:ssh (ESTABLISHED) ssh 40559 dgerman 3u IPv4 0x5c086aaa2b701651 0t0 TCP 192.168.1.12:63157->real-world-systems.com:ssh (CLOSED) com.apple 45247 dgerman 12u IPv4 0x5c086aaa2a94be69 0t0 TCP smackerpro.germans:49670->a23-11-217-54.deploy.static.akamaitechnologies.com:https (ESTABLISHED) com.apple 45247 dgerman 13u IPv4 0x5c086aaa2a959651 0t0 TCP smackerpro.germans:49671->appleglobal.102.112.2o7.net:https (ESTABLISHED) com.apple 45247 dgerman 17u IPv4 0x5c086aaa2a94be69 0t0 TCP smackerpro.germans:49670->a23-11-217-54.deploy.static.akamaitechnologies.com:https (ESTABLISHED) com.apple 45247 dgerman 18u IPv4 0x5c086aaa2a959651 0t0 TCP smackerpro.germans:49671->appleglobal.102.112.2o7.net:https (ESTABLISHED) com.apple 45247 dgerman 20u IPv4 0x5c086aaa2a958e69 0t0 TCP smackerpro.germans:49672->a23-11-217-54.deploy.static.akamaitechnologies.com:https (ESTABLISHED) com.apple 45247 dgerman 21u IPv4 0x5c086aaa2a958e69 0t0 TCP smackerpro.germans:49672->a23-11-217-54.deploy.static.akamaitechnologies.com:https (ESTABLISHED) ssh 45269 dgerman 3u IPv4 0x5c086aaa2a288e69 0t0 TCP 192.168.1.5:51851->real-world-systems.com:ssh (CLOSED) ssh 52305 dgerman 3u IPv4 0x5c086aaa26ca2e69 0t0 TCP 192.168.1.3:52101->real-world-systems.com:ssh (CLOSED) thunderbi 55630 dgerman 59u IPv4 0x5c086aaa2b979e69 0t0 TCP smackerpro.germans:63616->slmp-550-13.slc.westdc.net:imaps (ESTABLISHED) thunderbi 55630 dgerman 60u IPv4 0x5c086aaa24794e69 0t0 TCP smackerpro.germans:63617->slmp-550-13.slc.westdc.net:imaps (ESTABLISHED) ssh 60693 dgerman 3u IPv4 0x5c086aaa2ba8d651 0t0 TCP smackerpro.germans:51281->real-world-systems.com:ssh (CLOSED) ssh 65768 dgerman 3u IPv4 0x5c086aaa257d8651 0t0 TCP kitchen.germans:58667->real-world-systems.com:ssh (CLOSED) ssh 68409 dgerman 3u IPv4 0x5c086aaa2b353651 0t0 TCP smackerpro.germans:58718->real-world-systems.com:ssh (CLOSED) CIJScanne 77133 dgerman 4u IPv4 0x5c086aaa2a5469f1 0t0 UDP *:58348 CIJScanne 77133 dgerman 5u IPv4 0x5c086aaa2ba9f379 0t0 UDP *:59373 ssh 82907 dgerman 3u IPv4 0x5c086aaa257d7e69 0t0 TCP smackerpro.germans:55109->real-world-systems.com:ssh (CLOSED) ssh 94640 dgerman 3u IPv4 0x5c086aaa2ba8ce69 0t0 TCP smackerpro.germans:53255->real-world-systems.com:ssh (CLOSED) WakeOnLan 99904 dgerman 19u IPv4 0x5c086aaa29f97621 0t0 UDP *:63967 WakeOnLan 99904 dgerman 20u IPv4 0x5c086aaa2ca68b19 0t0 UDP *:62029 WakeOnLan 99904 dgerman 21u IPv4 0x5c086aaa396a6bd9 0t0 UDP *:55423 WakeOnLan 99904 dgerman 22u IPv4 0x5c086aaa396a6dc1 0t0 UDP *:54014 WakeOnLan 99904 dgerman 23u IPv4 0x5c086aaa251b59f1 0t0 UDP *:58716 WakeOnLan 99904 dgerman 24u IPv4 0x5c086aaa25b0dfa9 0t0 UDP *:50278 WakeOnLan 99904 dgerman 25u IPv4 0x5c086aaa29f97dc1 0t0 UDP *:59205 WakeOnLan 99904 dgerman 26u IPv4 0x5c086aaa2ca690d1 0t0 UDP *:60937 WakeOnLan 99904 dgerman 27u IPv4 0x5c086aaa2b606439 0t0 UDP *:61247 WakeOnLan 99904 dgerman 28u IPv4 0x5c086aaa2b607379 0t0 UDP *:62066 WakeOnLan 99904 dgerman 29u IPv4 0x5c086aaa2b607ee9 0t0 UDP *:52666 WakeOnLan 99904 dgerman 30u IPv4 0x5c086aaa2b60a191 0t0 UDP *:56540