Lsof
Encyclopedia
lsof is a command meaning "list open files", which is used in many Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems to report a list of all open files and the processes that opened them. This open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 utility was developed and supported by Vic Abell, the retired Associate Director of the Purdue University
Purdue University
Purdue University, located in West Lafayette, Indiana, U.S., is the flagship university of the six-campus Purdue University system. Purdue was founded on May 6, 1869, as a land-grant university when the Indiana General Assembly, taking advantage of the Morrill Act, accepted a donation of land and...

 Computing Center. It works in and supports several Unix flavors.

Open files in the system include disk files, pipes
Pipes
Pipes may refer to:*Pipe, a cylindrical conveyance*PIPES *Yahoo! Pipes*Pipeline *Bagpipes or Uilleann pipes*PIPE deal or private investment in public equity*Pipes , a Transformers character...

, network sockets
Internet socket
In computer networking, an Internet socket or network socket is an endpoint of a bidirectional inter-process communication flow across an Internet Protocol-based computer network, such as the Internet....

 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 we can see that "sendmail" is listening on its standard port of "25".
  • -i Lists IP sockets.
  • -n Do not resolve hostnames (no DNS).
  • -P Do not resolve port names (list port number instead of its name).


You can also list Unix Sockets by using lsof -U

See also

  • stat (Unix)
    Stat (Unix)
    stat is a Unix system call that returns useful data about a file inode. The semantics of stat vary between operating systems. As an example, the Unix command ls uses it to retrieve information on : time of last modification , time of last status change and time of last access .-stat functions and...

  • netstat
    Netstat
    netstat is a command-line tool that displays network connections , routing tables, and a number of network interface statistics...

  • strace
    Strace
    strace is a debugging utility for Linux and some other Unix-like systems to monitor the system calls used by a program and all the signals it receives, similar to "truss" utility in other Unix systems...

  • List of Unix programs
  • Process Explorer
    Process Explorer
    Process Explorer is a freeware computer program for Microsoft Windows created by Sysinternals, which has been acquired by Microsoft Corporation....

     from SysInternals
    Sysinternals
    Windows Sysinternals is a part of the Microsoft TechNet website which offers technical resources and utilities to manage, diagnose, troubleshoot, and monitor a Microsoft Windows environment. Originally, the Sysinternals website was created in 1996 and was operated by the company Winternals...

    - the equivalent for Windows (Find menu -> Find Handle or DLL)

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK