AIX : Which process is using a port
id : u1is80xkbu
category : computer
blog : unix
created : 06/09/11 - 11:04:08
lsof way
  • If you have lsof on your system you can use it to determine which process is using a specific port :
# lsof -i:22
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
sshd    237726 root    3u  IPv4 0xf100060000c0db98      0t0  TCP *:ssh (LISTEN)

  • Process is sshd with 237726 pid.
rmsock way
  • First of all find socket with netstat :
# netstat -Aan | grep LISTEN | grep 22
f100060000c0db98 tcp4       0      0  *.22               *.*                LISTEN

  • Socket is f100060000c0db98, use rmsock to find process pid :
# rmsock f100060000c0db98 tcpcb 
The socket 0xc0d808 is being held by proccess 237726 (sshd).

  • Process is sshd with 237726 pid.
kdb way
  • First of all find socket with netstat :
# netstat -Aan | grep LISTEN | grep 22
f100060000c0db98 tcp4       0      0  *.22               *.*                LISTEN

  • Socket is f100060000c0db98, use kdb to find process pid :
# kdb
(0)> sockinfo f100060000c0db98 tcpcb
...
pvproc+00E800   58*sshd     ACTIVE 003A09E 00330FE 0000000017207400   0 0001
(0)> hcal 003A09E
Value hexa: 0003A09E          Value decimal: 237726

  • Process pid is 237726