netstat、pid 与端口

2017年08月01日

查看端口 5555 所占用的 pid

netstat -vanp tcp | grep 5555

lsof -nP -iTCP:5555 -sTCP:LISTEN

输出该端口占用的 pid

lsof -nP -iTCP:5555 |grep LISTEN|awk '{print $2;}'

Linux:

netstat -nlp

查看某应用占用的进程:

ps aux | grep ruby

参考:

使用 lsof 代替 Mac OS X 中的 netstat 查看占用端口的程序