根据端口查找占用程序
url:http://daimojingdeyu.javaeye.com/blog/542921
关键字: 端口, 程序
以最常见的三个系统为例,到处搜刮了一下,整理出来备用。
1、Windows:
以查找3019端口的占用程序为例:
写道
C:/Documents and Settings/Administrator>netstat -ano|findstr 3019
UDP 127.0.0.1:3019 *:* 2728
UDP 127.0.0.1:3019 *:* 2728
通过上面的命令,可以找到占用3019端口的进程ID为2728,然后再使用下面的命令
写道
C:/Documents and Settings/Administrator>tasklist|findstr 2728
Thunder.exe 2728 Console 0 29,224 K
Thunder.exe 2728 Console 0 29,224 K
可以看到是Thunder也就是迅雷在使用3019端口
2、Linux:
写道
$netstat -pan|grep 2809
tcp 0 0 0.0.0.0:2809 0.0.0.0:* LISTEN 9493/java
tcp 0 0 0.0.0.0:2809 0.0.0.0:* LISTEN 9493/java
3、Solaris:
先写一个port.sh的shell脚本,编辑其内容如下:
- #more/tmp/port.sh
- #!/bin/sh
- forpidin`ls/proc`
- do
- pf=`/usr/bin/pfiles$pid2>/dev/null`
- ifecho$pf|grep$1>/dev/null2>&1
- then
- echo$pid
- /usr/bin/pargs$pid
- fi
- done
# 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
使用chmod a+x port.sh 为port.sh增加可执行权限。
然后使用
./port.sh 53250
得到如下结果:
写道
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
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