On Linux, I can use netstat -pntl | grep $PORT or fuser -n tcp $PORT to find out which process (PID) is listening on the specified TCP port. How do I get the same information on Mac OS X?
Join them; it only takes a minute:
|
Depending on your version of Mac OS X, use one of these:
Substitute Prepend The See the comments for more options. |
|||||||||||||||||||||
|
|
You can also use:
This works in Mavericks. |
|||||||||||||||||||||
|
|
For Yosemite (10.10) and El Capitan (10.11) and macOS Sierra (10.12):
|
|||||||||
|
|
Update January 2016 Really surprised no-one has suggested:
to get the basic information required. For instance, checking on port 1337:
Other variations, depending on circumstances:
You can easily build on this to extract the PID itself. For example:
which is also equivalent (in result) to this command:
Quick illustration: For completeness, because frequently used together: To kill the PID:
or as a one liner:
|
||||
|
This works in Mavericks (OSX 10.9.2).
|
|||||||||||||||||
|
|
On Snow Leopard (OS X 10.6.8), running 'man lsof' yields:
(actual manual entry is 'lsof -i 4 -a -p 1234') The previous answers didn't work on Snow Leopard, but I was trying to use 'netstat -nlp' until I saw the use of 'lsof' in the answer by pts. |
|||
|
|
|
on OS X you can use the -v option for netstat to give the associated pid. type:
the output will look like this:
The PID is the number before the last column, 3105 for this case |
|||||
|
This displays who's doing what. Remove -n to see hostnames (a bit slower). |
|||||||||||||||||||||
|
|
I am a Linux guy. In Linux it is extremely easy with |
|||||
|

netstat -p tcp | grep $PORT. I think this out of topic here. – khachik Dec 12 '10 at 12:34netstat -p tcp | grep $PORTdoesn't display PIDs since netstat on the Mac OS X cannot display PIDs. – pts Dec 12 '10 at 12:39