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?
On Linux, I can use netstat -pntl | grep $PORT or fuser -n tcp
Share
On macOS
Big Surand later, use this command:or to just see just IPv4:
On older versions, use one of the following forms:
Substitute
$PORTwith the port number or a comma-separated list of port numbers.sudomay not be needed if you need information on ports above 1023.The
-nflag is for displaying IP addresses instead of host names. This makes the command execute much faster, because DNS lookups to get the host names can be slow (several seconds or a minute for many hosts).The
-Pflag is for displaying raw port numbers instead of resolved names likehttp,ftpor more esoteric service names likedpserve,socalia.See the comments for more options.
For completeness, because frequently used together:
To kill the PID: