[AIX]Find Out Which Process Is Listening Upon a Port Without Using "lsof"

投稿者:しんさん        2016/04/13


Same as "lsof -i:" on Linux

When we manage servers, there are several cases we'd like to find out which process is listening upon a certain port.

If we can use "lsof", we can detect the process by using "lsof -i:" just like below example.

[[email protected] ~]# lsof -i:22
sshd 2637 root 3u IPv4 14260 0t0 TCP *:ssh (LISTEN)
sshd 2637 root 4u IPv6 14262 0t0 TCP *:ssh (LISTEN)

In the case we can't use "lsof" on AIX

But on AIX Severs, there might be many cases "lsof" is not installed.
Even in such case, there is a way to find out the process combining those two Basic AIX commands

  • netstat
  • rmsock


Below is the example that I would like to know "who's using Port 22 TCP".

[[email protected] ~]$ netstat -An|grep LISTEN|grep -e '\.22 '|cut -d' ' -f1|xargs -i{} rmsock {} tcpcb
The socket 0xd2008 is being held by proccess 782496 (sshd).

First I use "netstat" to discover the socket number listening port 22, then use rmsock to find out the process id associated with the sockect. In this case it's PID 782496 and the name of process is "sshd".

Point to Notice

When using "rmsock", we should not run as root user.

Original purpose of "rmsock" is to remove the socket.

Unlike the name implies, "rmsock" does not remove the socket if it's being used but just reports the information of process holding the socket.

Nevertheless, Sever Administrators should be risk averse as far as possible in my opinion, we should not carelessly execute removal commands on superuser rights.

Fortunately, we can execute both "netstat" and "rmsock" as normal user.

いいね ! しよう

Twitter で
  • B!
  • LINEへ送る

 - Server Administration , , , ,