Under AIX, how can I get the full path of a program bound to a port?
Solution 1
As recommended by IBM: use lsof -i -n
and look for port XY. If you want parseable output from lsof
, use the -F
flag and parse the output with awk.
You can get pre-compiled binaries for AIX V5. I don't know if there are pre-compiled binaries for V6; if there aren't, get the source and compile it.
Solution 2
Try using netstat
with rmsock
.
port=$1
addr=`netstat -Aan | grep $port | awk '{print $1}`
pid=`rmsock $addr tcpcb | awk '{print $9}'`
ps -ef | grep $pid
For netstat
, the -A
shows the address of any protocol control blocks associated with the sockets, the -a
option shows the state of all sockets including those of server processes, and the -n
option gives output in numeric form, so you're not wasting time trying to resolve addresses.
rmsock
, using the address given in the column1 output of netstat
, and using the tcpcb
database, will return information about the process holding that socket, including the pid and name.
You can then use ps -ef | grep $pid
to get the process information.
You can see this article at IBM Systems Magazine for more info on this.
Solution 3
One of the quickest way to find the application locking port is to use lsof or lsof64:
lsof64 -nP | grep $PortNumber
or
lsof -nP | grep $PortNumber
Above will return process ID locking/using given port number. Once you have it then run below to find running application/process
proctree $pid
Related videos on Youtube
LanceBaynes
Updated on September 18, 2022Comments
-
LanceBaynes over 1 year
Under Linux I can use
netstat -tulpnw
andps
, like so:# netstat -tulpnw | grep :53 tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1482/named udp 0 0 127.0.0.1:53 0.0.0.0:* 1482/named # ps aux | fgrep 1482 named 1482 0.0 1.0 93656 44900 ? Ssl Sep06 3:17 /usr/sbin/named -u named root 20221 0.0 0.0 4144 552 pts/0 R+ 21:09 0:00 fgrep --color=auto 1482 #
How can I get the full path of a program bound to a port when using
ksh
in AIX 6? -
LanceBaynes over 12 yearslsof is not always available on AIX:P
-
Gilles 'SO- stop being evil' over 12 yearsYou can check the manual online. AIX
ps
does support traditional BSD flags, but how do the flags you indicated help? -
Gilles 'SO- stop being evil' over 12 years
-
frogstarr78 over 12 yearsHm, looks like they do different things on AIX. Although the documentation you referenced includes an l option which prints "USER, PID, %CPU, %MEM, SZ, RSS, TTY, STAT, STIME, TIME, and COMMAND fields"
-
LanceBaynes over 12 yearsthere aren't always "lsof" on the machines... but i could take this as a good answer (other ones are "good" too! ty)
-
S edwards over 10 yearsthis is not event executing correctly on my AIX