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 files 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.
Field output is process and file sets.
A file set begins with a field whose identifier is f (for file descriptor). followed by lines that describe the
file's access mode, lock state, type, device, size, offset, inode, protocol, name and stream module names.
With the NUL field terminator , process and file set with a NL (0A).
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.
fields
a access mode
c process command name (all characters from proc or user structure)
C structure share count
d device character code
D major/minor device number (0x)
f descriptor
F structure address (0x)
G flaGs (0x; names if +fg follows)
g process group ID
i inode number
K tasK ID
k link count
l lock status
L process login name
m marker between repeated output
n 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 size (decimal)
S stream identification
t type
T TCP/TPI information, identified by prefixes (the
= is part of the prefix):
QR=queue for Read size
QS=queue for Sendsize
SO=socket options and values
SS=socket states
ST=connection state
TF=TCP flags and values
WR=window read size
WW=window write size>
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.)
help by specifying the -F\?
Additional information on field content can be found in the OUTPUT section.
Example:
Select the process ID (p), command name (c), file descriptor (f) and file name (n)
fields with an NL field terminator ;
-F pcfn&
Selects the same output with a NUL (000) field terminator
-F pcfn0&
Lsof does not 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.
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).
Utility Files included
- A C header file,
lsof_fields.h contains symbols for the field identification characters,
- a set of sample scripts that process field output, written in awk and Perl 5.
- The C library used for the test suite, written in C, uses field output to validate the
correct operation . The library can be found in the tests/LTlib.c file of the lsof distribution.
Blocks and Timeouts
Lsof can be blocked espically when NFS become inaccessible.
When it breaks a block, it will report the break with an error message, which can be suppressed with -t and -w.
The default timeout, displayed with -h 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.
AVOIDING KERNEL BLOCKS
You can use the -b option to tell lsof to avoid using kernel functions that would block. Some cautions apply.
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 cant specify names for lsof to locate unless theyre 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 theyre incorrect, lsof wont 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 wont 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 wont see the alternate device
numbers reported in the warning messages.
ALTERNATE DEVICE NUMBERS
On some dialects, when lsof has to break a block because it cant get information about a mounted file system via the lstat(2) and
stat(2) kernel functions, or because you specified the -b option, lsof can obtain some of the information it needs - the device number
and possibly the file system type - from the system mount table. When that is possible, lsof will report the device number it
obtained. (You can suppress the report by specifying the -w option.)
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
adding a 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 cant 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.
The 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.) Heres an example from a Sun Solaris 2.6
/etc/mnttab for a file system remotely mounted via NFS:
nfs ignore,noquota,dev=2a40001
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
wont 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
blocked.
If youre 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:
lsof -b
Look for standard error file warning messages that begin assuming "dev=xxxx" from ...&.
KERNEL NAME CACHE
Lsof reports the complete paths it finds in the NAME column. If lsof cant 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 doesnt 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.
DEVICE CACHE FILE
lsof maintains a cache of /dev information
Compilation options control the cache file path which defaults to:
Personal path (default);
-D option;
environment variable;
System-wide path;
Personal path, modified by an environment variable.
-h, -D? displays device cache support.
default read-mode device cache file path that is in effect for the current invocation of lsof.
The -D? output lists the
read-only and write device cache file paths, the names of any applicable environment variables, and the personal device cache path
.
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
setuid-root.
HP-UX 11.11 and 11.23
Linux
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., kmem&, sys&, or system&.
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.
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.
The ±f[cfgGn] is not supported under /proc-based Linux lsof, because it doesn't read kernel structures from kernel memory.
Environment
$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
information.
$LSOFPERSDCPATH the middle component of a modified personal device cache file path. See the MODIFIED PERSONAL DEVICE CACHE
PATH section for more information.
FAQ
Frequently-asked questions and their answers are available in the 00FAQ file of the lsof distribution.
available via anonymous ftp from lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
Files
/dev/kmem kernel virtual memory device
/dev/mem physical memory device
/dev/swap system paging device
lsof_hostname lsof's device cache file (The suffix, hostname, is the first component of the host's name returned by gethostname(2).)
See
access(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).
Revision-4.87
Example
smackerpro 8/4/14
0t0 is decimal 0
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 30u IPv4 0x5c086aaa2b60a191 0t0 UDP *:56540
Does not show /dev/disk if dd is writing to it!