Linux "lsof" Command Line Options and Examples
list open files

Lsof revision 4.89 lists on its standard output file information about files opened by processes for the following UNIX dialects: Apple Darwin 9 and Mac OS X 10.[567] FreeBSD 8.


Usage:

lsof [ -?abChKlnNOPRtUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [ +|-D D ] [ +|-e s ] [ +|-E ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s]
] [ -i [i] ] [ -k k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o [o] ] [ -p s ] [ +|-r [t[m]] ] [ -s [p:s] ] [ -S [t] ] [ -T [t] ] [
-u s ] [ +|-w ] [ -x [fl] ] [ -z [z] ] [ -Z [Z] ] [ -- ] [names]






Command Line Options:

-
as the separate options. Be careful of prefix grouping when one or more options in the group does take on separate meanings underdifferent prefixes - e.g., +|-M; ``-iM'' is not the same request as ``-i +M''. When in doubt, use separate options with appropriateprefixes.
lsof - ...
-?
detects an error in the options supplied to it, after it has displayed messages explaining each error. (Escape the `?'character as your shell requires.)
lsof -? ...
-a
causes list selection options to be ANDed, as described above.
lsof -a ...
-i6
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 address3ffe:1ebc::1, port 1234UDP:who - UDP who service portTCP@lsof.itap:513 - TCP, port 513 and host name lsof.itaptcp@foo:1-10,smtp,99 - TCP, ports 1 through 10,service name smtp, port 99, host name footcp@bar:1-smtp - TCP, ports 1 through smtp, host bar:time - either TCP, UDP or UDPLITE time service port
lsof -i6 ...
-N
selects the listing of NFS files.
lsof -N ...
-oo10
The default number of digits allowed after ``0t'' is normally 8, but may have been changed by the lsof builder. Consult thedescription of the -o o option in the output of the -h or -? option to determine the default that is in effect.
lsof -oo10 ...
-R
directs lsof to list the Parent Process IDentification number in the PPID column.
lsof -R ...
-iTCP
Or, for example, to list network files with all UDP states except Idle, use:
lsof -iTCP ...
-iUDP
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.See the lsof FAQ (The FAQ section gives its location.) for more information on how to use protocol state exclusion andinclusion, including examples.The -o (without a following decimal digit count) and -s option (without a following protocol and state name list) are mutu‐ally exclusive; they can't both be specified. When neither is specified, lsof displays whatever value - size or offset - isappropriate and available for the type of file.Since some types of files don't have true sizes - sockets, FIFOs, pipes, etc. - lsof displays for their sizes the contentamounts in their associated kernel buffers, if possible.
lsof -iUDP ...
-T
with no following key characters disables TCP/TPI information reporting.
lsof -T ...
-U
selects the listing of UNIX domain socket files.
lsof -U ...
-X
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, its use on a busy AIX system might cause an applicationprocess to hang so completely that it can neither be killed nor stopped. I have never seen this happen or had a report ofits happening, but I think there is a remote possibility it could happen.By default use of readx() is disabled. On AIX 5L and above lsof may need setuid-root permission to perform the actions thisoption requests.The lsof builder may specify that the -X option be restricted to processes whose real UID is root. If that has 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 defaultlsof 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 itmay 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 theStale Segment ID bug. It can cause the kernel's dir_search() function to believe erroneously that part of an in-memory copyof a file system directory has been zeroed. Another application process, distinct from lsof, asking the kernel to searchthe 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 com‐plete 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 pro‐cessing of whose information in the /proc/net/tcp* and /proc/net/udp* files would take lsof a long time, and whose reportingis 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 withopen 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., removedwith 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 beendeleted.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.
lsof -X ...
-z
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. Mul‐tiple -z z option and argument pairs may be specified to form a list of named zones. Any open file of any process in any ofthe zones will be listed, subject to other conditions specified by other options and arguments.
lsof -z ...
-'
character follows.The mode character is followed by one of these lock characters, describing the type of lock applied to the file:N for a Solaris NFS lock of unknown type;r for read lock on part of the file;R for a read lock on the entire file;w for a write lock on part of the file;W for a write lock on the entire file;u for a read and write lock of any length;U for a lock of unknown type;x for an SCO OpenServer Xenix lock on part of the file;X for an SCO OpenServer Xenix lock on the entire file;space if there is no lock.See the LOCKS section for more information on the lock information character.The FD column contents constitutes a single field for parsing in post-processing scripts.TYPE is the type of the node associated with the file - e.g., GDIR, GREG, VDIR, VREG, etc.or ``IPv4'' for an IPv4 socket;or ``IPv6'' for an open IPv6 network file - even if its address is IPv4, mapped in an IPv6 address;or ``ax25'' for a Linux AX.25 socket;or ``inet'' for an Internet domain socket;or ``lla'' for a HP-UX link level access file;or ``rte'' for an AF_ROUTE socket;or ``sock'' for a socket of unknown domain;or ``unix'' for a UNIX domain socket;or ``x.25'' for an HP-UX x.25 socket;or ``BLK'' for a block special file;or ``CHR'' for a character special file;or ``DEL'' for a Linux map file that has been deleted;or ``DIR'' for a directory;or ``DOOR'' for a VDOOR file;or ``FIFO'' for a FIFO special file;or ``KQUEUE'' for a BSD style kernel event queue file;or ``LINK'' for a symbolic link file;or ``MPB'' for a multiplexed block file;or ``MPC'' for a multiplexed character file;or ``NOFD'' for a Linux /proc/<PID>/fd directory that can't be opened -- the directory path appears in the NAME column,followed by an error message;or ``PAS'' for a /proc/as file;or ``PAXV'' for a /proc/auxv file;or ``PCRE'' for a /proc/cred file;or ``PCTL'' for a /proc control file;or ``PCUR'' for the current /proc process;or ``PCWD'' for a /proc current working directory;or ``PDIR'' for a /proc directory;or ``PETY'' for a /proc executable type (etype);or ``PFD'' for a /proc file descriptor;or ``PFDR'' for a /proc file descriptor directory;or ``PFIL'' for an executable /proc file;or ``PFPR'' for a /proc FP register set;or ``PGD'' for a /proc/pagedata file;or ``PGID'' for a /proc group notifier file;or ``PIPE'' for pipes;or ``PLC'' for a /proc/lwpctl file;or ``PLDR'' for a /proc/lpw directory;or ``PLDT'' for a /proc/ldt file;or ``PLPI'' for a /proc/lpsinfo file;or ``PLST'' for a /proc/lstatus file;or ``PLU'' for a /proc/lusage file;or ``PLWG'' for a /proc/gwindows file;or ``PLWI'' for a /proc/lwpsinfo file;or ``PLWS'' for a /proc/lwpstatus file;or ``PLWU'' for a /proc/lwpusage file;or ``PLWX'' for a /proc/xregs file;or ``PMAP'' for a /proc map file (map);or ``PMEM'' for a /proc memory image file;or ``PNTF'' for a /proc process notifier file;or ``POBJ'' for a /proc/object file;or ``PODR'' for a /proc/object directory;or ``POLP'' for an old format /proc light weight process file;or ``POPF'' for an old format /proc PID file;or ``POPG'' for an old format /proc page data file;or ``PORT'' for a SYSV named pipe;or ``PREG'' for a /proc register file;or ``PRMP'' for a /proc/rmap file;or ``PRTD'' for a /proc root directory;or ``PSGA'' for a /proc/sigact file;or ``PSIN'' for a /proc/psinfo file;or ``PSTA'' for a /proc status file;or ``PSXSEM'' for a POSIX semaphore file;or ``PSXSHM'' for a POSIX shared memory file;or ``PUSG'' for a /proc/usage file;or ``PW'' for a /proc/watch file;or ``PXMP'' for a /proc/xmap file;or ``REG'' for a regular file;or ``SMT'' for a shared memory transport file;or ``STSO'' for a stream socket;or ``UNNM'' for an unnamed type file;or ``XNAM'' for an OpenServer Xenix special file of unknown type;or ``XSEM'' for an OpenServer Xenix semaphore file;or ``XSD'' for an OpenServer Xenix shared data file;or the four type number octets if the corresponding name isn't known.FILE-ADDR contains the kernel file structure address when f has been specified to +f;FCT contains the file reference count from the kernel file structure when c has been specified to +f;FILE-FLAG when g or G has been specified to +f, this field contains the contents of the f_flag[s] member of the kernel file struc‐ture and the kernel's per-process open file flags (if available); `G' causes them to be displayed in hexadecimal; `g', asshort-hand names; two lists may be displayed with entries separated by commas, the lists separated by a semicolon (`;');the first list may contain short-hand names for f_flag[s] values from the following 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 during unp_gc() (AIX)GCMK mark during unp_gc() (AIX)GTTY accessed via /dev/ttyHUP HUP in progressKERN kernelKIOC kernel-issued ioctlLCK has lockLG 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/OPP 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 collisionTR truncateW writeWKUP parallel I/O synchronizationWTG parallel I/O synchronizationVH vhangup pendingVTXT virtual textXL exclusive lockthis 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>; see the lsof.h header file for a list showing the correspondence between the aboveshort-hand names and the header file definitions;the second list (after the semicolon) may contain short-hand names for kernel per-process open file flags from this table:ALLC allocatedBR the file has been readBHUP activity stopped by SIGHUPBW the file has been writtenCLSG closingCX close-on-exec (see fcntl(F_SETFD))LCK lock was appliedMP memory-mappedOPIP open pending - in progressRSVW reserved waitSHMT UF_FSHMAT set (AIX)USE in use (multi-threaded)NODE-ID (or INODE-ADDR for some dialects) contains a unique identifier for the file node (usually the kernel vnode or inodeaddress, but also occasionally a concatenation of device and node number) when n has been specified to +f;DEVICE 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 exam‐ple.);or the base address or device name of a Linux AX.25 socket device.Usually only the lower thirty two bits of Tru64 UNIX kernel addresses are displayed.SIZE, SIZE/OFF, or OFFSETis the size of the file or the file offset in bytes. A value is displayed in this column only if it is available. Lsofdisplays whatever value - size or offset - is appropriate for the type of the file and the version of lsof.On some UNIX dialects lsof can't obtain accurate or consistent file offset information from its kernel data sources, some‐times just for particular kinds of files (e.g., socket files.) In other cases, files don't have true sizes - e.g., sock‐ets, 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.) formore information.The file size is displayed in decimal; the offset is normally displayed in decimal with a leading ``0t'' if it contains 8digits or less; in hexadecimal with a leading ``0x'' if it is longer than 8 digits. (Consult the -o o option descriptionfor information on when 8 might default to some other value.)Thus the leading ``0t'' and ``0x'' identify an offset when the column may contain both a size and an offset (i.e., itstitle is SIZE/OFF).If the -o option is specified, lsof always displays the file offset (or nothing if no offset is available) and labels thecolumn OFFSET. The offset always begins with ``0t'' or ``0x'' as described above.The lsof user can control the switch from ``0t'' to ``0x'' with the -o o option. Consult its description for more infor‐mation.If the -s option is specified, lsof always displays the file size (or nothing if no size is available) and labels the col‐umn SIZE. The -o and -s options are mutually exclusive; they can't both be specified.For files that don't have a fixed size - e.g., don't reside on a disk device - lsof will display appropriate informationabout 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 is 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 is the name of the mount point and file system on which the file resides;or the name of a file specified in the names option (after any symbolic links have been resolved);or the name of a character special or block special device;or the local and remote Internet addresses of a network file; 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 onthe +|-M, -n, and -P options; colon-separated IPv6 numbers are enclosed in square brackets; IPv4 INADDR_ANY and IPv6IN6_IS_ADDR_UNSPECIFIED addresses, and zero port numbers are represented by an asterisk ('*'); a UDP destination addressmay be followed by the amount of time elapsed since the last packet was sent to the destination; TCP, UDP and UDPLITEremote 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 what netstat(1) reports; see the -T optiondescription or the description of the TCP/TPI field in OUTPUT FOR OTHER PROGRAMS for more information on state, queuesize, 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 pathname, 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 cachefor 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 socketaddress;or the HP-UX x.25 local address, followed by the virtual connection number (if any), followed by the remote address (ifany);or ``(dead)'' for disassociated Tru64 UNIX files - typically terminal files that have been flagged with the TIOCNOTTYioctl and closed by daemons;or ``rd=<offset>'' and ``wr=<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/event device, where n is the minor device number ofthe 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 dis‐abled (e.g., by the shutdown(2) function);or the local and remote addresses of a Linux IPX socket file in the form <net>:[<node>:]<port>, followed in parentheses bythe transmit and receive queue sizes, and the connection state;or ``dgram'' or ``stream'' 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 hexadeci‐mal when available;or the association value, association index, endpoint value, local address, local port, remote address and remote port forLinux SCTP sockets;or ``protocol: '' followed by the Linux socket's protocol attribute.For dialects that support a ``namefs'' file system, allowing one file to be attached to another with fattach(3C), lsof will add``(FA:<address1><direction><address2>)'' to the NAME column. <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 vnodeaddress of this vnode, has been fattach'ed to <address2>. <address1> may be omitted if it already appears in the DEVICE column.Lsof may add two parenthetical notes to the NAME column for open Solaris 10 files: ``(?)'' if lsof considers the path name of ques‐tionable accuracy; and ``(deleted)'' if the -X option has been specified and lsof detects the open file's path name has been deleted.Consult the lsof FAQ (The FAQ section gives its location.) for more information on these NAME column additions.LOCKSLsof can't adequately report the wide variety of UNIX dialect file locks in a single character. What it reports in a single charac‐ter is a compromise between the information it finds in the kernel and the limitations of the reporting format.Moreover, when a process holds several byte level locks on a file, lsof only reports the status of the first lock it encounters. Ifit is a byte level lock, then the lock character will be reported in lower case - i.e., `r', `w', or `x' - rather than the upper caseequivalent reported for a full file lock.Generally lsof can only report on locks held by local processes on local files. When a local process sets a lock on a remotelymounted (e.g., NFS) file, the remote server host usually records the lock state. One exception is Solaris - at some patch levels of2.3, and in all versions above 2.4, the Solaris kernel records information on remote locks in local structures.Lsof has trouble reporting locks for some UNIX dialects. Consult the BUGS section of this manual page or the lsof FAQ (The FAQ sec‐tion gives its location.) for more information.OUTPUT FOR OTHER PROGRAMSWhen the -F option is specified, lsof produces output that is suitable for processing by another program - e.g, an awk or Perlscript, or a C program.Each unit of information is output in a field that is identified with a leading character and terminated by a NL (012) (or a NUL(000) if the 0 (zero) field identifier character is specified.) The data of the field follows immediately after the field identifi‐cation character and extends to the field terminator.It is possible to think of field output as process and file sets. A process set begins with a field whose identifier is `p' (forprocess 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 is followed by lines that describe the file'saccess mode, lock state, type, device, size, offset, inode, protocol, name and stream module names. It extends to the beginning ofthe 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 fileset with a NL (012) character.Lsof always produces one field, the PID (`p') field. All other fields may be declared optionally in the field identifier characterlist that follows the -F option. When a field selection character identifies an item lsof does not normally list - e.g., PPID,selected with -R - specification of the field character - e.g., ``-FR'' - also selects the listing of the item.It is entirely possible to select a set of fields that cannot easily be parsed - e.g., if the field descriptor field is not selected,it may be difficult to identify file sets. To help you avoid this difficulty, lsof supports the -F option; it selects the output ofall fields with NL terminators (the -F0 option pair selects the output of all fields with NUL terminators). For compatibility rea‐sons neither -F nor -F0 select the raw device field.These are the fields that lsof will produce. The single character listed first is the field identifier.a file access modec process command name (all characters from proc oruser structure)C file structure share countd file's device character codeD file's major/minor device number (0x<hexadecimal>)f file descriptor (always selected)F file structure address (0x<hexadecimal>)G file flaGs (0x<hexadecimal>; names if +fg follows)g process group IDi file's inode numberK tasK IDk link countl file's lock statusL process login namem marker between repeated outputn file name, comment, Internet addressN node identifier (ox<hexadecimal>o file's offset (decimal)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 supportedUNIX dialects. The -h or -? help output for the
lsof -' ...
-9
of -F? identifies the information to be foundin dialect-specific fields.)You can get on-line help information on these characters and their descriptions by specifying the -F? option pair. (Escape the `?'character as your shell requires.) Additional information on field content can be found in the OUTPUT section.As an example, ``-F pcfn'' will select the process ID (`p'), command name (`c'), file descriptor (`f') and file name (`n') fieldswith an NL field terminator character; ``-F pcfn0'' selects the same output with a NUL (000) field terminator character.Lsof doesn't produce all fields for every process or file set, only those that are available. Some fields are mutually exclusive:file device characters and file major/minor device numbers; file inode number and protocol name; file name and stream identification;file size and offset. One or the other member of these mutually exclusive sets will appear in field output, but not both.Normally lsof ends each field with a NL (012) character. The 0 (zero) field identifier character may be specified to change thefield terminator character to a NUL (000). A NUL terminator may be easier to process with xargs (1), for example, or with programswhose quoting mechanisms may not easily cope with the range of characters in the field output. When the NUL field terminator is inuse, lsof ends each process and file set with a NL (012).Three aids to producing programs that can process lsof field output are included in the lsof distribution. The first is a C headerfile, lsof_fields.h, that contains symbols for the field identification characters, indexes for storing them in a table, and explana‐tion strings that may be compiled into programs. Lsof uses this header file.The second aid is a set of sample scripts that process field output, written in awk, Perl 4, and Perl 5. They're located in thescripts 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 thecorrect operation of lsof. The library can be found in the tests/LTlib.c file of the lsof distribution. The library uses the firstaid, the lsof_fields.h header file.BLOCKS AND TIMEOUTSLsof can be blocked by some kernel functions that it uses - lstat(2), readlink(2), and stat(2). These functions are stalled in thekernel, 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 the techniques are not wholly reliable. When lsof does man‐age to break a block, it will report the break with an error message. The messages may be suppressed with the -t and -w options.The default timeout value may be displayed with the -h or -? option, and it may be changed with the -S [t] option. The minimum fort is two seconds, but you should avoid small values, since slow system responsiveness can cause short timeouts to expire unexpectedlyand perhaps stop lsof before it can produce any output.When lsof has to break a block during its access of mounted file system information, it normally continues, although with less infor‐mation available to display about open files.Lsof can also be directed to avoid the protection of timers and child processes when using the kernel functions that might block byspecifying the -O option. While this will allow lsof to start up with less overhead, it exposes lsof completely to the kernel situa‐tions that might block it. Use this option cautiously.AVOIDING KERNEL BLOCKSYou can use the -b option to tell lsof to avoid using kernel functions that would block. Some cautions apply.First, using this option usually requires that your system supply alternate device numbers in place of the device numbers that lsofwould normally obtain with the lstat(2) and stat(2) kernel functions. See the ALTERNATE DEVICE NUMBERS section for more informationon 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 deviceand 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 dependscompletely on the availability and accuracy of the alternates. If no alternates are available, or if they're incorrect, lsof won'tbe 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'tbe able to resolve the links. This is because the -b option causes lsof to avoid the kernel readlink(2) function it uses to resolvesymbolic links.Finally, using the -b option causes lsof to issue warning messages when it needs to use the kernel functions that the -b optiondirects it to avoid. You can suppress these messages by specifying the -w option, but if you do, you won't see the alternate devicenumbers reported in the warning messages.ALTERNATE DEVICE NUMBERSOn some dialects, when lsof has to break a block because it can't get information about a mounted file system via the lstat(2) andstat(2) kernel functions, or because you specified the -b option, lsof can obtain some of the information it needs - the device num‐ber and possibly the file system type - from the system mount table. When that is possible, lsof will report the device number itobtained. (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 byadding 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
lsof -9 ...