In Linux, many times, you want to find out the PID of a process which is listening on a port e.g. if multiple apache(httpd) servers are running on a host then, how do you find the PID of the apache(httpd) listening on port 8080?
Here are few examples how to do that:
1. to find the PID of your httpd server listening on port 443, you can use following UNIX command:
# netstat -anp |grep 443 tcp 0 0 :::443 :::* LISTEN 1147/httpd
ps. (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)
From the output above we can see that process running on port 443 is httpd and PID: 1147
2. Another example of lsof command to list the process listening on a port.
# lsof -i :443 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 1147 apache 6u IPv6 5021617 0t0 TCP *:https (LISTEN)