From: http://blog.youkuaiyun.com/techcrunch/archive/2008/04/12/2284315.aspx
第一种方案:
1 使用下面shell script,先建立一个port.sh文件:
# more /tmp/port.sh
#!/bin/sh
for pid in `ls /proc`
do
pf=`/usr/bin/pfiles $pid 2>/dev/null`
if echo $pf | grep $1 > /dev/null 2>&1
then
echo $pid
/usr/bin/pargs $pid
fi
done
2 运行port.sh, 传入端口号,比如53250 :
# /tmp/port.sh 53250
3 运行结果如下:
1225
1225: /usr/lib/thunderbird/thunderbird-bin -UILocale zh-CN
-contentLocale CN
argv[0]: /usr/lib/thunderbird/thunderbird-bin
argv[1]: -UILocale
argv[2]: zh-CN
argv[3]: -contentLocale
argv[4]: CN
4212
4212: /bin/sh /tmp/port.sh 53250
argv[0]: /bin/sh
argv[1]: /tmp/port.sh
argv[2]: 53250
第二种方案:
下载"lsof" package。但可能不适合每种情况
第三种方案:
使用MDB
from socket info (netstat output), you can know its vnode
from vnode info, you can know which process owns it
from process info, you can know its args, so comes the result.
本文介绍了三种用于查找特定端口对应进程的方法:一是通过shell脚本遍历/proc目录;二是下载并使用lsof工具;三是利用MDB进行内核级调试。这些方法适用于不同场景下的需求。

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



