[AIX]Find Out Which Process Is Listening Upon a Port Without Using "lsof"
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.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
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
Below is the example that I would like to know "who's using Port 22 TCP".
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.