Monday, March 1, 2010

sockinfo -find out which process holds given socket port

AIX Only
# cat /usr/bin/sockinfo
#!/bin/ksh
netstat -Aan | grep "*.$1" | read s1 t1 t2 t3 t4
echo "Socket Address=>$s1"
echo "sockinfo $s1 tcpcb " | kdb | grep "^pvproc" | read pvproc procname active hex1 hex2 rest
echo "Socket occupied by PID=>" $((16#$hex1))

EX:
# sockinfo 8080
Socket Address=>f100020001c64398
Socket occupied by PID=> 258154


or you can use lsof ( Generic AIX/Linux etc best)

Ex: lsof -i :8080
lsof: WARNING: compiled for AIX version 5.1.0.0; this is 5.3.0.0.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 258154 root 76u IPv6 0xf100020001c64398 0t0 TCP *:http-alt (LISTEN)

or
# rmsock f100020001c64398 tcpcb (AIX only)
The socket 0x1c64008 is being held by proccess 258154 (java).

No comments:

Post a Comment