lsof
lsof---list open files
lsof 是一个列出当前系统已打开文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口。因为应用程序打开文件的描述符列表提供了大量关于这个应用程序本身的信息,因此通过lsof工具能够查看这个列表对系统监测以及排错将是很有帮助的。
  An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file
       or UNIX domain socket.)  A specific file or all the files in a file system may be selected by path.
因为lsof需要访问核心内存和各种文件,所以必须以 root 用户的身份运行它才能够充分地发挥其功能。 
每行显示一个打开的文件,若不指定条件默认将显示所有进程打开的所有文件。

1. lsof输出信息解析:
COMMAND:	进程的名称
PID:		进程标识符
USER:		进程所有者
FD:		文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等
TYPE:		文件类型,如DIR、REG等
DEVICE:	指定磁盘的名称
SIZE:		文件的大小
NODE:		索引节点(文件在磁盘上的标识)
NAME:		打开文件的名称
FD   is the File Descriptor number of the file or:
			    cwd  current working directory;
			    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;
			
		FD   is followed by one of these characters, describing the mode under which the file is open:
                r for read access;
                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.
                    
                
                
            
        
浙公网安备 33010602011771号