Linux中查看进程描述符

系统 Linux
在 Linux 中,可以使用 ls -l /proc/<PID>/fd 命令来查看指定进程的所有打开的文件描述符。其中 <PID> 是要查看的进程的进程标识符。

在 Linux 中,可以使用 ls -l /proc/<PID>/fd 命令来查看指定进程的所有打开的文件描述符。其中 <PID> 是要查看的进程的进程标识符。

该命令将列出指定进程的所有文件描述符的详细信息,包括文件描述符的名称、类型、大小等。例如:

lrwx------ 1 user user 64 Aug 31 18:42 0 -> /dev/pts/0
lrwx------ 1 user user 64 Aug 31 18:42 1 -> /dev/pts/0
lrwx------ 1 user user 64 Aug 31 18:42 2 -> /dev/pts/0
lrwx------ 1 user user 64 Aug 31 18:42 3 -> socket:[315245]

其中,第一列表示文件模式和权限,第二列表示硬链接数,第三列表示拥有者,第四列表示拥有组,第五列表示文件大小,第六列表示最后修改日期,第七列表示文件名。

在上面的例子中,文件描述符 0、1 和 2 都指向 /dev/pts/0,即标准输入、标准输出和标准错误输出。文件描述符 3 是一个套接字类型的文件描述符,它连接到另一个进程或服务器。

可以使用 lsof -p <PID> 命令查看指定进程打开的所有文件和套接字。该命令将显示每个文件或套接字的名称、类型、大小和状态等详细信息。例如:

COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF     NODE NAME
bash 3272 root cwd DIR 253,0 93 17057427 /home/shenshixi/ctest
bash 3272 root rtd DIR 253,0 238 128 /
bash 3272 root txt REG 253,0 1219248 50411954 /usr/bin/bash
bash 3272 root mem REG 253,0 2586930 50377323 /usr/lib/locale/en_US.utf8/LC_COLLATE
bash 3272 root mem REG 253,0 83760 82001 /usr/lib64/libnss_files-2.28.so
bash 3272 root mem REG 253,0 8406312 34695765 /var/lib/sss/mc/passwd
bash 3272 root mem REG 253,0 38160 2089406 /usr/lib64/libnss_sss.so.2
bash 3272 root mem REG 253,0 3167872 81989 /usr/lib64/libc-2.28.so
bash 3272 root mem REG 253,0 28856 81991 /usr/lib64/libdl-2.28.so
bash 3272 root mem REG 253,0 208616 81901 /usr/lib64/libtinfo.so.6.1
bash 3272 root mem REG 253,0 278512 81962 /usr/lib64/ld-2.28.so
bash 3272 root mem REG 253,0 337024 51059433 /usr/lib/locale/en_US.utf8/LC_CTYPEbash 3272 root mem REG 253,0 54 51059435 /usr/lib/locale/en_US.utf8/LC_NUMERIC
bash 3272 root mem REG 253,0 3316 1432404 /usr/lib/locale/en_US.utf8/LC_TIME
bash 3272 root mem REG 253,0 286 1432401 /usr/lib/locale/en_US.utf8/LC_MONETARY
bash 3272 root mem REG 253,0 57 81955 /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
bash 3272 root mem REG 253,0 34 33791042 /usr/lib/locale/en_US.utf8/LC_PAPERbash 3272 root mem REG 253,0 77 50377326 /usr/lib/locale/en_US.utf8/LC_NAME
bash 3272 root mem REG 253,0 167 81938 /usr/lib/locale/en_US.utf8/LC_ADDRESS
bash 3272 root mem REG 253,0 59 1432403 /usr/lib/locale/en_US.utf8/LC_TELEPHONE
bash 3272 root mem REG 253,0 23 1432400 /usr/lib/locale/en_US.utf8/LC_MEASUREMENT
bash 3272 root mem REG 253,0 26998 51037172 /usr/lib64/gconv/gconv-modules.cache
bash 3272 root mem REG 253,0 368 1432391 /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
bash 3272 root 0u CHR 136,1 0t0 4 /dev/pts/1
bash 3272 root 1u CHR 136,1 0t0 4 /dev/pts/1
bash 3272 root 2u CHR 136,1 0t0 4 /dev/pts/1
bash 3272 root 3r REG 253,0 8406312 34695765 /var/lib/sss/mc/passwd
bash 3272 root 4u unix 0xffff95f041aef500 0t0 65549 type=STREAM
bash 3272 root 255u CHR 136,1 0t0 4 /dev/pts/1

其中,COMMAND 列显示进程的名称,PID 显示进程的进程标识符,FD 列显示文件描述符或套接字,TYPE 列显示文件或套接字的类型。其他列则显示与文件或套接字相关的详细信息。

责任编辑:华轩 来源: 今日头条
相关推荐

2020-02-07 18:16:01

进程线程底层原理

2012-08-08 10:31:41

IBMdW

2019-03-05 22:15:08

BashLinux命令

2009-07-08 09:46:45

Servlet注释部署描述符

2016-10-28 21:55:28

Javascript属性特性属性描述符

2017-02-05 10:06:53

Python黑魔法描述符

2019-07-05 14:20:45

RPC服务器模型

2021-05-19 14:48:58

Linux文件fd

2023-12-13 14:01:34

Elasticsea文件描述符操作系统

2009-09-04 14:04:53

C#文档

2021-06-18 06:02:24

内核文件传递

2019-07-09 15:30:31

Linuxulimit文件描述符

2019-07-09 14:30:16

LinuxJava 服务器

2021-06-18 08:04:46

Linux进程操作系统

2013-12-02 17:33:20

Linux进程多线程

2020-04-29 15:10:16

Linux命令进程

2018-03-01 16:25:52

Linux内核内存管理

2023-05-08 12:03:14

Linux内核进程

2010-06-04 15:16:36

Linux 查看进程

2010-06-13 15:17:16

Linux 查看进程
点赞
收藏

51CTO技术栈公众号