查找具有最多 TCP 套接字的进程?

查找具有最多 TCP 套接字的进程?

如何找到当前正在使用 bash 运行的具有最多 TCP 套接字的进程?

我只想输出进程名称

答案1

如果你只对 TCP 套接字感兴趣,那么 lsof +c 0 -i tcp 就是答案,否则你需要扩展 lsof 的选项以包含其他类型的套接字

ps -ef | pgrep -lf `lsof +c 0 -i tcp | awk '{print $1}' | sort | uniq -c | sort -n | tail -1 | awk '{print $2}'` | cut -d' ' -f2 | uniq | sed -e 's/^.*\///'

安德烈

答案2

# ps -p $(netstat -tnp|awk '$6=="ESTABLISHED" {split($7,a,"/"); print a[1]}' | sort | uniq -c | sort -r | head -n 1 | awk '{print $2}') -o comm=
skype

相关内容