Listing socket/network connection owners on OSX

While playing with OSX I was wondering how to find out all the networks connections a particular process owns. On Linux I’d use netstat -p for this, which does not work on OSX.

It turns out that the solution is quite simple – lsof -i does the job and works on both Linux and OSX. Two other useful commands:

lsof -ai -p PID    # all connections/sockets owned by PID
lsof -i:PORT       # lists all connections/sockets with a particular PORT.

One Response to “Listing socket/network connection owners on OSX”

  1. ben hall Says:

    Thanks for this- I was getting seriously frustrated. What is the deal with BSD/Darwin’s netstat? Showing the owning process just seems like a natural bit of functionality to include considering netstat is what shows the ports as open to begin with…

Leave a Reply