man lsof
lsof - list open files
lsof [ -?abChlnNOPRstUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [ +|-D D ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s] ] [ -i [i] ] [ -k k ] [ +|-L [l] ] [ +|-m m ] [
+|-M ] [ -o [o] ] [ -p s ] [ +|-r [t] ] [ -S [t] ] [ -T [t] ] [ -u s ] [ +|-w ] [ -x [fl] ] [ -z [z] ] [ -Z [Z] ] [ -- ] [names]
Lsof revision 4.78 lists information about files opened by processes for the following UNIX dialects:
Apple Darwin 7.x and 8.x for Power Macintosh systems
FreeBSD 4.x, 4.1x, 5.x and [67].x for x86-based systems
FreeBSD 5.x and [67].x for Alpha, AMD64 and Sparc64-based
systems
HP-UX 11.00, 11.11 and 11.23
Linux 2.1.72 and above for x86-based systems
NetBSD 1.[456], 2.x and 3.x for Alpha, x86, and SPARC-based
systems
NEXTSTEP 3.[13] for NEXTSTEP architectures
OpenBSD 2.[89] and 3.[0-9] for x86-based systems
OPENSTEP 4.x
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
(Internet socket, NFS file or UNIX domain socket.) A specific file or all the files in a file system may be selected by path.
section for more information.
stopped with an interrupt or quit signal. See the +|-r [t] option description for more information.
In the absence of any options, lsof lists all open files belonging to all active processes.
files won’t be listed unless -N is also specified; or if a user list is specified with the -u option, UNIX domain socket files, belonging to users not in the list,
won’t be listed unless the -U option is also specified.
Normally list options that are specifically stated are ORed - i.e., specifying the -i option without an address and the -ufoo option produces a listing of all net-
work files OR files belonging to processes owned by user ‘‘foo’’. Three exceptions are: 1) the ‘^’ (negated) login name or user ID (UID), specified with the -u
option; 2) the ‘^’ (negated) process ID (PID), specified with the -p option; and 3) the ‘^’ (negated) process group ID (PGID), specified with the -g option. Since
they represent exclusions, they are applied without ORing or ANDing and take effect before any other selection criteria are applied.
owned by user ‘‘foo’’.
them, even though its placement there is acceptable. Wherever -a is placed, it causes the ANDing of all selection options.
joined in a single ORed set and applied before the result participates in ANDing. Thus, for example, specifying -i@aaa.bbb, -i@ccc.ddd, -a, and -ufff,ggg will
select the listing of files that belong to either login ‘‘fff’’ OR ‘‘ggg’’ AND have network connections to either host aaa.bbb OR ccc.ddd.
+|-f, -F, -g, -i, +|-L, -o, +|-r, -S, -T, -x and -z. when you have no values for them be careful that the following character isn’t ambiguous. For example, -Fn
might represent the -F and -n options, or it might represent the n field identifier character following the -F option. When ambiguity is possible, start a new
option with a ‘-’ character - e.g., ‘‘-F -n’’. If the next option is a file name, follow the possibly ambiguous option with ‘‘--’’ - e.g., ‘‘-F -- name’’.
under either prefix. Thus, for example, ‘‘+M -i’’ may be stated as ‘‘+Mi’’ and the group means the same as the separate options. Be careful of prefix grouping
when one or more options in the group does take on separate meanings under different prefixes - e.g., +|-M; ‘‘-iM’’ is not the same request as ‘‘-i +M’’. When in
doubt, use separate options with appropriate prefixes.
supplied to it, after it has displayed messages explaining each error. (Escape the ‘?’ character as your shell requires.)
an alternate name list file where the kernel addresses of the dynamic modules might be found. See the lsof FAQ (The FAQ section gives its location.) for
more information about dynamic modules, their symbols, and how they affect lsof.
using multiple -c options. They are joined in a single ORed set before participating in AND option selection.
expression must be quoted to prevent their interpretation by the shell. The closing slash may be followed by these modifiers:
i ignore the case of letters.
x the regular expression is an extended one
(default).
the command regular expression test isn’t made. This may result in ‘‘no command found for regex:’’ messages when lsof’s -V option is specified.
be printed in the COMMAND column. (The lsof default is nine.)
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 charac-
ters.
descend the directory tree, rooted at s. The +D D option may be used to request a full-descent directory tree search, rooted at directory D.
file system mount points on subdirectories of s unless the -x or -x f option is also specified.
comma-separated set s - e.g., ‘‘cwd,1,3’’, ‘‘^6,^2’’. (There should be no spaces in the set.)
ted.
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 descrip-
tors 0 through 7.
+D D This option causes lsof to search for all open instances of directory D and all the files and directories it contains to its complete depth.
file system mount points on subdirectories of D unless the -x or -x f option is also specified.
directory tree, rooted at D, calling stat(2) for each file and directory, building a list of all the files it finds, and searching that list for a match
with every open file. When directory D is large, these steps can take a long time, so use this option prudently.
tions that follow it for more information on this option.
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
description of the -D option that accompanies -h or -? option output. See the DEVICE CACHE FILE section and the sections that follow it for more infor-
mation on these functions and when they’re restricted.
lsof will examine when forming the device cache file path, and the format for the personal device cache file path. (Escape the ‘?’ character as your
shell requires.)
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
show the current default prefix - e.g., ‘‘.lsof’’.) The suffix, hostname, is the first component of the host’s name returned by gethostname(2).
exists or the existing one is improperly structured. The r function, when specified without a path name, prevents lsof from updating an incorrect or out-
dated device cache file, or creating a new one in its place. The r function is always available when it is specified without a path name argument; it may
be restricted by the permissions of the lsof process.
This is the default device cache file function when no -D option has been specified.
f by itself clarifies how path name arguments are to be interpreted. When followed by c, f, g, G, or n in any combination it specifies that the listing
of kernel file structure information is to be enabled (‘+’) or inhibited (‘-’).
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 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.
search for open files with a ‘/’ path name, not all open files in the ‘/’ (root) file system.
as a parameter. For example, use ‘‘--’’ after +f and -f as in these examples.
$ lsof -f -- /file/name
dialects - e.g., /proc-based Linux. When the prefix to f is a plus sign (‘+’), these characters request file structure information:
f file structure address
g file flag abbreviations
G file flags in hexadecimal
n file structure node address
tical files in use by different processes. Lsof column output can be sorted by output columns holding the values and listed to identify identical file
use, or lsof field output can be parsed by an AWK or Perl post-filter script, or by a C program.
output field. Each field to be output is specified with a single character in f. The field terminator defaults to NL, but may be changed to NUL (000).
See the OUTPUT FOR OTHER PROGRAMS section for a description of the field identification characters and the field output process.
patibility reasons) and the NL field terminator is used.
the NUL terminator character is used.
Other combinations of fields and their associated field terminator character must be set with explicit entries in f, as described in the OUTPUT FOR OTHER
PROGRAMS section.
e.g., ‘‘-FR’’ - also selects the listing of the item.
the ‘?’ character as your shell requires.)
rated set s - e.g., ‘‘123’’ or ‘‘123,^456’’. (There should be no spaces in the set.)
ANDing and take effect before other selection criteria are applied.
selects the listing of all Internet and x.25 (HP-UX) network files.
used only if the dialects supports IPv6, as indicated by ‘‘[46]’’ and ‘‘IPv[46]’’ in lsof’s -h or -? output.) Sequentially specifying -i4, followed by
-i6 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.
They are joined in a single ORed set before participating in AND option selection.
46 specifies the IP version, IPv4 or IPv6
that applies to the following address.
’6’ may be be specified only if the UNIX
dialect supports IPv6. If neither ’4’ nor
’6’ is specified, the following address
applies to all IP versions.
protocol is a protocol name - TCP or UDP.
hostname is an Internet host name. Unless a
specific IP version is specified, open
network files associated with host names
of all versions will be selected.
hostaddr is 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.
service is an /etc/services name - e.g., smtp -
or a list of them.
port is a port number, or a list of them.
If the displayed description of the -i option contains ‘‘[46]’’ and ‘‘IPv[46]’’, IPv6 is supported.
ified 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’.
tion, is always required; as is the ‘:’, leading the port specification. Specify either hostname or hostaddr. Specify either service name list or port
number list. If a service name list is specified, the protocol may also need to be specified if the TCP and UDP port numbers for the service name are
different. Use any case - lower or upper - for protocol.
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, however.
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 or UDP time service port
FIFOs and pipes.
form ‘‘+L1’’ will select open files that have been unlinked. A specification of the form ‘‘+aL1 <file_system>’’ will select unlinked open files on the
specified file system.
For other link count comparisons, use field output (-F) and a post-processing script or program.
followed by the device number in hexadecimal "0x" format - e.g.,
options are available.
with the HASPMAPENABLED #define in the dialect’s machine.h header file; lsof is distributed with the HASPMAPENABLED #define deactivated, so portmapper
reporting is disabled by default and must be requested with +M. Specifying lsof’s -h or -? option will report the default mode. Disabling portmapper
registration when it is already disabled or enabling it when already enabled is acceptable.
diately following the port numbers or service names - e.g., ‘‘:1234[name]’’ or ‘‘:name[100083]’’. The registration information may be a name or number,
depending on what the registering program supplied to the portmapper when it registered the port.
gested or stopped. Reverse the reporting mode to determine if portmapper registration reporting is slowing or blocking lsof.
ture; or if it is located in the foreign part of its containing kernel structure and the local and foreign Internet addresses are the same; or if it is
located in the foreign part of its containing kernel structure and the foreign Internet address is INADDR_LOOPBACK (127.0.0.1). This rule may make lsof
ignore some foreign ports on machines with multiple interfaces when the foreign Internet address is on a different interface from the local one.
ful when host name lookup is not working properly.
dialects lsof can’t obtain accurate or consistent file offset information from its kernel data sources, sometimes just for particular kinds of files
(e.g., socket files.) Consult the lsof FAQ (The FAQ section gives its location.) for more information.
appropriate and available for the type of the file.
value of zero (unlimited) directs lsof to use the ‘‘0t’’ form for all offset output.
of digits after ‘‘0t’’ in either mixed size and offset or offset-only output. Thus, for example, to direct lsof to display offset at all times with a
decimal digit count of 10, use:
or
-oo10
option in the output of the -h or -? option to determine the default that is in effect.
See the BLOCKS AND TIMEOUTS and AVOIDING KERNEL BLOCKS sections for more information on kernel operations that may block lsof.
cautiously.
s - e.g., ‘‘123’’ or ‘‘123,^456’’. (There should be no spaces in the set.)
ORing or ANDing and take effect before other selection criteria are applied.
also useful when port name lookup is not working properly.
listing, delaying and listing repetitively until stopped by a condition defined by the prefix to the option.
When repeat mode ends because no files are listed, the process exit code will be zero if any open files were ever listed; one, if none were ever listed.
Lsof marks the end of each listing: if field output is in progress (the -F, option has been specified), the marker is ‘m’; otherwise the marker is
‘‘========’’. The marker is followed by a NL character.
will be kept to a minimum. Options that filter at the process level - e.g., -c, -g, -p, -u - are the most efficient selectors.
a size, nothing is displayed.
displays whatever value - size or offset - is appropriate and available for the type of file.
nel buffers, if possible.
minimum for t is two; the default, fifteen; when no value is specified, the default is used.
mation appears in parentheses, each item except state identified by a keyword, followed by ‘=’, separated from others by a single space:
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>
-T with following characters selects the reporting of specific TCP/TPI information:
states and values, and TCP flags and
values.
q selects queue length reporting.
s selects connection state reporting.
w selects window size reporting.
the -T option will show what selections may be used with the UNIX dialect.
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.
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.
values may be reported:
Reported Description (Common Symbol)
LINGER linger time (SO_LINGER)
MSS maximum segment size (TCP_MAXSEG)
PQLEN partial listen queue connections
QLEN established listen queue connections
QLIM established listen queue limit
RCVBUF receive buffer length (SO_RCVBUF)
SNDBUF send buffer length (SO_SNDBUF)
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 par-
tial listen queue connection count for my dialect?’’ questions in the lsof FAQ (The FAQ section gives its location.)
kill(1). This option selects the -w option.
-u s This option selects the listing of files for the user whose login names or user ID numbers are in the comma-separated set s - e.g., ‘‘abe’’, or
‘‘548,root’’. (There should be no spaces in the set.)
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’’.
and where; the name of the compiler used to construct the lsof binary; the version number of the compiler when readily available; the compiler and loader
flags used to construct the lsof binary; and system information, typically the output of uname’s -a option.
names, NFS files, PIDs, PGIDs, and UIDs.
search item when an ANDed option or compile-time option prevents the listing of the open file containing the located search item.
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.
-h or -? option. Disabling warning messages when they are already disabled or enabling them when already enabled is acceptable.
scanning the directory (+d) or directory tree (+D).
that when -x is specified without a parameter, the next argument must begin with ’-’ or ’+’.
AIX:
This IBM AIX RISC/System 6000 option requests the reporting of executed text file and shared library references.
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.
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.
an AIX kernel directory search kernel error, known as the Stale Segment ID bug.
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 appli-
cation 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.
Segment ID bug, its APAR, and methods for defining readx() use when compiling lsof.
This Linux option requests that lsof skip the reporting of information on all open TCP and UDP IPv4 and IPv6 files.
/proc/net/tcp* and /proc/net/udp* files would take lsof a long time, and whose reporting is not of interest.
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).
path by which the file was opened, not its possibly different final path.
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 speci-
fied by other options and arguments.
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 con-
texts 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.
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.
the ‘‘--’’ option.
sidered 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).
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.
that are open - e.g., /dev/pt[cs]/1, /dev/pt[cs]/2, etc.
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.
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.
bers. 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.
Lsof supports the recognition of AFS files for these dialects (and AFS versions):
HP-UX 9.0.5 (AFS 3.4a)
Linux 1.2.13 (AFS 3.3)
Solaris 2.[56] (AFS 3.4a)
in other dialects, or may have difficulties recognizing AFS files in the supported dialects.
appear in the kernel’s variable name list. In that case, lsof may have to guess at the identity of AFS files, and might not be able to obtain volume information
from the kernel that is needed for calculating AFS volume node numbers. When lsof can’t compute volume node numbers, it reports blank in the NODE column.
this option is available, it will be listed in the lsof help output, presented in response to the -h or -?
Lsof has three features that may cause security concerns. First, its default compilation mode allows anyone to list all open files with it. Second, 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. (The list-all-open-files and device
cache features may be disabled when lsof is compiled.) Third, its -k and -m options name alternate kernel name list or memory files.
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).
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. 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.
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.)
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.
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.
control character ‘^’ form (e.g., ‘‘^@’’); or hexadecimal leading ‘‘\x’’ form (e.g., ‘‘\xab’’). Space is non-printable in the COMMAND column (‘‘\x20’’) and print-
able elsewhere.
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.
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.
from its predecessor by at least one space.
the column contains the first w characters of the name of the UNIX command associated with the process up to the limit of characters supplied to lsof by
the UNIX dialect. (See the description of the +c w command or the lsof FAQ for more information. The FAQ section gives its location.)
All command name characters maintained by the kernel in its structures are displayed in field output when the command name descriptor (‘c’) is speci-
fied. See the OUTPUT FOR OTHER COMMANDS section for information on selecting field output and the associated command name descriptor.
is the SELinux security context. This column must be selected with the -Z option.
ID number or login that owns the directory in /proc where lsof finds information about the process. Usually that is the same value reported by ps(1),
but may differ when the process has changed its effective user ID. (See the -l option description for information on when a user ID number or login
name is displayed.)
Lnn library references (AIX);
err FD information error (see NAME column);
jld jail directory (FreeBSD);
ltx shared library text (code and data);
Mxx hex memory-mapped type number xx.
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;
w for write access;
u for read and write access;
space if mode unknown and no lock
character follows;
‘-’ if mode unknown and lock
character follows.
The mode character is followed by one of these lock characters, describing the type of lock applied to the file:
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.
or ‘‘FIFO’’ for a FIFO special file;
or ‘‘PLDR’’ for a /proc/lpw directory;
or ‘‘PSIN’’ for a /proc/psinfo file;
open file flags (if available); ‘G’ causes them to be displayed in hexadecimal; ‘g’, as short-hand names; two lists may be displayed with entries sepa-
rated 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:
AP append
ASYN asynchronous I/O (e.g., FASYNC)
BAS block, test, and set in use
BKIU block if in use
BL use block offsets
BSK block seek
CA copy avoid
CIO concurrent I/O
CLON clone
CLRD CL read
CR create
DF defer
DFI defer IND
DFLU data flush
DIR direct
DLY delay
DOCL do clone
DSYN data-only integrity
EVO event only
EX open for exec
EXCL exclusive open
FSYN synchronous writes
GCDF defer during unp_gc() (AIX)
GCMK mark during unp_gc() (AIX)
GTTY accessed via /dev/tty
HUP HUP in progress
KERN kernel
KIOC kernel-issued ioctl
LCK has lock
LG large file
MBLK stream message block
MK mark
MNT mount
MSYN multiplex synchronization
NB non-blocking I/O
NBDR no BDRM check
NBIO SYSV non-blocking I/O
NBF n-buffering in effect
NC no cache
ND no delay
NDSY no data synchronization
NET network
NMFS NM file system
NOTO disable background stop
NSH no share
NTTY no controlling TTY
OLRM OLR mirror
PAIO POSIX asynchronous I/O
PP POSIX pipe
R read
RC file and record locking cache
REV revoked
RSH shared read
RSYN read synchronization
SL shared lock
SNAP cooked snapshot
SOCK socket
SQSH Sequent shared set on open
SQSV Sequent SVM set on open
SQR Sequent set repair on open
SQS1 Sequent full shared open
SQS2 Sequent partial shared open
STPI stop I/O
SWR synchronous read
SYN file integrity while writing
TCPM avoid TCP collision
TR truncate
W write
WKUP parallel I/O synchronization
WTG parallel I/O synchronization
VH vhangup pending
VTXT virtual text
XL exclusive lock
see the lsof.h header file for a list showing the correspondence between the above short-hand names and the header file definitions;
BR the file has been read
BHUP activity stopped by SIGHUP
BW the file has been written
CLSG closing
CX close-on-exec (see fcntl(F_SETFD))
LCK lock was applied
MP memory-mapped
OPIP open pending - in progress
RSVW reserved wait
SHMT UF_FSHMAT set (AIX)
USE in use (multi-threaded)
concatenation of device and node number) when n has been specified to +f;
is the size of the file or the file offset in bytes. A value is displayed in this column only if it is available. Lsof displays whatever value - size
or offset - is appropriate for the type of the file and the version of lsof.
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.
with a leading ‘‘0x’’ if it is longer than 8 digits. (Consult the -o o option description for information on when 8 might default to some other value.)
always begins with ‘‘0t’’ or ‘‘0x’’ as described above.
options are mutually exclusive; they can’t both be specified.
tion of the file if it is available in the kernel structures that define the file.
or the Internet protocol type - e. g, ‘‘TCP’’;
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 and UDP 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 what netstat(1) reports; see the -T option description or the description of the TCP/TPI field in OUTPUT FOR OTHER PROGRAMS
for more information on state, queue size, and window size;
nel addresses, socket pair information, and a bound vnode address;
KERNEL NAME CACHE section for more information.);
or ‘‘(dead)’’ for disassociated Tru64 UNIX files - typically terminal files that have been flagged with the TIOCNOTTY ioctl and closed by daemons;
socket has been disabled, or ‘‘, CANTRCVMORE’’ if receiving on the socket has been disabled (e.g., by the shutdown(2) function);
queue sizes, and the connection state;
available, followed by ‘‘->’’ and the remote path name or kernel socket address in hexadecimal when available.
tion><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 vnode address of this vnode, has been fattach’ed to <address2>. <address1> may be omitted if
it already appears in the DEVICE column.
‘‘(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.
Lsof can’t adequately report the wide variety of UNIX dialect file locks in a single character. What it reports in a single character is a compromise between the
information it finds in the kernel and the limitations of the reporting format.
the lock character will be reported in lower case - i.e., ‘r’, ‘w’, or ‘x’ - rather than the upper case equivalent reported for a full file lock.
remote server host usually records the lock state. One exception is Solaris - at some patch levels of 2.3, and in all versions above 2.4, the Solaris kernel
records information on remote locks in local structures.
more information.
When the -F option is specified, lsof produces output that is suitable for processing by another program - e.g, an awk or Perl script, or a C program.
tifier character is specified.) The data of the field follows immediately after the field identification character and extends to the field terminator.
It is possible to think of field output as process and file sets. A process set begins with a field whose identifier is ‘p’ (for process IDentifier (PID)). It
extends to the beginning of the next PID field or the beginning of the first file set of the process, whichever comes first. Included in the process set are
fields that identify the command, the process group IDentification (PGID) number, and the user ID (UID) number or login name.
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.
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.
tify 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.
c process command name (all characters from proc or
user structure)
C file structure share count
d file’s device character code
D file’s major/minor device number (0x<hexadecimal>)
f file descriptor
F file structure address (0x<hexadecimal>)
G file flaGs (0x<hexadecimal>; names if +fg follows)
i file’s inode number
k link count
l file’s lock status
L process login name
m marker between repeated output
n file name, comment, Internet address
N node identifier (ox<hexadecimal>
o file’s offset (decimal)
p process ID (always selected)
g process group ID
P protocol name
r raw device number (0x<hexadecimal>)
R parent process ID
s file’s size (decimal)
S file’s stream identification
t file’s type
T TCP/TPI information, identified by prefixes (the
‘=’ is part of the prefix):
QR=<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 -h or -? help output for the
-T option will show what TCP/TPI reporting can be
requested.)
u process user ID
z Solaris 10 and higher zone name
0 use NUL field terminator character in place of NL
1-9 dialect-specific field identifiers (The output
of -F? identifies the information to be found
in dialect-specific fields.)
requires.) Additional information on field content can be found in the OUTPUT section.
acter; ‘‘-F pcfn0’’ selects the same output with a NUL (000) field terminator character.
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 mutu-
ally exclusive sets will appear in field output, but not both.
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).
tains 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.
distribution.
library can be found in the tests/LTlib.c file of the lsof distribution. The library uses the first aid, the lsof_fields.h header file.
Lsof 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.
report the break with an error message. The messages may be suppressed with the -t and -w options.
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.
about open files.
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.
You can use the -b option to tell lsof to avoid using kernel functions that would block. Some cautions apply.
lstat(2) and stat(2) kernel functions. See the ALTERNATE DEVICE NUMBERS section for more information on alternate device numbers.
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 avail-
able, or if they’re incorrect, lsof won’t be able to locate files on the named file systems.
This is because the -b option causes lsof to avoid the kernel readlink(2) function it uses to resolve symbolic links.
press these messages by specifying the -w option, but if you do, you won’t see the alternate device numbers reported in the warning messages.
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 is possible, lsof will report the device number it obtained. (You can suppress the report by specifying the -w option.)
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.
options to see if the +m and +m m options are available.
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:
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.
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.
nate device numbers:
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.)
followed by a space, two ‘-’ characters, another space, and the name components it has located, separated by the ‘/’ character.
to cycle. That’s because other running processes can cause the kernel to remove entries from its name cache and replace them with others.
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.
HP-UX
Linux
NetBSD
NEXTSTEP
OpenBSD
OPENSTEP
SCO OpenServer
SCO|Caldera UnixWare
Solaris
Tru64 UNIX
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 num-
ber, inode number, and path - rarely changes.
The local system administrator who builds lsof can control the way the device cache file path is formed, selecting from these options:
Path from an environment variable;
System-wide path;
Personal path (the default);
Personal path, modified by an environment variable.
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.
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.
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 ver-
sion.
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.
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.
logged-on user) UID is not. The lsof distribution recommends that versions for these dialects run setuid-root.
Linux
can access kernel memory devices - e.g., ‘‘kmem’’, ‘‘sys’’, or ‘‘system’’.
more liberal device cache path formations. The lsof distribution recommends that versions for these dialects run setgid and be allowed to surrender setgid permis-
sion.
Apple Darwin 7.x Power Macintosh systems
FreeBSD 4.x, 4.1x, 5.x and [67].x for x86-based systems
FreeBSD 5.x and [67].x for 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
NEXTSTEP 3.[13] for NEXTSTEP architectures
OpenBSD 2.[89] and 3.[0-9] for x86-based systems
OPENSTEP 4.x
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
The -D option provides limited means for specifying the device cache file path. Its ? function will report the read-only and write device cache file paths that
lsof will use.
(r[path]); or read and rebuilt (u[path]). The b, r, and u functions are restricted under some conditions. They are restricted when the lsof process is
setuid-root. The path specified with the r function is always read-only, even when it is available.
The b, r, and u functions are also restricted when the lsof process runs setgid and lsof doesn’t surrender the setgid permission. (See the LSOF PERMISSIONS THAT
AFFECT DEVICE CACHE FILE ACCESS section for a list of implementations that normally don’t surrender their setgid permission.)
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 permis-
sion, a path name argument may accompany the r function.
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.
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.
the lsof process doesn’t surrender its setgid permission. (See the LSOF PERMISSIONS THAT AFFECT DEVICE CACHE FILE ACCESS section for information on implementa-
tions that don’t surrender their setgid permission.)
the environment variable’s name.
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.
or -? option.
file has been written, the procedure must change its permission modes to 0644 (owner-read and owner-write, group-read, and other-read).
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.
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.
preceding the first ‘.’ in the gethostname(2) output, or all the gethostname(2) output if it contains no ‘.’.
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.
exist or should its contents be incorrect or outdated.
in the 00DCACHE file of the lsof distribution.
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.
format specification of the dialect’s machine.h header file. (It’s placed right after the home directory in the default lsof distribution.)
is the default (‘‘%h/%p.lsof_%L’’), the modified personal device cache file path is:
DEVICE CACHE FILE ACCESS section for a list of implementations that normally don’t surrender their setgid permission.)
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.
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.
Errors are identified with messages on the standard error file.
PIDs, PGIDs, or UIDs it was asked to list. If the -V option is specified, lsof will indicate the search items it failed to list.
It returns a zero (0) if no errors were detected and if it was able to list some information about all the specified search arguments.
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 >B -?
options - with the message:
the WARNDEVACCESS definition. In this case, the output from the help options will include the message:
For a more extensive set of examples, documented more fully, see the 00QUICKSTART file of the lsof distribution.
To list all open files on device /dev/hd4, use:
number for /nfs/mount/point, use:
lar expression form of the -c c option:
lsof -i@128.210.15.17
loop-back address - use:
Since lsof reads kernel memory in its search for open files, rapid changes in kernel memory may produce unpredictable results.
combination of the individual record locks that might be described by multiple lock structures.
for files to which its user or its set-GID group (if any) has access permission.
raw socket’s protocol control block, some do not.
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.)
Solaris, UnixWare.
the full path name be specified.
cal file descriptors are labeled mem descriptors.
lsof FAQ (The FAQ section gives its location.) for details.
create such file structures is to run X clients with the DISPLAY variable set to ‘‘:0.0’’.
The +|-f[cfgGn] option is not supported under /proc-based Linux lsof, because it doesn’t read kernel structures from kernel memory.
Lsof may access these environment variables.
mation.
Frequently-asked questions and their answers (an FAQ) are available in the 00FAQ file of the lsof distribution.
/dev/kmem kernel virtual memory device
Lsof was written by Victor A. Abell <abe@purdue.edu> of Purdue University. Many others have contributed to lsof. They’re listed in the 00CREDITS file of the lsof
distribution.
The latest distribution of lsof is available via anonymous ftp from the host lsof.itap.purdue.edu. You’ll find the lsof distribution in the pub/tools/unix/lsof
directory.
sites. The pub/tools/unix/lsof directory also contains a more complete list in its mirrors file. Use mirrors with caution - not all mirrors always have the lat-
est lsof revision.
Some pre-compiled Lsof executables are available on lsof.itap.purdue.edu, but their use is discouraged - it’s better that you build your own from the sources. If
you feel you must use a pre-compiled executable, please read the cautions that appear in the README files of the pub/tools/unix/lsof/binaries subdirectories and in
the 00* files of the distribution.
README.lsof_<version> and the other 00* files of the distribution before sending questions to the author.
Not all the following manual pages may exist in every UNIX dialect to which lsof has been ported.
perl(1), ps(1), readlink(2), setlocale(3), stat(2), uname(1).
man lsof的更多相关文章
- lsof命令
学习资源https://linux.die.net/man/8/lsof lsof mean list open files 如果说linux中一切皆文件的话,那么lsof就是一盏照亮黑暗的文件系统的 ...
- Linux 利用lsof命令恢复删除的文件
lsof命令 lsof命令用于查看你进程开打的文件,打开文件的进程,进程打开的端口(TCP.UDP).找回/恢复删除的文件.是十分方便的系统监视工具,因为lsof命令需要访问核心内存和各种文件,所以需 ...
- shell命令lsof
PREFACE linux一切皆是文件,共有7中文件类型 1.普通文件(regular file) 2.目录文件(directory file) 3.块特殊文件(block special file) ...
- Linux lsof命令 以及 恢复删除的文件
1.简介 lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传 ...
- 【Linux】lsof 命令,记一次端口占用查询
3月21日测试时,发现测试服务器启,总是报端口占用情况,察看端口占用情况 1-使用命令 netstat -tunlp |grep 端口号 差看下 这个端口被那个进程占用 我当前使用的 JBOSS 端口 ...
- lsof 常用命令
lsof 常用命令 原文地址: Lsof 是遵从Unix 哲学的典范,它只做一件事情,并且做的相当完美——它可以列出某个进程打开的所有文件信息.打开的文件可能是普通的文件,目录,NFS文件,块文件 ...
- 转:linux lsof命令详解
简介 lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传输控 ...
- LSOF 安装与使用
linux上安装: tar zxvf lsof_4.76.tar.gz cd lsof_4.76 ls 00.README.FIRST_4.76 lsof_4.76_src.tar.gz README ...
- 每天一个linux命令(51):lsof命令
lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传输控制协议 ...
- linux lsof 用法简介
1.简介: lsof(list open files)是一个列出当前系统打开文件的工具. 只需输入 lsof 就可以生成大量的信息,因为 lsof 需要访问核心内存和各种文件,所以必须以 root 用 ...
随机推荐
- react-native 组件之间传值
1.通过 AsyncStorage 将值保存在本地(最低端的方法) import { AsyncStorage, } from 'react-native'; // 保存 IP AsyncStorag ...
- leetcode-mid-array-73 set matrix zeros
mycode 空间复杂度 m+n 思路:用set把为0元素所在行.列记录下来 注意:注释的方法更快 class Solution(object): def setZeroes(self, matrix ...
- Linux内核调试方法总结之ptrace
ptrace [用途] 进程跟踪器,类似于gdb watch的调试方法 [原理][详细说明参考man ptrace帮助文档] ptrace系统调用主要是父进程用来观察和控制子进程的执行过程.检查并替换 ...
- Jenkins获取运行job的用户名(在构建历史中展示构建人)
首先安装插件: jenkins>>manage jenkins>> manage plugins>>可选插件>>搜索并安装插件: user build ...
- Vultr CentOS下后台跑node
在Mac或者Windows下简直易如反掌.几行命令搞定的事情,但因为使用的是远程SSH连接纯命令行处理,所以需要记录下来怎么弄. 比如, 1. 怎么在什么都没有的CentOS里下载Node安装包? 2 ...
- deepin 安装tar.gz
由于网上推荐的比较多的安装方式是:sudo apt-get install mysql-server mysql-client,这个安装的是mysql5.7,既然都安装了就要安装最新的,所以从官网下载 ...
- 没看这篇干货,别和我说你会IDEA Debug
所谓工欲善其事必先利其器,现在idea已经成为java开发者眼中最热门最好用的IDE了.下面这篇文章将总结下idea调试的一些高级技巧. 多线程调试 直接上例子说明,比如下面这段代码 debug模式下 ...
- 【ABAP系列】SAP ABAP 生成随机数的函数
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP 生成随机数的函数 ...
- 东软、天健、金仕达、杭创、中联、NECHIS、军字一号 HIS产品的比较
HIS主流厂商产品介绍1.沈阳东软医疗系统有限公司创立于1998年公司是中国目前最大的软件集团——东软集团为技术和资源依托,以研制生产大型医疗设备为主,同时为医院数字化提供全面解决方案.但是,公司改制 ...
- sql Server20008总结
1.like------->常用于“数据库的模糊查询” 1)即:查询某个字段中含有哪些的内容的数据库的信息列表(详情) 比如:查询学生表中名字姓是‘韩’的所有学生的信息 select * fro ...