LSOF(1)
๐ LSOF(1) โ the lsof page, but make it cute ๐
General Commands Manual ยท LSOF(1)
okay bestie, sit down, hydrate, because this is the manual page for lsof and it's a big one. we're doing it together, part by part. no skipping, no skimming, every single flag is coming with us. ๐ซถ
โจ NAME โจ
lsof โ list open files
โจ SYNOPSIS โจ
lsof [ -?abChHlnNOPQRtUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [
+|-D D ] [ +|-e s ] [ +|-E ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s] ] [ -i
[i] ] [ -k k ] [ -K k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o [o] ] [ -p
s ] [ +|-r [t[m<fmt>]] ] [ -s [p:s] ] [ -S [t] ] [ -T [t] ] [ -u s ] [
+|-w ] [ -x [fl] ] [ -z [z] ] [ -Z [Z] ] [ -- ] [names]
๐ธ DESCRIPTION ๐ธ
Lsof revision 4.98.0 lists, on its standard output, file information about files opened by processes for these UNIX dialects:
- Apple Darwin 9, Mac OS X 10, macOS 11 and above
- FreeBSD 8.2 and above
- Linux 2.1.72 and above
- NetBSD 1.2 and above
- Solaris 9, 10 and 11 and above
(if you want the newest lsof revision ever, the DISTRIBUTION section of this manual page tells you how to get it. iykyk.)
So likeโฆ what counts as an "open file"? so many things: 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 (that's an Internet socket, an NFS file, or a UNIX domain socket). You can pick a specific file, or literally every file in a file system, by path. ๐
Instead of the pretty formatted display, lsof can also spit out output that other programs can parse. Check the -F option description and the OUTPUT FOR OTHER PROGRAMS section for the tea. ๐ต
And it doesn't just run once, bestie โ lsof can run in repeat mode. In repeat mode it produces output, delays, then repeats the whole output thing over and over until you stop it with an interrupt or quit signal. The +|-r [t[m<fmt>]] option description has the details. ๐
๐ OPTIONS ๐
With zero options given, lsof lists all open files belonging to all active processes. that's the default vibe.
โ ๏ธ but here's the catch: if you specify any list request option, the other list requests have to be asked for specifically. like, if you say-Uto list UNIX socket files, NFS files will NOT show up unless you also say-N. same energy: if you give a user list with-u, UNIX domain socket files belonging to users who aren't in that list won't show up unless you also say-U. no free extras, sorry. ๐ญ
Normally, list options that you explicitly state get ORed together. so specifying -i with no address plus -ufoo gives you all network files OR files belonging to processes owned by user foo. cute, right?
but the exceptions are (write these down, fr fr):
- the
^(negated) login name or user ID (UID), specified with the-uoption; - the
^(negated) process ID (PID), specified with the-poption; - the
^(negated) process group ID (PGID), specified with the-goption; - the
^(negated) command, specified with the-coption; - the
^(negated) TCP or UDP protocol state names, specified with the-s [p:s]option.
Since those are exclusions, they get applied without ORing or ANDing, and they take effect before any other selection criteria get applied. they're the bouncers at the door. ๐
The -a option is how you AND your selections. for example: -a, -U, and -ufoo together gives you only UNIX socket files that belong to processes owned by user foo. slay.
๐จ Caution: the-aoption causes all list selection options to be ANDed. you can't use it to AND just selected pairs of selection options by placing it between them โ even though placing it there is, like, technically acceptable. wherever you put-a, it ANDs everything. it has main character energy and it will not be contained.
Items of the same selection set โ command names, file descriptors, network addresses, process identifiers, user identifiers, zone names, security contexts โ get joined into a single ORed set, and that happens before the result participates in ANDing. so for example: specifying -i@aaa.bbb, -i@ccc.ddd, -a, and -ufff,ggg selects files that belong to either login fff OR ggg AND have network connections to either host aaa.bbb OR ccc.ddd. โจ
Options can be grouped together after a single prefix โ like, the option set -a -b -C can just be written as -abC. however, since values are optional following +|-f, -F, -g, -i, +|-L, -o, +|-r, -s, -S, -T, -x and -z, when you have no values for them, be careful that the next character isn't ambiguous. for example, -Fn might mean the -F and -n options, or it might mean the n field identifier character following the -F option. ๐ตโ๐ซ when ambiguity is possible, start a new option with a - character โ like -F -n. and if the next option is a file name, follow the possibly-ambiguous option with -- โ like -F -- name.
Either the + or the - prefix can be applied to a group of options. options that don't take on separate meanings for each prefix โ like -i โ can be grouped under either prefix. so +M -i can be written as +Mi, and the group means the exact same thing as the separate options. but be careful with prefix grouping when one or more options in the group does take on separate meanings under different prefixes โ like +|-M; -iM is not the same request as -i +M. when in doubt, use separate options with appropriate prefixes. ๐ง
-?,-hโ these two are equivalent, and they select a usage (help) output list. Lsof displays a shortened form of this output when it detects an error in the options you gave it, after it's shown messages explaining each error. (escape the?character however your shell needs you to.)-aโ causes list selection options to be ANDed, as described above. ๐-A Aโ available on systems configured for AFS whose AFS kernel code is implemented via dynamic modules. it lets the lsof user specifyAas an alternate name list file where the kernel addresses of the dynamic modules might be found. see the lsof FAQ (the FAQ section tells you where it lives) for more info about dynamic modules, their symbols, and how they affect lsof.-bโ causes lsof to avoid kernel functions that might block:lstat(2),readlink(2), andstat(2). see the BLOCKS AND TIMEOUTS and AVOIDING KERNEL BLOCKS sections for how to use this option.-c cโ selects the listing of files for processes executing the command that begins with the characters ofc. you can specify multiple commands using multiple-coptions โ they all get joined into a single ORed set before participating in AND option selection. ๐ซถ
If c begins with a ^, then the characters after it specify a command name whose processes get ignored (excluded).
If c begins and ends with a slash (/), the characters between the slashes are interpreted as a regular expression. shell meta-characters in the regex must be quoted so the shell doesn't eat them. the closing slash can be followed by these modifiers:
bโ the regular expression is a basic one.iโ ignore the case of letters.xโ the regular expression is an extended one (this is the default).
See the lsof FAQ (the FAQ section gives its location) for more info on basic and extended regular expressions.
The simple command specification is tested first. if that test fails, the command regular expression gets applied. if the simple command test succeeds, the command regular expression test isn't made at all. and heads up: this may result in no command found for regex: messages when lsof's -V option is specified. ๐ญ
+c wโ defines the maximum number of initial characters of the name (supplied by the UNIX dialect) of the UNIX command associated with a process, to be printed in theCOMMANDcolumn. (the lsof default is nine.)
Note that many UNIX dialects do not supply all command name characters to lsof in the files and structures from which lsof obtains the command name. often, dialects limit the number of characters supplied in those sources. for example, Linux 2.4.27 and Solaris 9 both limit command name length to 16 characters.
If w is zero (0), all command characters supplied to lsof by the UNIX dialect get printed.
If w is less than the length of the column title, COMMAND, it gets raised to that length.
-Cโ disables the reporting of any path name components from the kernel's name cache. see the KERNEL NAME CACHE section for more info.+d sโ causes lsof to search for all open instances of directorysand the files and directories it contains at its top level.+ddoes NOT descend the directory tree rooted ats. the+D Doption is what you want for a full-descent directory tree search rooted at directoryD.
Processing of the +d option does not follow symbolic links within s unless the -x or -x l option is also specified. Nor does it search for open files on file system mount points on subdirectories of s unless the -x or -x f option is also specified.
๐ Note: the authority of the user of this option limits it to searching for files the user has permission to examine with the system stat(2) function.
-d sโ specifies a list of file descriptors (FDs) to exclude from or include in the output listing. the file descriptors are given in the comma-separated setsโ e.g.,cwd,1,3,^6,^2. (there should be no spaces in the set.)
The list is an exclusion list if all entries of the set begin with ^. It's an inclusion list if no entry begins with ^. Mixed lists are not permitted. ๐
โโ๏ธ
A file descriptor number range may be in the set, as long as neither member is empty, both members are numbers, and the ending member is larger than the starting one โ e.g., 0-7 or 3-10. ranges may be specified for exclusion if they have the ^ prefix โ e.g., ^0-7 excludes all file descriptors 0 through 7.
Multiple file descriptor numbers get joined into a single ORed set before participating in AND option selection.
When there are both exclusion and inclusion members in the set, lsof reports them as errors and exits with a non-zero return code. ๐
See the description of File Descriptor (FD) output values in the OUTPUT section for more info on file descriptor names.
fd is a pseudo file descriptor name for specifying the whole range of possible file descriptor numbers. fd does not appear in the FD column of output.
...and that's where part 1 ends, bestie. there's so much more coming. ๐
+D Dโ bestie, this one makeslsofgo hunt down every single open instance of directory D, plus every file and directory inside it, all the way down to its complete depth. No half-measures. ๐ธ
Okay but heads up: processing +D does not follow symbolic links inside D unless you also throw in -x or -x l. And it will not search for open files on file system mount points on subdirectories of D unless you also specify -x or -x f.
Also, the authority of whoever runs this option limits it โ you only get to search for files you have permission to examine with the system stat(2) function. ๐
Further note, and this one's important:lsofmay process this option slowly and need a large amount of dynamic memory to do it. Why? Because it has to descend the entire directory tree rooted at D, callingstat(2)for every file and directory, build a list of everything it finds, and then search that list for a match against every open file. When D is huge, these steps can take a long time. Use this option prudently, bestie. ๐ซถ
-D Dโ this one directslsof's use of the device cache file. Its use is sometimes restricted. See theDEVICE CACHE FILEsection and the sections after it for the full tea. โ
-D must be followed by a function letter, and that function letter may optionally be followed by a path name. lsof recognizes these function letters:
? - report device cache file paths
b - build the device cache file
i - ignore the device cache file
r - read the device cache file
u - read and update the device cache file
The b, r, and u functions, when accompanied by a path name, are sometimes restricted. When they're restricted, they won't even show up in the description of the -D option that comes with -h or -? output. Check the DEVICE CACHE FILE section and the ones after it for the lore on these functions and when they're restricted.
The ? function reports the read-only and write paths lsof can use for the device cache file, the names of any environment variables whose values lsof will examine when forming the device cache file path, and the format for the personal device cache file path. (Escape the ? character the way your shell requires, bestie. ๐)
When they're available, the b, r, and u functions may be followed by the device cache file's path. The standard default is .lsof_hostname in the home directory of the real user ID that executes lsof โ but this could have been changed when lsof was configured and compiled. (The output of the -h and -? options shows the current default prefix โ e.g., .lsof.) The suffix, hostname, is the first component of the host's name returned by gethostname(2).
When available, the b function directs lsof to build a new device cache file at the default or specified path.
The i function directs lsof to ignore the default device cache file and get its info about devices via direct calls to the kernel.
The r function directs lsof to read the device cache at the default or specified path, but stops it from creating a new device cache file when none exists or when the existing one is improperly structured. The r function, when specified without a path name, prevents lsof from updating an incorrect or outdated device cache file, or creating a new one in its place. The r function is always available when it's specified without a path name argument; it may be restricted by the permissions of the lsof process.
When available, the u function directs lsof to read the device cache file at the default or specified path, if possible, and to rebuild it if necessary. This is the default device cache file function when no -D option has been specified. โจ
+|-e sโ exempts the file system whose path name is s from being subjected to kernel function calls that might block. ๐
The +e option exempts stat(2), lstat(2) and most readlink(2) kernel function calls. The -e option exempts only stat(2) and lstat(2) kernel function calls. You can specify multiple file systems with separate +|-e specifications, and each one can have readlink(2) calls exempted or not.
This option is currently implemented only for Linux.
CAUTION, bestie, read this twice: this option can easily be mis-applied to a file system other than the one you actually care about, because it uses path name rather than the more reliable device and inode numbers. (Device and inode numbers are acquired via the potentially blockingstat(2)kernel call and are thus not available here โ but peep the+|-m moption as a possible alternative way to supply device numbers.) Use this option with great care and fully specify the path name of the file system to be exempted. ๐
When open files on exempted file systems are reported, it may not be possible to obtain all their information. So some information columns will be blank, the characters UNKN preface the values in the TYPE column, and the applicable exemption option is added in parentheses to the end of the NAME column. (Some device number information might be made available via the +|-m m option.)
+|-Eโ+Esays that Linux pipe, Linux UNIX socket, Linux INET(6) socket closed in a local host, Linux pseudoterminal files, POSIX Message Queueue implementation in Linux, and Linux eventfd should be displayed with endpoint information, and the files of the endpoints should also be displayed. โจ- Note 1: UNIX socket file endpoint information is only available when the features enabled line of
-voutput containsuxsockept, and psudoterminal endpoint information is only available when the features enabled line containsptyept. - Note 2: POSIX Message Queue file endpoint information is only available when the mqueue file system is mounted.
- Note 1: UNIX socket file endpoint information is only available when the features enabled line of
Pipe endpoint information is displayed in the NAME column in the form PID,cmd,FDmode, where PID is the endpoint process ID; cmd is the endpoint process command; FD is the endpoint file's descriptor; and mode is the endpoint file's access mode.
Pseudoterminal endpoint information is displayed in the NAME column as ->/dev/ptsmin PID,cmd,FDmode or PID,cmd,FDmode. The first form is for a master device; the second, for a slave device. min is a slave device's minor device number; and PID, cmd, FD and mode are the same as with pipe endpoint information. Note: psudoterminal endpoint information is only available when the features enabled line of -V output contains ptyept. In addition, this feature works on Linux kernels above 4.13.0. ๐ง
UNIX socket file endpoint information is displayed in the NAME column in the form type=TYPE ->INO=INODE PID,cmd,FDmode, where TYPE is the socket type; INODE is the i-node number of the connected socket; and PID, cmd, FD and mode are the same as with pipe endpoint information. Note: UNIX socket file endpoint information is available only when the features enabled line of -v output contains uxsockept.
INET socket file endpoint information is inserted to the value at the NAME column in the form -> PID,cmd,FDmode, where PID, cmd, FD and mode are the same as with pipe endpoint information. The endpoint information is available only if the socket is used for local IPC; both endpoints bind to the same local IPv4 or IPv6 address. ๐
POSIX Message Queue file endpoint information is displayed in the NAME column in the same form as that of pipe.
eventfd endpoint information is displayed in the NAME column in the same form as that of pipe. This feature works on Linux kernels above 5.2.0.
Multiple occurrences of this information can appear in a file's NAME column.
-E specifies that endpoint supported files should be displayed with endpoint information, but not the files of the endpoints. ๐
+|-f [cfgGn]โfby itself clarifies how path name arguments are to be interpreted. When followed byc,f,g,G, ornin any combination, it specifies that the listing of kernel file structure information is to be enabled (+) or inhibited (-). ๐
Normally a path name argument is taken to be a file system name if it matches a mounted-on directory name reported by mount(8), or if it represents a block device, named in the mount output and associated with a mounted directory name. When +f is specified, all path name arguments will be taken to be file system names, and lsof will complain if any of them are not. This can be useful, for example, when the file system name (mounted-on device) isn't a block device. This happens for some CD-ROM file systems. ๐ฟ
When -f is specified by itself, all path name arguments will be taken to be simple files. So, for example, the -f -- / arguments direct lsof to search for open files with a / path name, not all open files in the / (root) file system.
Be careful to make sure +f and -f are properly terminated and aren't followed by a character (e.g., of the file or file system name) that might be taken as a parameter. For example, use -- after +f and -f as in these examples:
$ lsof +f -- /file/system/name
$ lsof -f -- /file/name
The listing of information from kernel file structures, requested with the +f [cfgGn] option form, is normally inhibited, and is not available in whole or part for some dialects โ e.g., /proc-based Linux kernels below 2.6.22. When the prefix to f is a plus sign (+), these characters request file structure information:
cโ file structure use count (not Linux)fโ file structure address (not Linux)gโ file flag abbreviations (Linux 2.6.22 and up)
okay so the abbrevs map to the actual C flags like this (peep open(2) for the receipts):
WโO_WRONLYRWโO_RDWRCRโO_CREATEXCLโO_EXCLNTTYโO_NOCTTYTRโO_TRUNCAPโO_APPENDNDโO_NDELAYSYNโO_SYNCASYNโO_ASYNCDIRโO_DIRECTDTYโO_DIRECTORYNFLKโO_NOFOLLOWNATMโO_NOATIMEDSYNโO_DSYNCRSYNโO_RSYNCLGโO_LARGEFILECXโO_CLOEXECTMPFโO_TMPFILE
Gโ file flags in hexadecimal (Linux 2.6.22 and up)nโ file structure node address (not Linux)
And when the prefix is a minus (-), the same characters turn off the listing of the values you named. Reverse uno card, basically.
File structure addresses, use counts, flags and node addresses are your besties for spotting identical files that got inherited by child processes, and identical files being used by different processes. Like, lsof column output can be sorted by output columns holding those values and listed so you can find identical file use โ or you can parse lsof field output with an AWK or Perl post-filter script, or with a C program. Slay, options for days. ๐
-Ff โ picks out a character list, f, that selects which fields get output so another program can chew on them, plus the character that terminates each output field. Every field you want is named with a single character in f. The field terminator defaults toNL, but you can switch it toNUL(000). TheOUTPUT FOR OTHER PROGRAMSsection has the whole breakdown of the field identification characters and how the field output process works. โจ
When the field selection character list is empty, all standard fields are selected (except the raw device field, security context and zone field, for compatibility reasons) and the NL field terminator is used. Compatibility era, we love her.
When the field selection character list contains only a zero (0), all fields are selected (except the raw device field, for compatibility reasons) and the NUL terminator character is used.
Any other combo of fields and their associated field terminator character has to be set with explicit entries in f, as described in the OUTPUT FOR OTHER PROGRAMS section.
When a field selection character names an item lsof doesn't normally list โ like PPID, selected with -R โ then specifying that field character (e.g. -FR) also selects the listing of the item. Two birds, one flag, no cap.
When the field selection character list contains the single character ?, lsof will display a help list of the field identification characters. (Escape the ? character however your shell needs you to. ๐ญ)
-g[s] โ excludes or selects the listing of files for the processes whose optional process group IDentification (PGID) numbers are in the comma-separated set s โ e.g.123or123,^456. (No spaces in the set, bestie, I'm begging.)
PGID numbers that begin with ^ (negation) are exclusions. ๐ซ
Multiple PGID numbers get joined into a single ORed set before they take part in AND option selection. But PGID exclusions are applied without ORing or ANDing and take effect before the other selection criteria are applied.
The -g option also turns on the output display of PGID numbers. When you specify it without a PGID set, that's literally all it does.
-Hโ tells lsof to print human readable sizes, e.g.123.4K456.7M. Numbers that don't make your eyes bleed? Iconic.-i[i] โ selects the listing of files any of whose Internet address matches the address you put in i. If you give no address, this option selects the listing of all Internet and x.25 (HP-UX) network files. ๐
If -i4 or -i6 is specified with no following address, only files of the indicated IP version, IPv4 or IPv6, get displayed. (An IPv6 specification can only be used if the dialect supports IPv6, as shown by [46] and IPv[46] in lsof's -h or -? output.) Specifying -i4, then -i6, one after the other, is the same as specifying -i, and vice-versa. Specifying -i4, or -i6 after -i, is the same as specifying -i4 or -i6 by itself. Math is math, and the math is mathing.
Multiple addresses (up to a limit of 100) may be specified with multiple -i options. (A port number or service name range counts as one address.) They're joined into a single ORed set before participating in AND option selection.
An Internet address is specified in this form (the bits in square brackets are optional):
[46][protocol][@hostname|hostaddr][:service|port]
where:
46specifies the IP version, IPv4 or IPv6, that applies to the following address.6may be specified only if the UNIX dialect supports IPv6. If neither4nor6is specified, the following address applies to all IP versions.protocolis a protocol name โTCP,UDPorUDPLITE.hostnameis an Internet host name. Unless a specific IP version is specified, open network files associated with host names of all versions will be selected.hostaddris a numeric Internet IPv4 address in dot form; or an IPv6 numeric address in colon form, enclosed in brackets, if the UNIX dialect supports IPv6. When an IP version is selected, only its numeric addresses may be specified.serviceis an/etc/servicesname โ e.g.smtpโ or a list of them.portis a port number, or a list of them.
IPv6 options may be used only if the UNIX dialect supports IPv6. To check whether your dialect does, run lsof and specify the -h or -? (help) option. If the displayed description of the -i option contains [46] and IPv[46], then IPv6 is supported. vibe check passed โ
IPv4 host names and addresses may not be specified if network file selection is limited to IPv6 with -i 6. IPv6 host names and addresses may not be specified if network file selection is limited to IPv4 with -i 4. When an open IPv4 network file's address is mapped in an IPv6 address, the open file's type will be IPv6, not IPv4, and its display will be selected by 6, not 4. It's giving glow-up, not disguise.
At least one address component โ 4, 6, protocol, hostname, hostaddr, or service โ must be supplied. The @ character, leading the host specification, is always required; same with the :, leading the port specification. Specify either hostname or hostaddr. Specify either a service name list or a port number list. If you specify a service name list, the protocol may also need to be specified if the TCP, UDP and UDPLITE port numbers for that service name are different. Use any case โ lower or upper โ for protocol. ๐
Service names and port numbers may be combined in a list whose entries are separated by commas and whose numeric range entries are separated by minus signs. There may be no embedded spaces, and all service names must belong to the specified protocol. Since service names may contain embedded minus signs, the starting entry of a range can't be a service name; it can be a port number, though. Gotcha alert, bestie.
Here are some sample addresses:
-i6 - IPv6 only
TCP:25 - TCP and port 25
@1.2.3.4 - Internet IPv4 host address 1.2.3.4
@[3ffe:1ebc::1]:1234 - Internet IPv6 host address
3ffe:1ebc::1, port 1234
UDP:who - UDP who service port
TCP@lsof.itap:513 - TCP, port 513 and host name lsof.itap
tcp@foo:1-10,smtp,99 - TCP, ports 1 through 10,
service name smtp, port 99, host name foo
tcp@bar:1-smtp - TCP, ports 1 through smtp, host bar
:time - either TCP, UDP or UDPLITE time service port
-Kk โ selects the listing of tasks (threads) of processes, on dialects where task (thread) reporting is supported. (If the help output โ i.e. the output of the-hor-?options โ shows this option, then task (thread) reporting is supported by the dialect.) ๐งต
If -K is followed by a value, k, it must be i. That makes lsof ignore tasks, especially in the default list-everything case when no other options are specified.
When -K and -a are both specified on Linux, and the tasks of a main process are selected by other options, the main process will also be listed as though it were a task, but without a task ID. (See the description of the TID column in the OUTPUT section.)
Where the FreeBSD version supports threads, all threads will be listed with their IDs.
In general, threads and tasks inherit the files of the caller, but they may close some and open others, so lsof always reports all the open files of threads and tasks. They contain multitudes.
-kk โ specifies a kernel name list file, k, in place of/vmunix,/mach, etc. Heads up:-kis not available under AIX on the IBM RISC/System 6000. ๐-lโ inhibits the conversion of user ID numbers to login names. Also super useful when login name lookup is working improperly or slowly. We've all had a slow day.+|-L[l] โ enables (+) or disables (-) the listing of file link counts, where they're available โ e.g. they aren't available for sockets, or most FIFOs and pipes. ๐
When +L is specified without a following number, all link counts get listed. When -L is specified (the default), no link counts get listed.
- so when
+Lis followed by a number, only files with a link count less than that number get listed. (And bestie, no number may follow-Lโ that's just not a thing.) A spec like+L1selects open files that have been unlinked. And a spec like+aL1 <file_system>selects unlinked open files on that specified file system. ๐ฆ - For any other link count comparisons? Use field output (
-F) plus a post-processing script or program. Slay.
+|-mm โ picks an alternate kernel memory file, or turns on mount table supplement processing. Two whole vibes in one flag, iconic. ๐- The
-mm form says: use kernel memory file m instead of/dev/kmemor/dev/memโ like, say, a crash dump file. ๐ - The
+mform requests that a mount supplement file get written to standard output. And honestly? Every other option is silently ignored when you do this. Not me ignoring everything else, but okay. - The mount supplement file gets one line per mounted file system: the mounted file system directory, then a single space, then the device number in hexadecimal
"0x"format. Like:
- The
/ 0x801
- Lsof can use that mount supplement file to get device numbers for file systems when it can't get them via
stat(2)orlstat(2). - The
+mm form identifies m as a mount supplement file. - > Note: the
+mand+mm options are not available for all supported dialects. Check the output of lsof's-hor-?options to see if they're available for you. ๐ซถ
+|-Mโ enables (+) or disables (-) reporting of portmapper registrations for local TCP, UDP and UDPLITE ports, where port mapping is supported. (The last paragraph of this option spills the tea on where it's supported, keep reading. ๐)- The default reporting mode is set by the lsof builder with the
HASPMAPENABLED#definein the dialect'smachine.hheader file. Lsof ships with that#definedeactivated, so portmapper reporting is off by default and you gotta ask for it with+M. Run lsof's-hor-?option and it'll report the default mode. Disabling it when it's already disabled, or enabling it when it's already enabled? Totally acceptable, no drama. ๐ - When portmapper registration reporting is on, lsof shows the portmapper registration (if any) for local TCP, UDP or UDPLITE ports in square brackets right after the port numbers or service names โ e.g.
:1234[name]or:name[100083]. That registration info may be a name or a number, depending on what the registering program handed the portmapper when it registered. - > When portmapper registration reporting is enabled, lsof may run a little more slowly or even become blocked when access to the portmapper gets congested or stops. Flip the reporting mode to figure out if it's slowing or blocking lsof. ๐ญ
- For purposes of portmapper registration reporting, lsof considers a TCP, UDP or UDPLITE port local if: it's found in the local part of its containing kernel structure; or it's in the foreign part of its containing kernel structure and the local and foreign Internet addresses are the same; or it's in the foreign part of its containing kernel structure and the foreign Internet address is
INADDR_LOOPBACK(127.0.0.1). Heads up, this rule may make lsof ignore some foreign ports on machines with multiple interfaces when the foreign Internet address lives on a different interface from the local one. - See the lsof FAQ (the FAQ section tells you where it lives) for more discussion of portmapper registration reporting issues.
- Portmapper registration reporting is supported only on dialects that have RPC header files. (Some Linux distributions with GlibC 2.14 do not have them. ๐) When it is supported, the
-hor-?help output will show the+|-Moption.
- The default reporting mode is set by the lsof builder with the
-nโ stops network numbers from being converted to host names for network files. This inhibition can make lsof run faster, and it's also a lifesaver when host name lookup is being weird. โจ
-Nโ selects the listing of NFS files. ๐
-oโ tells lsof to display file offset at all times. It changes theSIZE/OFFoutput column title toOFFSET. Note: on some UNIX dialects lsof can't get accurate or consistent file offset info from its kernel data sources โ sometimes just for particular kinds of files (like socket files, ugh). Consult the lsof FAQ (the FAQ section says where it is) for more.- The
-oand-soptions are mutually exclusive โ you literally cannot specify both. When neither is specified, lsof displays whatever value โ size or offset โ is appropriate and available for that file's type.
- The
-oo โ defines the number of decimal digits (o) to print after the0tfor a file offset, before the form switches to0x.... An o value of zero (unlimited) tells lsof to use the0tform for all offset output. ๐- > This option does NOT tell lsof to display offset at all times โ specify
-o(no trailing number) for that.-oo only sets the number of digits after0tin either mixed size-and-offset or offset-only output. - So, like, to display offset at all times with a decimal digit count of 10, you'd use:
- > This option does NOT tell lsof to display offset at all times โ specify
-o -o 10
or
-oo10
- The default number of digits allowed after
0tis normally 8, but the lsof builder may have changed it. Check the-oo description in the output of-hor-?to find the default actually in effect. ๐
-Oโ tells lsof to bypass the strategy it uses to avoid getting blocked by some kernel operations, i.e. doing them in forked child processes. See the BLOCKS AND TIMEOUTS and AVOIDING KERNEL BLOCKS sections for more on kernel operations that may block lsof.- > Using this option reduces lsof startup overhead, but it may also make lsof hang when the kernel doesn't respond to a function. Use it cautiously, bestie. โ ๏ธ
-ps โ excludes or selects the listing of files for the processes whose optional process IDentification (PID) numbers are in the comma-separated set s โ e.g.123or123,^456. (No spaces in the set, please and thank you. ๐ )- PID numbers starting with
^(negation) represent exclusions. - Multiple PID numbers are joined into a single ORed set before participating in AND option selection. But PID exclusions are applied with no ORing or ANDing at all, and they take effect before other selection criteria get applied. Order matters, periodt.
- PID numbers starting with
-Pโ stops port numbers from being converted to port names for network files. Inhibiting that conversion may make lsof run a little faster, and it's also handy when port name lookup is acting up. ๐ธ
-Qโ ignore failed search terms. When lsof is told to search for users of a file, or users of a device, or a specific PID, or certain protocols in use by that PID, and so on, lsof returns an error if any search results come up empty.-Qflips that: lsof instead returns a successful exit code (0) even if any search results are empty. Bonus โ missing search terms won't be reported tostderreither. No cap. ๐
+|-r [*t*[*c<N>*][*m<fmt>*]]โ puts lsof into repeat mode. There, lsof lists open files as selected by other options, waits t seconds (default fifteen), then repeats the listing, delaying and listing over and over until stopped by a condition defined by the option's prefix. ๐- If the prefix is
-, repeat mode is endless. Lsof must be terminated with an interrupt or quit signal.c<N>sets the limits of repeating โ if the number of iterations reaches<N>, lsof stops itself. - If the prefix is
+, repeat mode ends on the first cycle where no open files are listed โ and of course when lsof is stopped with an interrupt or quit signal. When repeat mode ends because no files were listed, the process exit code is zero if any open files were ever listed, and one if none ever were. - Lsof marks the end of each listing: if field output is in progress (the
-Foption was specified), the default marker ism; otherwise the default marker is========. The marker is followed by a NL character. - The optional
m<fmt>argument specifies a format for the marker line. The<fmt>characters aftermare interpreted as a format specification to thestrftime(3)function, when both it and thelocaltime(3)function are available in the dialect's C library. Consult thestrftime(3)documentation for what may appear in its format specification. Note that when field output is requested with-F,<fmt>cannot contain the NL format,%n. Also note that when<fmt>contains spaces or other characters that affect the shell's interpretation of arguments,<fmt>must be quoted appropriately. โจ - Repeat mode reduces lsof startup overhead, so it's more efficient than calling lsof repetitively from a shell script, for example.
- To use repeat mode most efficiently, pair
+|-rwith other lsof selection options so the amount of kernel memory access lsof does stays at a minimum. Options that filter at the process level โ e.g.-c,-g,-p,-uโ are the most efficient selectors. ๐
- If the prefix is
Repeat mode is useful when coupled with field output (see the -F, option description) and a supervising awk or Perl script, or a C program. โจ
-Rโ tellslsofto list the Parent Process IDentification number in thePPIDcolumn. ๐-s [p:s]โsall on its own tellslsofto display file size at all times. It also changes theSIZE/OFFoutput column title toSIZE. And if a file doesn't have a size? Nothing gets displayed, bestie. No fake numbers, no cap. ๐
The optional -s p:s form is available only for selected dialects, and only when the -h or -? help output actually lists it. Check first. ๐
When that optional form is available, the s may be followed by a protocol name (p) โ either TCP or UDP โ a colon (:) and a comma-separated protocol state name list. The option then causes open TCP and UDP files to be excluded if their state name(s) are in the list (s) preceded by a ^; or included if their name(s) are not preceded by a ^.
Dialects that support this option may support only one protocol. When an unsupported protocol is specified, a message will be displayed indicating state names for the protocol are unavailable. ๐ญ
When an inclusion list is defined, only network files with state names in the list will be present in the lsof output. So specifying one state name means only network files with that lone state name get listed. Periodt.
Case is unimportant in the protocol or state names, but there may be no spaces, and that colon (:) separating the protocol name (p) and the state name list (s) is required.
If only TCP and UDP files are to be listed, as controlled by the specified exclusions and inclusions, the -i option must be specified, too. And if only a single protocol's files are to be listed, add its name as an argument to the -i option.
For example, to list only network files with TCP state LISTEN, use:
-iTCP -sTCP:LISTEN
Or, for example, to list network files with all UDP states except Idle, use:
-iUDP -sUDP:^Idle
State names vary with UNIX dialects, so it's not possible to provide a complete list. Some common TCP state names are: CLOSED, IDLE, BOUND, LISTEN, ESTABLISHED, SYN_SENT, SYN_RCDV, ESTABLISHED, CLOSE_WAIT, FIN_WAIT1, CLOSING, LAST_ACK, FIN_WAIT_2, and TIME_WAIT. Two common UDP state names are Unbound and Idle. ๐ฆ
(Yep โ ESTABLISHED shows up twice in that list. That's exactly how the page has it, it's not me being chaotic. ๐ซถ)
See the lsof FAQ (the FAQ section gives its location) for more information on how to use protocol state exclusion and inclusion, including examples. ๐ง
Heads up: the-o(without a following decimal digit count) and the-soption (without a following protocol and state name list) are mutually exclusive โ they can't both be specified. When neither is specified,lsofdisplays whatever value โ size or offset โ is appropriate and available for the type of file. โ ๏ธ
And since some types of files don't have true sizes โ sockets, FIFOs, pipes, etc. โ lsof displays for their sizes the content amounts in their associated kernel buffers, if possible. ๐ธ
-S [t]โ specifies an optional time-out seconds value for kernel functions โlstat(2),readlink(2), andstat(2)โ that might otherwise deadlock. The minimum fortis two; the default is fifteen; when no value is specified, the default is used.
See the BLOCKS AND TIMEOUTS section for more information. โณ
-T [t]โ controls the reporting of some TCP/TPI information, also reported bynetstat(1), following the network addresses. In normal output the information appears in parentheses, each item except TCP or TPI state name identified by a keyword, followed by=, separated from others by a single space:
<TCP or TPI state name>
QR=<read queue length>
QS=<send queue length>
SO=<socket options and values>
SS=<socket states>
TF=<TCP flags and values>
WR=<window read length>
WW=<window write length>
Not all values are reported for all UNIX dialects. Items values (when available) are reported after the item name and =.
When the field output mode is in effect (see OUTPUT FOR OTHER PROGRAMS) each item appears as a field with a T leading character. ๐
-T with no following key characters disables TCP/TPI information reporting.
-T with following characters selects the reporting of specific TCP/TPI information:
f selects reporting of socket options,
states and values, and TCP flags and
values.
q selects queue length reporting.
s selects connection state reporting.
w selects window size reporting.
Not all selections are enabled for some UNIX dialects. State may be selected for all dialects and is reported by default. The -h or -? help output for the -T option will show what selections may be used with the UNIX dialect. ๐
When -T is used to select information โ i.e., it is followed by one or more selection characters โ the displaying of state is disabled by default, and it must be explicitly selected again in the characters following -T. (In effect, then, the default is equivalent to -Ts.) For example, if queue lengths and state are desired, use -Tqs. ๐ฅ
Socket options, socket states, some socket values, TCP flags and one TCP value may be reported (when available in the UNIX dialect) in the form of the names that commonly appear after SO_, so_, SS_, TCP_ and TF_ in the dialect's header files โ most often <sys/socket.h>, <sys/socketvar.h> and <netinet/tcp_var.h>. Consult those header files for the meaning of the flags, options, states and values. ๐
SO= precedes socket options and values; SS=, socket states; and TF=, TCP flags and values.
If a flag or option has a value, the value will follow an = and the name โ e.g., SO=LINGER=5, SO=QLIM=5, TF=MSS=512. The following values may be reported:
KEEPALIVEโ keep alive time (SO_KEEPALIVE)LINGERโ linger time (SO_LINGER)MSSโ maximum segment size (TCP_MAXSEG)PQLENโ partial listen queue connectionsQLENโ established listen queue connectionsQLIMโ established listen queue limitRCVBUFโ receive buffer length (SO_RCVBUF)SNDBUFโ send buffer length (SO_SNDBUF)
Details on what socket options and values, socket states, and TCP flags and values may be displayed for particular UNIX dialects may be found in the answer to the "Why doesn't lsof report socket options, socket states, and TCP flags and values for my dialect?" and "Why doesn't lsof report the partial listen queue connection count for my dialect?" questions in the lsof FAQ (the FAQ section gives its location). On Linux this option also prints the state of UNIX domain sockets. ๐ง
-tโ produce terse output comprising only process identifiers (without a header), so that it is easy to use programmatically. e.g.
# reload anything using old SSL
lsof -t /lib/*/libssl.so.* | xargs -r kill -HUP
# get list of processes and then iterate over them (Bash only)
mapfile -t pids < <(
lsof -wt /var/log/your.log
)
for pid in "${pids[@]}" ; do
your_command -p "$pid"
done
The -t option implies the -w option. ๐คซ
-u sโ selects the listing of files for the user whose login names or user ID numbers are in the comma-separated setsโ e.g.,abe, or548,root. (There should be no spaces in the set!)
Multiple login names or user ID numbers are joined in a single ORed set before participating in AND option selection.
If a login name or user ID is preceded by a ^, it becomes a negation โ i.e., files of processes owned by the login name or user ID will never be listed. A negated login name or user ID selection is neither ANDed nor ORed with other selections; it is applied before all other selections and absolutely excludes the listing of the files of the process. For example, to direct lsof to exclude the listing of files belonging to root processes, specify -u^root or -u^0. ๐
-Uโ selects the listing of UNIX domain socket files. ๐-vโ selects the listing oflsofversion information, including: revision number; when thelsofbinary was constructed; who constructed the binary and where; the name of the compiler used to construct thelsofbinary; the version number of the compiler when readily available; the compiler and loader flags used to construct thelsofbinary; and system information, typically the output ofuname's-aoption. ๐-Vโ directslsofto indicate the items it was asked to list and failed to find โ command names, file names, Internet addresses or files, login names, NFS files, PIDs, PGIDs, and UIDs. ๐
When other options are ANDed to search options, or compile-time options restrict the listing of some files, lsof may not report that it failed to find a search item when an ANDed option or compile-time option prevents the listing of the open file containing the located search item.
For example, lsof -V -iTCP@foobar -a -d 999 may not report a failure to locate open files at TCP@foobar and may not list any, if none have a file descriptor number of 999. A similar situation arises when HASSECURITY and HASNOSOCKSECURITY are defined at compile time and they prevent the listing of open files. ๐ซ
+|-wโ Enables (+) or disables (-) the suppression of warning messages. ๐ค
The lsof builder can also pick whether warning messages are off or on by default โ and the default state gets spelled out for you in the output of the -h or -? option, so you can just peek. Turning warnings off when they're already off? Fine. Turning them on when they're already on? Also fine. It's giving zero drama.
Also, the -t option implies the -w option. iykyk.
-x[fl] โ this one's the buddy option for+dand+D, bestie. It tells their processing to cross over symbolic links and/or file system mount points that get stumbled on while scanning the directory (+d) or the directory tree (+D).
If you drop -x all by itself with no parameter after it, cross-over processing for both symbolic links and file system mount points is enabled. But heads up: when -x comes with no parameter, the next argument has to start with - or +. No cap.
The optional f parameter switches on file system mount point cross-over processing; l switches on symbolic link cross-over processing.
๐จ The-xoption may not be supplied without also supplying a+dor+Doption. It's a package deal.
-Xโ okay so this one is a dialect-specific option, meaning it means different things depending on where you're running it. Buckle up.
AIX
This IBM AIX RISC/System 6000 option requests the reporting of executed text file and shared library references. โจ
WARNING: because this option uses the kernel readx() function, using it on a busy AIX system might cause an application process to hang so completely that it can neither be killed nor stopped. I have never seen this happen or had a report of its happening, but I think there is a remote possibility it could happen. ๐ญ So like, respect the warning, okay?
By default, use of readx() is disabled. On AIX 5L and above, lsof may need setuid-root permission to perform the actions this option requests.
The lsof builder may specify that the -X option be restricted to processes whose real UID is root. If that's been done, the -X option will not appear in the -h or -? help output unless the real UID of the lsof process is root. The default lsof distribution allows any UID to specify -X, so by default it will appear in the help output.
When AIX readx() use is disabled, lsof may not be able to report information for all text and loader file references, but it may also avoid exacerbating an AIX kernel directory search kernel error, known as the Stale Segment ID bug.
The readx() function, used by lsof or any other program to access some sections of kernel virtual memory, can trigger the Stale Segment ID bug. It can cause the kernel's dir_search() function to believe erroneously that part of an in-memory copy of a file system directory has been zeroed. Another application process, distinct from lsof, asking the kernel to search the directory โ e.g., by using open(2) โ can cause dir_search() to loop forever, thus hanging the application process. ๐
Consult the lsof FAQ (The FAQ section gives its location.) and the 00README file of the lsof distribution for a more complete description of the Stale Segment ID bug, its APAR, and methods for defining readx() use when compiling lsof.
Linux
This Linux option requests that lsof skip the reporting of information on all open TCP, UDP and UDPLITE IPv4 and IPv6 files. ๐ฆ
This Linux option is most useful when the system has an extremely large number of open TCP, UDP and UDPLITE files, the processing of whose information in the /proc/net/tcp* and /proc/net/udp* files would take lsof a long time, and whose reporting is not of interest.
Use this option with care and only when you are sure that the information you want lsof to display isn't associated with open TCP, UDP or UDPLITE socket files. ๐ซถ
Solaris 10 and above
This Solaris 10 and above option requests the reporting of cached paths for files that have been deleted โ i.e., removed with rm(1) or unlink(2).
The cached path is followed by the string `` (deleted)'' to indicate that the path by which the file was opened has been deleted.
Because intervening changes made to the path โ i.e., renames with mv(1) or rename(2) โ are not recorded in the cached path, what lsof reports is only the path by which the file was opened, not its possibly different final path. ๐ญ Sneaky.
-z[z] โ specifies how Solaris 10 and higher zone information is to be handled.
Without a following argument โ e.g., NO z โ the option specifies that zone names are to be listed in the ZONE output column. ๐
The -z option may be followed by a zone name, z. That causes lsof to list only open files for processes in that zone. Multiple -z z option and argument pairs may be specified to form a list of named zones. Any open file of any process in any of the zones will be listed, subject to other conditions specified by other options and arguments.
-Z[Z] โ specifies how SELinux security contexts are to be handled. It andZfield output character support are inhibited when SELinux is disabled in the running Linux kernel. See OUTPUT FOR OTHER PROGRAMS for more information on theZfield output character.
Without a following argument โ e.g., NO Z โ the option specifies that security contexts are to be listed in the SECURITY-CONTEXT output column. โจ
The -Z option may be followed by a wildcard security context name, Z. That causes lsof to list only open files for processes in that security context. Multiple -Z Z option and argument pairs may be specified to form a list of security contexts. Any open file of any process in any of the security contexts will be listed, subject to other conditions specified by other options and arguments. Note that Z can be A:B:C or *:B:C or A:B:* or *:*:C to match against the A:B:C context. ๐
--โ the double minus sign option is a marker that signals the end of the keyed options. It may be used, for example, when the first file name begins with a minus sign. It may also be used when the absence of a value for the last keyed option must be signified by the presence of a minus sign in the following option and before the start of the file names. It's the "okay we're done with flags, now we're talking about FILES" divider. ๐namesโ these are path names of specific files to list. Symbolic links are resolved before use. The first name may be separated from the preceding options with the--option.
If a name is the mounted-on directory of a file system or the device of the file system, lsof will list all the files open on the file system. To be considered a file system, the name must match a mounted-on directory name in mount(8) output, or match the name of a block device associated with a mounted-on directory name. The +|-f option may be used to force lsof to consider a name a file system identifier (+f) or a simple file (-f).
If name is a path to a directory that is not the mounted-on directory name of a file system, it is treated just as a regular file is treated โ i.e., its listing is restricted to processes that have it open as a file or as a process-specific directory, such as the root or current working directory. To request that lsof look for open files inside a directory name, use the +d s and +D D options.
If a name is the base name of a family of multiplexed files โ e.g., AIX's /dev/pt[cs] โ lsof will list all the associated multiplexed files on the device that are open โ e.g., /dev/pt[cs]/1, /dev/pt[cs]/2, etc. ๐ธ
If a name is a UNIX domain socket name, lsof will usually search for it by the characters of the name alone โ exactly as it is specified and is recorded in the kernel socket structure. (See the next paragraph for an exception to that rule for Linux.) Specifying a relative path โ e.g., ./file โ in place of the file's absolute path โ e.g., /tmp/file โ won't work because lsof must match the characters you specify with what it finds in the kernel UNIX domain socket structures. So don't try to be cute with it. ๐
If a name is a Linux UNIX domain socket name, in one case lsof is able to search for it by its device and inode number, allowing name to be a relative path. The case requires that the absolute path โ i.e., one beginning with a slash (/) โ be used by the process that created the socket, and hence be stored in the /proc/net/unix file; and it requires that lsof be able to obtain the device and node numbers of both the absolute path in /proc/net/unix and name via successful stat(2) system calls. When those conditions are met, lsof will be able to search for the UNIX domain socket when some path to it is is specified in name. Thus, for example, if the path is /dev/log, and an lsof search is initiated when the working directory is /dev, then name could be ./log. ๐ฆ Slay.
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.
If you have also specified the -b option, the only names you may safely specify are file systems for which your mount table supplies alternate device numbers. See the AVOIDING KERNEL BLOCKS and ALTERNATE DEVICE NUMBERS sections for more information. ๐
Multiple file names are joined in a single ORed set before participating in AND option selection.
๐ณ AFS ๐ณ
okay so real talk โ lsof can recognize AFS files, but only for these specific dialects (and AFS versions), bestie:
AIX 4.1.4(AFS 3.4a)HP-UX 9.0.5(AFS 3.4a)Linux 1.2.13(AFS 3.3)Solaris 2.[56](AFS 3.4a)
It may recognize AFS files on other versions of these dialects, but it has not been tested there, so like... no promises. And depending on how AFS is implemented, lsof may recognize AFS files in other dialects, or it may have difficulties recognizing AFS files in the supported dialects. It's giving chaos, honestly. ๐
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. And when lsof can't compute volume node numbers, it reports blank in the NODE column. Blank. As in, we don't know her. ๐ญ
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. ๐ง
Also, 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. Not her fault, she's just working with what the kernel gave her. ๐
๐ SECURITY ๐
Bestie, listen. lsof has three features that may cause security concerns, and we're gonna go through all of them, no skimming:
- Its default compilation mode allows anyone to list all open files with it.
- By default it creates a user-readable and user-writable device cache file in the home directory of the real user ID that executes
lsof. - Its
-kand-moptions name alternate kernel name list or memory files.
(The list-all-open-files and device cache features may be disabled when lsof is compiled, fyi.)
Restricting the listing of all open files is controlled by the compile-time HASSECURITY and HASNOSOCKSECURITY options. When HASSECURITY is defined, lsof will allow only the root user to list all open files. The non-root user may list only open files of processes with the same user IDentification number as the real user ID number of the lsof process (the one that its user logged on with).
However, if HASSECURITY and HASNOSOCKSECURITY are both defined, anyone may list open socket files, provided they are selected with the -i option. Slay, I guess? ๐ซถ
When HASSECURITY is not defined, anyone may list all open files. Yeah. Everyone. The whole group chat.
Help output, presented in response to the -h or -? option, gives the status of the HASSECURITY and HASNOSOCKSECURITY definitions.
See the Security section of the 00README file of the lsof distribution for information on building lsof with the HASSECURITY and HASNOSOCKSECURITY options enabled.
Creation and use of a user-readable and user-writable device cache file is controlled by the compile-time HASDCACHE option. See the DEVICE CACHE FILE section and the sections that follow it for details on how its path is formed. For security considerations it is important to note that in the default lsof distribution, if the real user ID under which lsof is executed is root, the device cache file will be written in root's home directory โ e.g., / or /root. Yeah. /. The whole root directory. Not a vibe. ๐ When HASDCACHE is not defined, lsof does not write or attempt to read a device cache file.
When HASDCACHE is defined, the lsof help output, presented in response to the -h, -D?, or -? options, will provide device cache file handling information. When HASDCACHE is not defined, the -h or -? output will have no -D option description.
Before you decide to disable the device cache file feature โ enabling it improves the performance of lsof by reducing the startup overhead of examining all the nodes in /dev (or /devices) โ read the discussion of it in the 00DCACHE file of the lsof distribution and the lsof FAQ (The FAQ section gives its location.) ๐
โ ๏ธ WHEN IN DOUBT, YOU CAN TEMPORARILY DISABLE THE USE OF THE DEVICE CACHE FILE WITH THE -Di OPTION. โ ๏ธ
When lsof user declares alternate kernel name list or memory files with the -k and -m options, lsof checks the user's authority to read them with access(2). This is intended to prevent whatever special power lsof's modes might confer on it from letting it read files not normally accessible via the authority of the real user ID. Keeping her humble, periodt. ๐
๐ OUTPUT ๐
This section describes the information lsof lists for each open file. See the OUTPUT FOR OTHER PROGRAMS section for additional information on output that can be processed by another program.
Lsof only outputs printable (declared so by isprint(3)) 8 bit characters. Non-printable characters are printed in one of three forms: the C `\[bfrnt]' form; the control character `^' form (e.g., `^@'); or hexadecimal leading `\x' form (e.g., `\xab'). Space is non-printable in the COMMAND column (`\x20') and printable elsewhere. Little formatting princess behavior, and honestly? Iconic. โจ
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 considers 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 information.
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. She's doing the math so you don't have to. ๐
The Columns, One By One ๐
COMMANDโ contains the first nine characters of the name of the UNIX command associated with the process. If a non-zerowvalue is specified to the+c woption, the column contains the firstwcharacters of the name of the UNIX command associated with the process up to the limit of characters supplied tolsofby the UNIX dialect. (See the description of the+c wcommand or thelsofFAQ for more information. The FAQ section gives its location.)
If w is less than the length of the column title, COMMAND, it will be raised to that length.
If a zero w value is specified to the +c w option, the column contains all the characters of the name of the UNIX command associated with the process.
All command name characters maintained by the kernel in its structures are displayed in field output when the command name descriptor (c) is specified. See the OUTPUT FOR OTHER COMMANDS section for information on selecting field output and the associated command name descriptor.
PIDโ is the Process IDentification number of the process.TIDโ is the task (thread) IDentification number, if task (thread) reporting is supported by the dialect and a task (thread) is being listed. (If help output โ i.e., the output of the-hor-?options โ shows this option, then task (thread) reporting is supported by the dialect.)
A blank TID column in Linux indicates a process โ i.e., a non-task.
TASKCMDโ is the task command name. Generally this will be the same as the process named in theCOMMANDcolumn, but some task implementations (e.g., Linux) permit a task to change its command name.
The TASKCMD column width is subject to the same size limitation as the COMMAND column.
ZONEโ is the Solaris 10 and higher zone name. This column must be selected with the-zoption.SECURITY-CONTEXTโ is the SELinux security context. This column must be selected with the-Zoption. Note that the-Zoption is inhibited when SELinux is disabled in the running Linux kernel.PPIDโ is the Parent Process IDentification number of the process. It is only displayed when the-Roption has been specified.PGIDโ is the process group IDentification number associated with the process. It is only displayed when the-goption has been specified.USERโ is the user ID number or login name of the user to whom the process belongs, usually the same as reported byps(1). However, on LinuxUSERis the user ID number or login that owns the directory in/procwherelsoffinds information about the process. Usually that is the same value reported byps(1), but may differ when the process has changed its effective user ID. (See the-loption description for information on when a user ID number or login name is displayed.)FDโ is the File Descriptor number of the file or:cwdโ current working directory;Lnnโ library references (AIX);errโ FD information error (seeNAMEcolumn);jldโ jail directory (FreeBSD);ltxโ shared library text (code and data);Mxxโ hex memory-mapped type numberxx.m86โ DOS Merge mapped file;memโ memory-mapped file;mmapโ memory-mapped device;pdโ parent directory;rtdโ root directory;trโ kernel trace file (OpenBSD);txtโ program text (code and data);v86โ VP/ix mapped file;
FD is followed by one of these characters, describing the mode under which the file is open:
โฆand then the mode character itself, bestie, it's literally one of these five:
rโ read access ๐wโ write access โ๏ธuโ read and write access, she does it all ๐- space โ mode unknown and no lock character follows ๐ซฅ
-โ mode unknown, but a lock character <em>does</em> follow ๐
And then, right after that mode character, you get one of these lock characters, describing what kind of lock got slapped on the file:
Nโ a Solaris NFS lock of unknown type ๐rโ read lock on <em>part</em> of the fileRโ read lock on the <em>entire</em> file ๐wโ write lock on part of the fileWโ write lock on the entire file ๐ฅuโ a read and write lock of any lengthUโ a lock of unknown type ๐xโ an SCO OpenServer Xenix lock on part of the fileXโ an SCO OpenServer Xenix lock on the entire file- space โ there is no lock at all, she's free ๐๏ธ
Peep the LOCKS section if you want the whole tea on the lock information character, iykyk.
๐ The FD column, one more time ๐
The FD column contents constitute a single field for parsing in post-processing scripts โ so don't you dare split it, bestie. And FD numbers bigger than 9999 get abbreviated to a * followed by the last three digits. Like, 10001 shows up as *001. Cute, right? ๐ธ
โจ TYPE โจ
This one is the type of the node associated with the file โ like GDIR, GREG, VDIR, VREG, etc.
Or it's one of these iconic little guys:
IPv4โ for an IPv4 socket ๐IPv6โ for an open IPv6 network file โ and yes, even if its address is IPv4, mapped in an IPv6 address ๐ax25โ for a Linux AX.25 socketinetโ for an Internet domain socketllaโ for a HP-UX link level access filerteโ for anAF_ROUTEsocketsockโ for a socket of unknown domain ๐ซฅunixโ for a UNIX domain socketx.25โ for an HP-UX x.25 socketBLKโ for a block special fileCHRโ for a character special fileDELโ for a Linux map file that has been deleted ๐DIRโ for a directory ๐DOORโ for a VDOOR fileFIFOโ for a FIFO special fileKQUEUEโ for a BSD style kernel event queue fileLINKโ for a symbolic link file ๐MPBโ for a multiplexed block fileMPCโ for a multiplexed character fileNOFDโ for a Linux/proc/<PID>/fddirectory that can't be opened โ the directory path appears in the NAME column, followed by an error message ๐ญPASโ for a/proc/asfilePAXVโ for a/proc/auxvfilePCREโ for a/proc/credfilePCTLโ for a/proccontrol filePCURโ for the current/procprocessPCWDโ for a/proccurrent working directoryPDIRโ for a/procdirectoryPETYโ for a/procexecutable type (etype)PFDโ for a/procfile descriptorPFDRโ for a/procfile descriptor directoryPFILโ for an executable/procfilePFPRโ for a/procFP register setPGDโ for a/proc/pagedatafilePGIDโ for a/procgroup notifier filePIPEโ for pipes ๐ชPLCโ for a/proc/lwpctlfilePLDRโ for a/proc/lpwdirectoryPLDTโ for a/proc/ldtfilePLPIโ for a/proc/lpsinfofilePLSTโ for a/proc/lstatusfilePLUโ for a/proc/lusagefilePLWGโ for a/proc/gwindowsfilePLWIโ for a/proc/lwpsinfofilePLWSโ for a/proc/lwpstatusfilePLWUโ for a/proc/lwpusagefilePLWXโ for a/proc/xregsfilePMAPโ for a/procmap file (map)PMEMโ for a/procmemory image filePNTFโ for a/procprocess notifier filePOBJโ for a/proc/objectfilePODRโ for a/proc/objectdirectoryPOLPโ for an old format/proclight weight process filePOPFโ for an old format/procPID filePOPGโ for an old format/procpage data filePORTโ for a SYSV named pipePREGโ for a/procregister filePRMPโ for a/proc/rmapfilePRTDโ for a/procroot directoryPSGAโ for a/proc/sigactfilePSINโ for a/proc/psinfofilePSTAโ for a/procstatus filePSXMQโ for a POSIX message queue filePSXSEMโ for a POSIX semaphore filePSXSHMโ for a POSIX shared memory filePTSโ for a/dev/ptsfilePUSGโ for a/proc/usagefilePWโ for a/proc/watchfilePXMPโ for a/proc/xmapfileREGโ for a regular fileSMTโ for a shared memory transport fileSTSOโ for a stream socketUNNMโ for an unnamed type fileXNAMโ for an OpenServer Xenix special file of unknown typeXSEMโ for an OpenServer Xenix semaphore fileXSDโ for an OpenServer Xenix shared data file
โฆor, if the corresponding name isn't known, you just get the four type number octets. Periodt. ๐
๐ FILE-ADDR ๐
This field holds the kernel file structure address โ but only when f has been specified to +f. That's the deal. ๐ซถ
๐ FCT ๐
This one's got the file reference count from the kernel file structure โ and again, only when c has been specified to +f. No c, no count, bestie. ๐
๐ FILE-FLAG ๐
Okay so when g or G has been specified to +f, this field contains the contents of the f_flag[s] member of the kernel file structure <em>and</em> the kernel's per-process open file flags (if available).
Gmakes them display in hexadecimal โจggives you the short-hand names instead
You can get <em>two</em> lists up in here โ entries separated by commas, and the two lists separated by a semicolon (;).
The first list may contain short-hand names for f_flag[s] values, pulled straight from this table:
AIOโ asynchronous I/O (e.g.,FAIO)APโ appendASYNโ asynchronous I/O (e.g.,FASYNC)BASโ block, test, and set in useBKIUโ block if in useBLโ use block offsetsBSKโ block seekCAโ copy avoidCIOโ concurrent I/OCLONโ cloneCLRDโ CL readCRโ createDFโ deferDFIโ defer INDDFLUโ data flushDIRโ directDLYโ delayDOCLโ do cloneDSYNโ data-only integrityDTYโ must be a directoryEVOโ event onlyEXโ open for execEXCLโ exclusive openFSYNโ synchronous writesGCDFโ defer duringunp_gc()(AIX)GCMKโ mark duringunp_gc()(AIX)GTTYโ accessed via/dev/ttyHUPโ HUP in progressKERNโ kernelKIOCโ kernel-issued ioctlLCKโ has lock ๐LGโ large fileMBLKโ stream message blockMKโ markMNTโ mountMSYNโ multiplex synchronizationNATMโ don't update atimeNBโ non-blocking I/ONBDRโ no BDRM checkNBIOโ SYSV non-blocking I/ONBFโ n-buffering in effectNCโ no cacheNDโ no delayNDSYโ no data synchronizationNETโ networkNFLKโ don't follow linksNMFSโ NM file systemNOTOโ disable background stopNSHโ no shareNTTYโ no controlling TTYOLRMโ OLR mirrorPAIOโ POSIX asynchronous I/OPATHโ pathPPโ POSIX pipeRโ readRCโ file and record locking cacheREVโ revokedRSHโ shared readRSYNโ read synchronizationRWโ read and write accessSLโ shared lockSNAPโ cooked snapshotSOCKโ socketSQSHโ Sequent shared set on openSQSVโ Sequent SVM set on openSQRโ Sequent set repair on openSQS1โ Sequent full shared openSQS2โ Sequent partial shared openSTPIโ stop I/OSWRโ synchronous readSYNโ file integrity while writingTCPMโ avoid TCP collisionTMPFโ temporary fileTRโ truncateWโ writeWKUPโ parallel I/O synchronizationWTGโ parallel I/O synchronizationVHโ vhangup pendingVTXTโ virtual textXLโ exclusive lock
This list of names was derived from F* #define's in dialect header files <fcntl.h>, <linux</fs.h>, <sys/fcntl.c>, <sys/fcntlcom.h>, and <sys/file.h> โ and if you want the receipts, go see the lsof.h header file, which has a list showing the correspondence between the short-hand names above and the header file definitions. ๐โจ
And the second list (the one after the semicolon) may contain short-hand names for kernel per-process open file flags from this table:
Okay so continuing that FD flag list โ here's the rest of the alphabet soup, bestie:
ALLCโ allocatedBRโ the file has been readBHUPโ activity stopped bySIGHUPBWโ the file has been writtenCLSGโ closingCXโ close-on-exec (seefcntl(F_SETFD))LCKโ lock was appliedMPโ memory-mappedOPIPโ open pending - in progressRSVWโ reserved waitSHMTโUF_FSHMATset (AIX)USEโ in use (multi-threaded)
NODE-ID
(also called INODE-ADDR on some dialects, iykyk) โ this one holds a unique identifier for the file node. Usually that's the kernel vnode or inode address, but sometimes it's a concatenation of device and node number instead. You only get this column when n has been specified to +f, so no n, no node-id, periodt.
DEVICE
This column is giving "where does this thing actually live", and it's kind of a shapeshifter. It contains:
- the device numbers, separated by commas, for a character special, block special, regular, directory or NFS file;
- or ``memory'' for a memory file system node under Tru64 UNIX;
- or the address of the private data area of a Solaris socket stream;
- or a kernel reference address that identifies the file (the kernel reference address may be used for FIFO's, for example);
- or the base address or device name of a Linux AX.25 socket device.
Heads up: usually only the lower thirty two bits of Tru64 UNIX kernel addresses are displayed. That's just how it is, bestie. ๐
SIZE, SIZE/OFF, or OFFSET
Okay so this one is literally the size of the file or the file offset in bytes. A value shows up in this column only if it's available. Lsof displays whatever value โ size or offset โ is appropriate for the type of the file and the version of lsof. Main character behavior honestly, it just decides. โจ
On some UNIX dialects lsof can't obtain accurate or consistent file offset information from its kernel data sources, and sometimes that's just for particular kinds of files (e.g., socket files.) In other cases, files don't have true sizes โ e.g., sockets, FIFOs, pipes โ so lsof displays for their sizes the content amounts it finds in their kernel buffer descriptors (e.g., socket buffer size counts or TCP/IP window sizes.) Consult the lsof FAQ (the FAQ section gives its location.) for more information, no cap.
The file size is displayed in decimal. The offset is normally displayed in decimal with a leading 0t'' if it contains 8 digits or less, and in hexadecimal with a leading 0x'' if it's longer than 8 digits. (Consult the -o o option description for information on when 8 might default to some other value.) So the leading 0t and 0x are literally how you tell an offset apart when the column might contain both a size and an offset โ i.e., when its title is SIZE/OFF. ๐
- If the
-ooption is specified, lsof always displays the file offset (or nothing if no offset is available) and labels the column OFFSET. The offset always begins with0tor0xas described above. - The lsof user can control the switch from
0tto0xwith the-o ooption. Consult its description for more information. - If the
-soption is specified, lsof always displays the file size (or nothing if no size is available) and labels the column SIZE. - If the
-Hoption is specified, lsof displays file size in human readable form.
Careful: the-oand-soptions are mutually exclusive โ they can't both be specified. Pick a lane, bestie. ๐ญ
For files that don't have a fixed size โ e.g., don't reside on a disk device โ lsof will display appropriate information about the current size or position of the file if it is available in the kernel structures that define the file.
NLINK
Contains the file link count when +L has been specified.
NODE
The node column is also a "depends on the vibe" situation, so here's the whole menu:
- the node 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'';
- or ``STR'' for a stream;
- or ``CCITT'' for an HP-UX x.25 socket;
- or the IRQ or inode number of a Linux AX.25 socket device.
NAME
Ah, the NAME column โ the one everybody actually came here for. It's the longest list in the whole page, so buckle up, because it can be any of these:
- 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; the local host name or IP number is followed by a colon (
:), the port,->'', and the two-part remote address; IP addresses may be reported as numbers or names, depending on the `+|-M`, `-n`, and `-P` options; colon-separated IPv6 numbers are enclosed in square brackets; IPv4 `INADDR_ANY` and IPv6 `IN6_IS_ADDR_UNSPECIFIED` addresses, and zero port numbers are represented by an asterisk (`*`); a UDP destination address may be followed by the amount of time elapsed since the last packet was sent to the destination; TCP, UDP and UDPLITE remote addresses may be followed by TCP/TPI information in parentheses โ state (e.g.,(ESTABLISHED)'', ``(Unbound)''), queue sizes, and window sizes (not all dialects) โ in a fashion similar to whatnetstat(1)reports; see the-Toption description or the description of the TCP/TPI field in OUTPUT FOR OTHER PROGRAMS for more information on state, queue size, and window size; - or the address or name of a UNIX domain socket, possibly including a stream clone device name, a file system object's path name, local and foreign kernel addresses, socket pair information, and a bound vnode address;
- or the local and remote mount point names of an NFS file;
- or ``STR'', followed by the stream name;
- or a stream character device name, followed by
->'' and the stream name or a list of stream module names, separated by->''; - or
STR:'' followed by the SCO OpenServer stream device and module names, separated by->''; - or system directory name, `` -- '', and as many components of the path name as lsof can find in the kernel's name cache for selected dialects (see the KERNEL NAME CACHE section for more information.);
- or ``PIPE->'', followed by a Solaris kernel pipe destination address;
- or ``COMMON:'', followed by the vnode device information structure's device name, for a Solaris common vnode;
- or the address family, followed by a slash (
/), followed by fourteen comma-separated bytes of a non-Internet raw socket address; - or the HP-UX x.25 local address, followed by the virtual connection number (if any), followed by the remote address (if any);
- or ``(dead)'' for disassociated Tru64 UNIX files โ typically terminal files that have been flagged with the
TIOCNOTTYioctl and closed by daemons; - or
rd=<offset>'' andwr=<offset>'' for the values of the read and write offsets of a FIFO; - or ``clone n:/dev/event'' for SCO OpenServer file clones of the
/dev/eventdevice, where n is the minor device number of the file; - or ``(socketpair: n)'' for a Solaris 2.6, 8, 9 or 10 UNIX domain socket, created by the
socketpair(3N)network function; - or
no PCB'' for socket files that do not have a protocol block associated with them, optionally followed by, CANTSENDMORE'' if sending on the socket has been disabled, or ``, CANTRCVMORE'' if receiving on the socket has been disabled (e.g., by theshutdown(2)function); - or the local and remote addresses of a Linux IPX socket file in the form
<net>:[<node>:]<port>, followed in parentheses by the transmit and receive queue sizes, and the connection state; - or
dgram'' orstream'' for the type UnixWare 7.1.1 and above in-kernel UNIX domain sockets, followed by a colon (:) and the local path name when available, followed by ``->'' and the remote path name or kernel socket address in hexadecimal when available; - or the association value, association index, endpoint value, local address, local port, remote address and remote port for Linux SCTP sockets;
- or ``protocol: '' followed by the Linux socket's protocol attribute.
One more little add-on for the NAME column: for dialects that support a ``namefs'' file system โ the one that lets you attach one file to another with fattach(3C) โ lsof will tack on (FA:<address1><direction><address2>) to the NAME column. Here's the decode, bestie:
<address1>and<address2>are hexadecimal vnode addresses.<direction>will be ``<-'' if<address2>has been fattach'ed to this vnode whose address is<address1>.- and ``->'' if
<address1>, the vnode address of this vnode, has been fattach'ed to<address2>. <address1>may be omitted if it already appears in the DEVICE column.
And 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
-Xoption 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. ๐ฆ
๐ LOCKS ๐
okay bestie, so here's the tea on locks: lsof literally can't report the whole wide variety of UNIX dialect file locks in a single character. What it does report in one character is a compromise โ a little negotiated peace treaty between what it finds in the kernel and what the reporting format can actually hold. ๐
And it gets messier: when a process holds several byte level locks on a file, lsof only reports the status of the first lock it encounters. If that one's a byte level lock, the lock character comes out in lower case โ like r, w, or x โ instead of the upper case equivalent that gets reported for a full file lock. no cap.
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 is usually the one recording the lock state. There's one exception though, and it's giving special: 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 section tells you where to find it) for more info.
๐จ๏ธ OUTPUT FOR OTHER PROGRAMS ๐จ๏ธ
When the -F option gets specified, lsof produces output that's suitable for processing by another program โ like an awk or Perl script, or a C program. It's giving โจmachine-readableโจ.
Each unit of information is output in a field that's 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.
๐ process sets and file sets ๐
It's possible to think of field output as process and file sets, bestie.
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) number, 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's 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. In repeat mode, the marker (m) is also produced. 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. two birds, one stone, iconic.
Not me bringing up version drama but: lsof versions from4.88to4.93.2always produced one more field, the file descriptor (f) field. However, lsof in this version doesn't produce it. This change is for supporting the use case where a user needs only the PID field, and doesn't need the file descriptor field. Specifyfexplicitly if you need the field. ๐
It is entirely possible to select a set of fields that cannot easily be parsed โ e.g., if the field descriptor field isn't 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.
โญ the fields โญ
These are the fields that lsof will produce. The single character listed first is the field identifier. ๐
aโ file access modecโ process command name (all characters from proc or user structure)Cโ file structure share countdโ file's device character codeDโ file's major/minor device number (0x<hexadecimal>)fโ file descriptorFโ file structure address (0x<hexadecimal>)Gโ file flaGs (0x<hexadecimal>; names if+fgfollows)gโ process group IDiโ file's inode numberKโ tasK IDkโ link countlโ file's lock statusLโ process login namemโ marker between repeated output (always selected in repeat mode)Mโ the task comMand namenโ file name, comment, Internet addressNโ node identifier (ox<hexadecimal>oโ file's offset (0t<decimal>or0x<hexadecimal>, see-o o)pโ process ID (always selected)Pโ protocol namerโ raw device number (0x<hexadecimal>)Rโ parent process IDsโ file's size (decimal)Sโ file's stream identificationtโ file's typeTโ TCP/TPI information, identified by prefixes (the=is part of the prefix):QR=<read queue size>QS=<send queue size>SO=<socket options and values>(not all dialects)SS=<socket states>(not all dialects)ST=<connection state>TF=<TCP flags and values>(not all dialects)WR=<window read size>(not all dialects)WW=<window write size>(not all dialects)- (TCP/TPI information isn't reported for all supported UNIX dialects. The
-hor-?help output for the-Toption will show what TCP/TPI reporting can be requested.)
uโ process user IDzโ Solaris 10 and higher zone nameZโ SELinux security context (inhibited when SELinux is disabled)0โ use NUL field terminator character in place of NL1-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 โ shells are dramatic like that. ๐ญ) 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. slay.
๐ the mutually exclusive bit ๐
Lsof doesn't produce all fields for every process or file set, only those that are available. Some fields are mutually exclusive, bestie:
- 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. periodt.
๐ธ terminators ๐ธ
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 little helpers ๐ง
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 explanation 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. ๐ซถ
โณ BLOCKS AND TIMEOUTS โณ
Lsof can be blocked by some kernel functions that it uses โ lstat(2), readlink(2), and stat(2). These functions are stalled in the kernel, for example, when the hosts where mounted NFS file systems reside become inaccessible. ๐
Lsof attempts to break these blocks with timers and child processes, but ngl, the techniques are not wholly reliable. When lsof does manage 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. ๐ญ don't do that to yourself.
When lsof has to break a block during its access of mounted file system information, it normally continues, although with less information 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 situations that might block it.
โ ๏ธ Use this option cautiously. like, genuinely. main character energy but for danger. ๐
AVOIDING KERNEL BLOCKS ๐
okay bestie, so -b is literally the "please don't block me, I'm just a little guy" button. It tells lsof to avoid using kernel functions that would block. but there are some cautions, and we are going to go through them because we're responsible and iconic. โจ
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 info 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 completely 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 symbolic links. no link resolution for you, bestie.
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. so like, pick your poison, but at least you know. ๐ซถ
ALTERNATE DEVICE NUMBERS โจ
on some dialects, when lsof has to break a block because it can't 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's 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 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.
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.) here's 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 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. that's the glow-up. ๐
some dialects that do not use an ASCII /etc/mtab or /etc/mnttab file for the mount table may still provide an alternative device number 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 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:
lsof -b
look for standard error file warning messages that begin assuming "dev=xxxx" from ....
KERNEL NAME CACHE ๐ง
lsof is able to examine the kernel's name cache or use other kernel facilities (e.g., the ADVFS 4.x tag_to_path() function under Tru64 UNIX) on some dialects for most file system types, excluding AFS, and extract recently used path name components from it. (AFS file system path lookups don't use the kernel's name cache; some Solaris VxFS file system operations apparently don't use it, either.) ๐ธ
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. it's giving chaos, but that's just how it is. ๐ญ
lsof's use of the kernel name cache to identify the paths of files can lead it to report incorrect components under some circumstances. 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
- OpenBSD
- 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 location.)
DEVICE CACHE FILE ๐
examining all members of the /dev (or /devices) node tree with stat(2) functions can be time consuming. what's more, the information that lsof needs โ device number, inode number, and path โ rarely changes. so like, why do all that work every single time? exactly. ๐
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
-Doption; - 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 legitimately 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.
- AIX 5.[12] and 5.3-ML1
- Apple Darwin 7.x Power Macintosh systems
- FreeBSD 4.x, 4.1x, 5.x and [6789].x for x86-based systems
- FreeBSD 5.x, [6789].x and 1[012].8for Alpha, AMD64 and Sparc64 based systems
- HP-UX 11.00
- NetBSD 1.[456], 2.x and 3.x for Alpha, x86, and SPARC-based systems
- OpenBSD 2.[89] 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 file.
- Linux
๐พ DEVICE CACHE FILE PATH FROM THE -D OPTION
okay so the -D option is lsof's lowkey limited little toolkit for telling it where the device cache file should live. its ? function will straight up report the read-only and write device cache file paths that lsof is gonna use. bestie reveal. โจ
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]). But here's the tea ๐ซ โ the b, r, and u functions are restricted under some conditions. They're restricted when the lsof process is setuid-root. And 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. (Peep 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. it's the chill one. no cap.
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. it's giving thorough.
๐ฑ 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.
heads up bestie: lsof will never write to the system-wide device cache file path by default. It must be explicitly named with a-Dfunction in a root-owned procedure. Once the file has been written, the procedure must change its permission modes to0644(owner-read and owner-write, group-read, and other-read). periodt.
๐ 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. cute lil suffix tbh. ๐
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 distinct 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. it's giving organized. โจ
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 format 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 %p 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 lsof.itap.purdue.edu, and the HASPERSDC format is the default (%h/%p.lsof_%L), the modified personal device cache file path is:
/Homes/abe/LSOF/.lsof_vic
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 permission.)
If, for example, you want to create a sub-directory of personal device cache file paths by using the LSOFPERSDCPATH environment variable 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. ๐
manual labor era.
The local system administrator may: disable this option when lsof is built; change the name of the environment variable from LSOFPERSDCPATH 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 specification.
๐ฉบ 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 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. If the -Q option is specified, lsof will ignore any search item failures and only return an error if something unusual and unrecoverable happened.
It returns a zero (0) if no errors were detected and if either the -Q option was specified or it was able to list some information about all the specified search arguments. slay. โ
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 indicated in its help output โ requested with the -h or -? 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. ๐ they just needed a lil time.
๐ธ EXAMPLES ๐ธ
Ok bestie, this is the part where we stop talking about lsof and start using lsof, and honestly? It's giving cheat-sheet energy. ๐
For a more extensive set of examples, documented more fully, see the 00QUICKSTART file of the lsof distribution.
Wanna list, like, all the open files? Just say the word:
lsof
Wanna see all the open Internet, x.25 (HP-UX), and UNIX domain files? Slay:
lsof -i -U
Wanna see all open IPv4 network files being used by the process whose PID is 1234? Go off:
lsof -i 4 -a -p 1234
Now โ if it's totally fine that PID 1234 doesn't exist, or that PID 1234 has zero open IPv4 network files, then add -Q:
lsof -Q -i 4 -a -p 1234
Presuming your UNIX dialect supports IPv6, and you only want the open IPv6 network files:
lsof -i 6
Wanna list all the files using any protocol on ports 513, 514, or 515 of host wonderland.cc.purdue.edu? Periodt:
lsof -i @wonderland.cc.purdue.edu:513-515
And all the files using any protocol on any port of mace.cc.purdue.edu โ where cc.purdue.edu is the default domain โ is just:
lsof -i @mace
Now, to list all open files for login name ``abe'', or user ID 1234, or process 456, or process 123, or process 789, all in one go:
lsof -p 456,123,789 -u 1234,abe
To list all open files on device /dev/hd4:
lsof /dev/hd4
To find the process that has /u/abe/foo open, without stressing about whether there even is one:
lsof -Q /u/abe/foo
To take action only if a process actually has /u/abe/foo open:
lsof /u/abe/foo echo "still in use"
To send a SIGHUP to the processes that have /u/abe/bar open:
kill -HUP `lsof -t /u/abe/bar`
To find any open file โ including an open UNIX domain socket file โ with the name /dev/log:
lsof /dev/log
To 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 /nfs/mount/point:
lsof -b /nfs/mount/point
And to do that exact same search but with the warning messages suppressed:
lsof -bw /nfs/mount/point
To ignore the device cache file entirely:
lsof -Di
To get PID and command name field output for each process, plus file descriptor, file device number, and file inode number for each file of each process:
lsof -FpcfDi
To 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
To 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 -c c option:
lsof -c /^..o.$/i -a -d cwd
To find an IP version 4 socket file by its associated numeric dot-form address:
lsof -i@128.210.15.17
To find an IP version 6 socket file (when the UNIX dialect supports IPv6) by its associated numeric colon-form address:
lsof -i@[0:1:2:3:4:5:6:7]
To find an 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 โ like, say, the loop-back address:
lsof -i@[::1]
To obtain a repeat mode marker line that contains the current time:
lsof -rm====%T====
And to add spaces to that previous marker line:
lsof -r "m==== %T ===="
๐ BUGS ๐
Ok so this is the "no cap, here's where it gets messy" section. Read it, bestie. ๐ซถ
- Since
lsofreads kernel memory in its search for open files, rapid changes in kernel memory may produce unpredictable results. - 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.
lsofcan'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. lsofcan't always represent Solaris device numbers the same way thatls(1)does. For example, the major and minor device numbers that thelstat(2)andstat(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
/procfile 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
/procfile items โ device number, inode number, and file size โ are unavailable in some dialects. Searching for files in a/procfile 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 labeledmemdescriptors. lsofcan't search for Tru64 UNIX named pipes by name, because their kernel implementation oflstat(2)returns an improper device number for a named pipe.lsofcan'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.hheader file. One way to create such file structures is to run X clients with theDISPLAYvariable set to ``:0.0''. - The
+|-f[cfn]option is not supported under/proc-based Linuxlsof, because it doesn't read kernel structures from kernel memory.
๐ ENVIRONMENT ๐
lsof may access these environment variables, bestie. Learn them, love them. โจ
LANGโ defines a language locale. Seesetlocale(3)for the names of other variables that can be used in place ofLANGโ e.g.,LC_ALL,LC_TYPE, etc.LSOFDEVCACHEโ defines the path to a device cache file. See the DEVICE CACHE PATH FROM AN ENVIRONMENT VARIABLE section for more information.LSOFPERSDCPATHโ defines 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 (an FAQ) are available in the 00FAQ file of the lsof distribution.
And the latest version of that file lives right here:
https://github.com/lsof-org/lsof/blob/master/00FAQ
๐ฆ FILES ๐ฆ
The files lsof cares about, in all their glory:
/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 bygethostname(2).)
๐ AUTHORS ๐
Lsof was written by Victor A.Abell <abe@purdue.edu> of Purdue University. Since version 4.93.0, the lsof-org team at GitHub maintains lsof. Many others have contributed to lsof. They're listed in the 00CREDITS file of the lsof distribution. ๐
๐ธ DISTRIBUTION ๐ธ
The latest distribution of lsof is available at
https://github.com/lsof-org/lsof/releases
โญ SEE ALSO โญ
Quick heads up: not all the following manual pages may exist in every UNIX dialect to which lsof has been ported. ๐
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), open(2), perl(1), ps(1), readlink(2), setlocale(3), stat(2), strftime(3), time(2), uname(1).
and that's the whole page, bestie!! ๐โจ This was revision 4.98.0 of the LSOF(1) manual โ go forth and list some open files, you absolute icon. ๐ ๐ซถ๐
๐ฆ where this page comes from
- centos-stream 10: lsof 4.98.0-7.el10 ยท lsof
- fedora 43: lsof 4.98.0-8.fc43 ยท lsof
- fedora 44: lsof 4.98.0-9.fc44 ยท lsof
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms