如何知道某个端口被哪个进程和应用程序占用?

From: http://blog.csdn.net/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.

你可能感兴趣的:(socket,shell,output)