Who is stealing my port ?
I often had to deal with problems about port already in use.
The main question
was why my server cannot bind on port xxx ? On Linux the
--program
option of netstat
show you the id of the process currently owning a specific socket
connection.
Solaris's
netstat command does
not have this option. Tired to scan the
/proc with
pfiles I've made a
small script. I hope it can be useful to somebody else.
#!/bin/sh
if [ $# -ne 1 ]
then
echo "usage $0 <port number>"
exit 1
fi
PORT=$1
echo "looking for process consuming port $PORT"
old=`pwd`
cd /proc
for pid in *
do
/usr/bin/pfiles $pid 2>/dev/null | /usr/bin/nawk -v port_num=$PORT '
$0 ~ /^[0-9]*:/ {
pid=$1
program=$2
}
$1 ~ /^[\t ]*sockname/ && $5 == port_num {
printf ("program [%d:%s] is bounded on %s:%d\n",pid,program,$3,port_num)
}'
done
cd $old
Posted at 07:40PM août 08, 2007 by ejannett in Unix | Comments[3]
Today's Page Hits: 5
lsof -i :8080
will list all processes busy with that port.
http://en.wikipedia.org/wiki/Lsof
Posted by Alain Honorez on août 09, 2007 at 08:21 AM CEST #
yep you are right. but as for 'netstat --program' you will
have to be on Linux (or a system on which lsof is installed) for that.
That was not my case :-(
Posted by 192.18.1.36 on août 09, 2007 at 11:08 AM CEST #
Thank you very much for this useful script, works perfectly!
Posted by summerian on juin 01, 2009 at 12:28 PM CEST #