1. 程式人生 > >linux下通過程序名檢視其佔用埠

linux下通過程序名檢視其佔用埠

1、先檢視程序pid

ps -ef | grep 程序名

2、通過pid檢視佔用埠

netstat -nap | grep 程序pid

例:通過nginx程序檢視對應的埠號

#檢視nginx程序pid:
命令:
ps -ef | grep nginx
結果:
root      9836     1  0 Jul11 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    9841  9836  0 Jul11 ?        00:00:09 nginx: worker process      

#通過nginx程序pid檢視佔用埠(程序pid為9836)
命令:
netstat -nap | grep 9836
結果:
tcp        0      0 0.0.0.0:8081 
0.0.0.0:* LISTEN 9836/nginx tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 9836/nginx tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 9836/nginx tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN 9836/nginx

https://www.cnblogs.com/MacoLee/p/5664306.html