1.使用lsof找出pid
lsof -i:22
2.使用netstat找出pid
#找出非监听端口
netstat -ntp | grep ":22"
#找出监听端口
netstat -ntpl | grep ":22"
3.使用ps找出进程名
ps -ef|grep $pid
本文介绍了通过lsof、netstat和ps命令查找特定端口(如22端口)对应进程ID(PID)的三种实用方法。首先,使用lsof命令结合端口号直接获取PID;其次,利用netstat命令区分非监听与监听状态的端口来查找PID;最后,通过ps命令结合grep过滤出指定PID对应的进程名称。
1.使用lsof找出pid
lsof -i:22
2.使用netstat找出pid
#找出非监听端口
netstat -ntp | grep ":22"
#找出监听端口
netstat -ntpl | grep ":22"
3.使用ps找出进程名
ps -ef|grep $pid
1229
1万+
2万+

被折叠的 条评论
为什么被折叠?