Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The fuser command on Mac OS X is rather primitive and can't check for processes listening on a specific port. Does anybody know a good alternative? It it enough to know which process listening on that one port.

share|improve this question
1  
Try sudo lsof -i -P – vcsjones Dec 23 '10 at 17:02
    
I was under the impression that lsof` only works when a task actually connects to the port. Besides one would need at least a | grep portno as well to get a meaningful result. – Martin Dec 23 '10 at 18:09

As @vcsjones said in the comments, lsof is the tool for this:

$ sudo lsof -i tcp:80
COMMAND PID   USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
Safari  804 gordon   16u  IPv4 0x05a2cec8      0t0  TCP 192.168.6.3:50542->stackoverflow.com:http (ESTABLISHED)
httpd   874   root    3u  IPv6 0x05a2a940      0t0  TCP *:http (LISTEN)
httpd   878   _www    3u  IPv6 0x05a2a940      0t0  TCP *:http (LISTEN)

Without the -i, it shows all open files; with just -i it shows network files only; if you specify something after the -i you can restrict by any or all of: IPv4/6, TCP/UDP, hostname or IP, and port number/service name.

share|improve this answer
    
Just in case it's useful for someone like me looking to blindly kill all processes using a given port: lsof -i tcp:5000 | grep LISTEN | awk '{print $2}' | xargs kill kills all processes listening on port 5000 – JeremyKun Jun 28 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .