Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Given a port number how can we find which process is using it?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

We have a variety of options:

  • netstat
  • fuser
  • lsof

netstat

sudo netstat -nlp

will give you all open network connections.

enter image description here


lsof

lsof -i tcp:43796

will give you the list of processes using tcp port 43796.

enter image description here


fuser

fuser 43796/tcp

will give you the list of pids using tcp port 43796.

enter image description here


Source

share|improve this answer

Try lsof

sudo lsof -n -P -i +c 13

Output will be like

COMMAND       PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
avahi-daemon 1222    avahi   13u  IPv4  10835      0t0  UDP *:5353 
avahi-daemon 1222    avahi   14u  IPv6  10836      0t0  UDP *:5353 
avahi-daemon 1222    avahi   15u  IPv4  10837      0t0  UDP *:32913 
avahi-daemon 1222    avahi   16u  IPv6  10838      0t0  UDP *:41774 
cupsd        1242     root    8u  IPv6   1847      0t0  TCP [::1]:631 (LISTEN)
cupsd        1242     root    9u  IPv4   1848      0t0  TCP 127.0.0.1:631 (LISTEN)
dhclient     1859     root    6u  IPv4  11971      0t0  UDP *:68 
gdomap       1876   nobody    3u  IPv4  11083      0t0  UDP *:538 
gdomap       1876   nobody    4u  IPv4  11084      0t0  TCP *:538 (LISTEN)
master       1975     root   12u  IPv4  12024      0t0  TCP 127.0.0.1:25 (LISTEN)
master       1975     root   13u  IPv6  12025      0t0  TCP [::1]:25 (LISTEN)
dnsmasq      1987   nobody    4w  IPv4  12039      0t0  UDP 127.0.0.1:53 
dnsmasq      1987   nobody    5u  IPv4  12040      0t0  TCP 127.0.0.1:53 (LISTEN)
firefox      4370 shashank   50u  IPv4  18226      0t0  TCP 192.168.1.2:33467->69.171.248.16:443 (ESTABLISHED)

Or Try netstat

 sudo netstat --tcp --programs

output will be like

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp       29      0 192.168.1.2:44054       69.59.197.29:http       ESTABLISHED 4370/firefox    
tcp        0      0 192.168.1.2:44087       69.59.197.29:http       ESTABLISHED 4370/firefox    
tcp       58      0 192.168.1.2:43895       69.59.197.29:http       ESTABLISHED 4370/firefox    
tcp       58      0 192.168.1.2:43935       69.59.197.29:http       ESTABLISHED 4370/firefox  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.