Best method Finding the PID of the process using a specific port on Linux?

How Finding the PID of the process using a specific port on Linux? #


Sometimes you may want to see what processes are active on a specific port of your Linux system.
Or sometimes you install software and when you try to activate it, you encounter this error that this port is in use and you don’t know exactly what process is working on the port. Well, here you can use this tutorial.

 

We see an example of these problems in the image below:

How Finding the PID of the process using a specific port on Linux?

As you can see in this image, the Nginx service cannot run because ports 80 and 443 are being used by another program.

1) SS command : #

In modern systems, ss is the appropriate tool to use to get this information:

Code

$ sudo ss -lptn ‘sport = :80’

Result

State Local Address:Port Peer Address:Port
LISTEN 127.0.0.1:80 *:* users:((“nginx”,pid=125004,fd=12))
LISTEN ::1:80 :::* users:((“nginx”,pid=125004,fd=11))

2) netstat command: #

Code

$ sudo netstat -nlp | grep :80

Result

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 125004/nginx

3) lsof command #

Code

$ sudo lsof -n -i :80

Result

nginx 125004 nginx 3u IPv4 6645 0t0 TCP 0.0.0.0:80 (LISTEN)

 

Powered by BetterDocs