Command to trace process to port and vice versa
Few times while doing day today admin tasks like starting a server, etc we get issues like the port is already in use issues or sometimes we don’t know what is the port number used by a process id.
to get those kind of answers we can follow below methods in Windows and Unix flavor OS.
Windows:
To get port number associated with a process ID.
To get the process ID of a running process ->
Open cmd prompt and execute “tasklist” command. It will give you the process ID associated with the process name.
After getting the process ID run “netstat -anb | find “ProcessID” ” in cmd prompt without double quotes to find the ports opened/used by the selected process.
To get process ID associated with a port number.
run “netstat -anb | find “PortNumber”” without double quotes to get the process ID associated with the port number.
Once processID is retrieved run “tasklist | find “ProcessID”” to get the process name which is using the port number.
Unix:
To get the process ID of a running process ->
Open shell and execute “ps -eaf | grep processname” or “/usr/ucb/ps -auxww | grep processname” command. It will give you the process ID associated with the process name.
After getting the process ID run “netstat -antlup | grep ProcessID ” in shell to find the ports opened/used by the selected process.
To get process ID associated with a port number.
run “netstat -antlup | grep PortNumber” without double quotes to get the process ID associated with the port number.
Once processID is retrieved run “ps -eaf | grep processID” or “/usr/ucb/ps -auxww | grep ProcessID” to get the process name/path which is using the port number.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.