歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> Solaris平台上如何知道某個端口被哪個進程和應用程序占用

Solaris平台上如何知道某個端口被哪個進程和應用程序占用

日期:2017/2/28 11:13:56   编辑:關於Unix


我經常在Solaris服務器上啟好幾個Tomcat和GlassFish, 會遇到"端口"被占用的錯誤, 很難直接用命令得知這個端口到底被哪個進程或者應用程序占用了, Alex給了我三個解決方案。附帶說一句,我只嘗試了第一種方案,相當的好用。而Alex願意花時間找解決方案,卻不願意花幾分鐘把這些好東西寫出來,結果就是被我發表出來。功勞還是要歸Alex Peng.
第一種方案:
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.
Copyright © Linux教程網 All Rights Reserved