Linux 查看一个进程打开了哪些文件

netstat

获得要查看的进程的pid
ps aux|grep process_name
命令
netstat -p program_pid
举栗子
[root@localhost ~]# ps aux|grep nginx
root      11940  0.0  0.0  46212  1160 ?        Ss   13:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
wp        11941  0.0  0.1  46672  1920 ?        S    13:02   0:00 nginx: worker process
root      12066  0.0  0.0 112824   980 pts/0    S+   13:27   0:00 grep --color=auto nginx

[root@localhost ~]# netstat -p 11940
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0     36 localhost.localdoma:ssh 192.168.186.1:7433      ESTABLISHED 8707/sshd: root@pts 
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ]         DGRAM                    17663    709/chronyd          /var/run/chrony/chronyd.sock
unix  2      [ ]         DGRAM                    13599    1/systemd            /run/systemd/shutdownd
unix  3      [ ]         DGRAM                    441      1/systemd            /run/systemd/notify
unix  2      [ ]         DGRAM                    443      1/systemd            /run/systemd/cgroups-agent
unix  5      [ ]         DGRAM                    457      1/systemd            /run/systemd/journal/socket
unix  15     [ ]         DGRAM                    459      1/systemd            /dev/log
unix  3      [ ]         STREAM     CONNECTED     21433    1459/master          
unix  3      [ ]         STREAM     CONNECTED     21485    1459/master          
unix  3      [ ]         STREAM     CONNECTED     21470    1459/master          
unix  2      [ ]         DGRAM                    19471    706/dbus-daemon      
unix  3      [ ]         STREAM     CONNECTED     17844    726/systemd-logind   
unix  3      [ ]         STREAM     CONNECTED     14948    1/systemd            /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    22266    1520/qmgr            
unix  2      [ ]         DGRAM                    17682    702/VGAuthService    
unix  3      [ ]         STREAM     CONNECTED     21453    1459/master          
unix  3      [ ]         STREAM     CONNECTED     21498    1459/master          
unix  3      [ ]         STREAM     CONNECTED     14848    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     21477    1459/master          
unix  3      [ ]         STREAM     CONNECTED     21462    1459/master          
unix  3      [ ]         STREAM     CONNECTED     18552    706/dbus-daemon      
unix  3      [ ]         STREAM     CONNECTED     18781    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     21494    1459/master          
unix  3      [ ]         STREAM     CONNECTED     21449    1459/master          
unix  3      [ ]         STREAM     CONNECTED     18820    706/dbus-daemon      /run/dbus/system_bus_socket

lsof

1. lsof -c process_name

命令
lsof -c process_name
举栗子
[root@localhost ~]# lsof -c nginx
COMMAND   PID USER   FD      TYPE             DEVICE SIZE/OFF     NODE NAME
nginx   11940 root  cwd       DIR              253,0      151    12971 /usr/local/nginx
nginx   11940 root  rtd       DIR              253,0      237       64 /
nginx   11940 root  txt       REG              253,0  7688160 17030071 /usr/local/nginx/sbin/nginx
nginx   11940 root  mem       REG              253,0    61560    36534 /usr/lib64/libnss_files-2.17.so
nginx   11940 root  mem       REG              253,0   155744    59473 /usr/lib64/libselinux
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值