Problem description:
In the process of system management, it is often encountered that the port is occupied when a process is started. For example, port 9090 is often occupied when the WebSphere console is started. Using netstat-an | grep 9090, you can see that the port is being listened on, but you do not know which process occupies the port. Of course, you can change the port but it is troublesome. If you can find out which process occupies the port, kill the process.
Solution:
1. netstat-aan | grep <portnumber>
Find the PCB/ADDR corresponding to the port connection and the protocol type of the connection.
Note: PCB ---- Protocol control block
2. For TCP connection, rmsock <PCB/ADDR> tcpcb
If it is a UDP connection, the rmsock <PCB/ADDR> inpcb uses port 23 used by the telnet service as an example to describe this method:
# Netstat-aan | grep 23
F1000200019ce398 TCP 0 0 *. 23 *. * listen
The PCB/ADDR is f1000200019ce398 and the protocol type is TCP. # Rmsock f1000200019ce398 tcpcb
The socket 0x19ce008 is being held by proccess 185006 (inetd ).
The Command reports that the port is being used by the inetd process and the PID is 185006.
Note: The rmsock Command requires the root permission for execution. If we execute this command as a common user, the following error message is reported: