linux进程与端口


1.通过进程名查其占用端口:
    查看进程名PID
    # ps -ef | grep 进程名

    根据pid查看占用端口
    # netstat -nap | grep PID 

    # ps -ef|grep ssh
    root     17231  9429  0 10:32 ?        00:00:00 sshd: patrol [priv]
    # netstat -nap|grep 17231
    tcp        0     52 192.168.148.6:22            16.96.46.198:54278          ESTABLISHED 17231/sshd          
    unix  3      [ ]         STREAM     CONNECTED     127099770 17231/sshd          
    unix  2      [ ]         STREAM     CONNECTED     127099766 17231/sshd          
 
==================

2.通过端口查看进程:
    # netstat -nap | grep 端口号

    # netstat -nap|grep 22
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      9429/sshd           
    tcp        0     52 192.168.148.6:22            16.96.46.198:54278         ESTABLISHED 17231/sshd          
    tcp        0      0 192.168.148.6:22            192.168.148.12:50634        ESTABLISHED 15075/sshd          
    tcp        0      0 192.168.148.6:22            192.168.148.12:49876        ESTABLISHED 32586/sshd          
    tcp        0      0 :::22                       :::*                        LISTEN      9429/sshd