Question
How to find out which application is using what port?
Answer
For AIX:
1. netstat -Aan | grep <port number>
- This shows if the specified <port number> is being used. The hex number in the first column is the address of protocol control block (PCB)
2. rmsock <addr of PCB> tcpcb
- This shows the process who is holding the socket. Note that this command must be run as root.
An AIX example:
# netstat -Aan | grep 9515
f100060003743b98 tcp4 0 0 *.9515 *.* LISTEN
# rmsock f100060003743b98 tcpcb
The socket 0x3743808 is being held by proccess 438488 (java).
For Windows:
Let’s say that we are looking for port 9549 — Data server.
Here is the command.
C:\> netstat -aon | findstr 9549
-a means list all active connections and their ports.
-o means include their process IDs.
-n means display the port numbers numerically.
The pipe symbol ( | ) means, that instead of the result of netstat being displayed on the screen, feed it’s result to the findstr process — we are looking specifically for the line which has port 9549.
You might see something like this
TCP 0.0.0.0:9549 0.0.0.0:0 LISTENING 3444
Now we know that process 3444 is using port 9549 (that last column right there, is the process ID).
You could now enter "tasklist".
C:\> tasklist | findstr 3444
java.exe 3444 Console 0 22,920 K
tasklist is another Windows command line utility which shows you a list of all active processes.
In this case, the process is the java process link to the data server process.
If you kill process 3444, you kill the data server service.