Lsof
   HOME

TheInfoList



OR:

lsof is a command meaning "list open files", which is used in many
Unix-like A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
systems to report a list of all open files and the processes that opened them. This
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
utility was developed and supported by Victor A. Abell, the retired Associate Director of the
Purdue University Purdue University is a Public university#United States, public Land-grant university, land-grant research university in West Lafayette, Indiana, United States, and the flagship campus of the Purdue University system. The university was founded ...
Computing Center. It works in and supports several Unix flavors. A replacement for Linux, , is included in util-linux.


History

In 1985, Cliff Spencer publishes the command. Its
man page A man page (short for manual page) is a form of software documentation found on Unix and Unix-like operating systems. Topics covered include programs, system libraries, system calls, and sometimes local system details. The local host administr ...
says: "ofiles – who has a file open ..displays the owner and id of any process accessing a specified device". Spencer compiled it for 4.2BSD and
ULTRIX Ultrix (officially all-caps ULTRIX) is the brand name of Digital Equipment Corporation's (DEC) discontinued native Unix operating systems for the PDP-11, VAX, MicroVAX and DECstations. History The initial development of Unix occurred on DEC eq ...
. Moreover, in the
newsgroup A Usenet newsgroup is a repository usually within the Usenet system for messages posted from users in different locations using the Internet. They are not only discussion groups or conversations, but also a repository to publish articles, start ...
net.unix-wizards, he further remarks:
With all the chatter about dismounting active file systems, I have posted my program to indicate who is using a particular filesystem, "ofiles" to net.sources.
In 1988, the command ("file status") appears as part of the 4.3BSD-Tahoe release. Its man page says:
''fstat'' identifies open files. A file is considered open if a process has it open, if it is the working directory for a process, or if it is an active pure text file. If no options are specified, ''fstat'' reports on all open files.
In 1989, in comp.sources.unix, Vic Abell publishes ports of the ofiles and fstat commands from 4.3BSD-Tahoe to " DYNIX 3.0.1 4for Sequent Symmetry and Balance,
SunOS SunOS is a Unix-branded operating system developed by Sun Microsystems for their workstation and server computer systems from 1982 until the mid-1990s. The ''SunOS'' name is usually only used to refer to versions 1.0 to 4.1.4, which were based ...
4.0 and
ULTRIX Ultrix (officially all-caps ULTRIX) is the brand name of Digital Equipment Corporation's (DEC) discontinued native Unix operating systems for the PDP-11, VAX, MicroVAX and DECstations. History The initial development of Unix occurred on DEC eq ...
2.2". Various people had evolved and ported ofiles over the years. Abell contrasted the commands as follows:
Fstat is similar to the ofiles program which I recently submitted. Like ofiles, fstat identifies open files. It's orientation differs slightly from that of ofiles: ofiles starts with a file name and paws through the proc and user structures to identify the file; fstat reads all the proc and user structures, displaying information in all files, optionally applying a few filters to the output (including a single file name filter.) In combination with netstat -aA and grep, fstat will identify the process associated with a network connection, just as will ofiles.
In 1991, Vic Abell publishes lsof version 1.0 to comp.sources.unix. He notes:
Lsof (for LiSt Open Files) lists files opened by processes on selected Unix systems. It is my answer to those who regularly ask me when I am going to make fstat (comp.sources.unix volume 18, number 107) or ofiles (volume 18, number 57) available on
SunOS SunOS is a Unix-branded operating system developed by Sun Microsystems for their workstation and server computer systems from 1982 until the mid-1990s. The ''SunOS'' name is usually only used to refer to versions 1.0 to 4.1.4, which were based ...
4.1.1 or the like. Lsof is a complete redesign of the fstat/ofiles series, based on the SunOS vnode model. Thus, it has been tested on AIX 3.1. 57
HP-UX HP-UX (from "Hewlett Packard Unix") is a proprietary software, proprietary implementation of the Unix operating system developed by Hewlett Packard Enterprise; current versions support HPE Integrity Servers, based on Intel's Itanium architect ...
8x,
NeXTStep NeXTSTEP is a discontinued object-oriented, multitasking operating system based on the Mach kernel and the UNIX-derived BSD. It was developed by NeXT, founded by Steve Jobs, in the late 1980s and early 1990s and was initially used for its ...
2. 1 Sequent Dynix 3.0.12 and 3.1.2, and
Sunos SunOS is a Unix-branded operating system developed by Sun Microsystems for their workstation and server computer systems from 1982 until the mid-1990s. The ''SunOS'' name is usually only used to refer to versions 1.0 to 4.1.4, which were based ...
4.1 and 4.1.1. Using available kernel access methods, such as nlist() and kvm_read(), lsof reads process table entries, user areas and file pointers to reach the underlying structures that describe files opened by processes.
In 2018, Vic Abbell publishes lsof version 4.92. The same year, he initiates the transfer of responsibility. He writes:
I will reach 80 years of age later this year and I think it's time for me to end my work on general lsof revision releases.
The lsof code is put on Github and maintenance is transferred.


Examples

Open files in the system include disk files, named pipes, network sockets and devices opened by all processes. One use for this command is when a disk cannot be unmounted because (unspecified) files are in use. The listing of open files can be consulted (suitably filtered if necessary) to identify the process that is using the files. # lsof /var COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME syslogd 350 root 5w VREG 222,5 0 440818 /var/adm/messages syslogd 350 root 6w VREG 222,5 339098 6248 /var/log/syslog cron 353 root cwd VDIR 222,5 512 254550 /var -- atjobs To view the port associated with a daemon: # lsof -i -n -P , grep sendmail sendmail 31649 root 4u IPv4 521738 TCP *:25 (LISTEN) From the above one can see that "sendmail" is listening on its standard port of "25". ;: Lists IP sockets. ;: Do not resolve hostnames (no DNS). ;: Do not resolve port names (list port number instead of its name). One can also list Unix Sockets by using lsof -U.


Lsof output

The lsof output describes: *the identification number of the process (PID) that has opened the file; *the process group identification number (PGID) of the process (optional); *the process identification number of the parent process (PPID) (optional); *the command the process is executing; *the owner of the process; *for all files in use by the process, including the executing text file and the shared libraries it is using: **the file descriptor number of the file, if applicable; **the file's access mode; **the file's lock status; **the file's device numbers; **the file's inode number; **the file's size or offset; **the name of the file system containing the file; **any available components of the file's path name; **the names of the file's stream components; **the file's local and remote network addresses; **the TLI network (typically UDP) state of the file; **the TCP state, read queue length, and write queue length of the file; **the file's TCP window read and write lengths (Solaris only); and **other file or dialect-specific values. For a complete list of options, see the Lsof(8) Linux manual page.


See also

*
fuser (Unix) The Unix command (computing), command fuser is used to show which process (computing), processes are using a specified computer file, file system, or Unix domain socket, Unix socket. Example For example, to check process IDs and users accessing ...
*
stat (Unix) is a Unix system call that queries the file system for metadata about a computer file, file (including Unix file type, special files such as computer directory, directories). The metadata contains many fields including Unix file type, type, fil ...
*
netstat In computing, netstat is a command-line network utility that displays open network sockets, routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistic ...
* strace *
List of Unix commands This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...


References


External links


Old sitelsof-l mailing listmirror of legacy sources
* *
Using lsofLsof FAQ
*Sam Nelson'
PCP
script, an alternative to "lsof -i" for Solaris.
Glsof
is two separate utilities (Queries and Filemonitor) based on lsof.
Sloth
is a macOS graphical interface for lsof

{{Unix commands Unix file system-related software