How to find the PID of the process using a specific port

subject: Commands · date: 2017-12-09

  • Use lsof:

    $ sudo lsof -n -i :80 | grep LISTEN
    nginx   5004 nginx    3u  IPv4   6645      0t0  TCP 0.0.0.0:80 (LISTEN)
    
  • Use netstat:

    $ sudo netstat -nlp | grep :80
    tcp  0  0  0.0.0.0:80  0.0.0.0:*  LISTEN  5004/nginx
    
  • Use ss:

    $ sudo ss -lptn 'sport = :80'
    State   Local Address:Port  Peer Address:Port              
    LISTEN  127.0.0.1:80        *:*                users:(("nginx",pid=5004,fd=12))
    

read more

share this article