pwdx与netstat、lsof结合查找进程号是由哪个程序启动的

pwxd命令是查看指定进程号由哪个程序启动的,或者说查看指定进程号所在的工作目录,那么进程号我们可以 通过netstat 命令或者lsof命令来获取,比如使用netstat命令查看本机上正在监听的tcp链接,如下;

[root@master /]# netstat -lntp							#查看本机正在监听的tcp链接
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1966/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1211/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1189/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1807/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2588/sshd: root@pts 
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::1521                 :::*                    LISTEN      2707/tnslsnr        
tcp6       0      0 :::21365                :::*                    LISTEN      2778/ora_d000_orcl  
tcp6       0      0 :::22                   :::*                    LISTEN      1211/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1189/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1807/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2588/sshd: root@pts 
tcp6       0      0 :::5500                 :::*                    LISTEN      2707/tnslsnr     
[root@master /]# pwdx 2778				#查看进程号为2778是有哪个程序发起的
2778: /u01/app/oracle/product/12.1.0.2/db_1/dbs   

当我们要查找指定端口是谁在监听,使用lsof命令,如下:

[root@master proc]# lsof -i:1521
COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
tnslsnr   2707 oracle    9u  IPv6  23973      0t0  TCP *:ncube-lm (LISTEN)
tnslsnr   2707 oracle   14u  IPv6  27049      0t0  TCP master:ncube-lm->master:27786 (ESTABLISHED)
ora_lreg_ 2770 oracle    9u  IPv4  25340      0t0  TCP master:27786->master:ncube-lm (ESTABLISHED)
[root@master proc]# pwdx 2770
2770: /u01/app/oracle/product/12.1.0.2/db_1/dbs
[root@master proc]# 

当然,你也可以使用ps 来查找服务,得到进程号然后使用pwdx命令查看程序的工作目录;

一般的,当我们不知道主机上有哪些程序正在跑时,我们可以使用netstat -lntp来列出所有的正在监听的tcp链接,然后就能根据进程号结合pwdx命令来确定指定进程的工作目录了,也就能指定是哪个程序发起的进程号了。

更为方便的,我们可以将netstat和pwdx通过awk结合起来使用来达到快速查看当前主机安装了哪些程序,如下:

root@master /]#pwdx `netstat -lntp | grep -v Proto|awk '{print $7}'| awk -F/ '{print $1}'`
1: /
1966: /
1211: /
1189: /
1807: /var/spool/postfix
2588: /
1: /
2707: /home/oracle
2778: /u01/app/oracle/product/12.1.0.2/db_1/dbs
1211: /
1189: /
1807: /var/spool/postfix
2588: /
2707: /home/oracle

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值