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.
December 4th, 2007 at 3:39 pm
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…