lsof

    lsof命令 用于查看你进程开打的文件,打开文件的进程,进程打开的端口(TCP、UDP)。找回/恢复删除的文件。是十分方便的系统监视工具,因为lsof命令需要访问核心内存和各种文件,所以需要root用户执行。

    lsof输出各列信息的意义如下:

    • COMMAND:进程的名称
    • PID:进程标识符
    • PPID:父进程标识符(需要指定-R参数)
    • USER:进程所有者
    • PGID:进程所属组
    • FD:文件描述符,应用程序通过文件描述符识别该文件。
    1. cwd:表示current work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
    2. txt:该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序
    3. lnn:library references (AIX);
    4. er:FD information error (see NAME column);
    5. jld:jail directory (FreeBSD);
    6. ltx:shared library text (code and data);
    7. m86:DOS Merge mapped file;
    8. mem:memory-mapped file;
    9. mmap:memory-mapped device;
    10. pd:parent directory;
    11. rtd:root directory;
    12. tr:kernel trace file (OpenBSD);
    13. v86 VP/ix mapped file;
    14. 0:表示标准输出
    15. 1:表示标准输入
    16. 2:表示标准错误

    一般在标准输出、标准错误、标准输入后还跟着文件状态模式:

    1. u:表示该文件被打开并处于读取/写入模式。
    2. r:表示该文件被打开并处于只读模式。
    3. w:表示该文件被打开并处于。
    4. 空格:表示该文件的状态模式为unknow,且没有锁定。
    5. -:表示该文件的状态模式为unknow,且被锁定。
    1. N:for a Solaris NFS lock of unknown type;
    2. R:for a read lock on the entire file;
    3. w:for a write lock on part of the file;(文件的部分写锁)
    4. W:for a write lock on the entire file;(整个文件的写锁)
    5. u:for a read and write lock of any length;
    6. U:for a lock of unknown type;
    7. x:for an SCO OpenServer Xenix lock on part of the file;
    8. X:for an SCO OpenServer Xenix lock on the entire file;
    9. space:if there is no lock.

    文件类型:

    1. DIR:表示目录。
    2. CHR:表示字符类型。
    3. BLK:块设备类型。
    4. UNIX: UNIX 域套接字。
    5. FIFO:先进先出 (FIFO) 队列。
    6. IPv4:网际协议 (IP) 套接字。
    7. DEVICE:指定磁盘的名称
    8. SIZE:文件的大小
    9. NAME:打开文件的确切名称