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?
相关问题
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- Avoid cmake to add the flags -search_paths_first a
- installing packages for python 3
相关文章
- 现在使用swift开发ios应用好还是swift?
- Socket编程 TCP方式发送时间有点长
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- ImportError: No module named twisted.persisted.sty
- How can I vertically align my status bar item text
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:
On macOS, here's an easy way to get the process ID that's listening on a specific port with netstat. This example looks for a process serving content on port 80:
find server running on port 80
sample output
The 2nd from the last column is the PID. In above, it's 715.
options
-a
- show all ports, including those used by servers-n
- show numbers, don't look up names. This makes the command a lot faster-v
- verbose output, to get the process IDs-w
- search words. Otherwise the command will return info for ports 8000 and 8001, not just "80"LISTEN
- give info only for ports in LISTEN mode, i.e. serverson 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).
This did what I needed.
On macOS High Sierra, use this command:
On older versions, use one of the following forms:
Substitute
$PORT
with the port number or a comma-separated list of port numbers.Prepend
sudo
(followed by a space) if you need information on ports below #1024.The
-n
flag 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
-P
flag is for displaying raw port numbers instead of resolved names likehttp
,ftp
or more esoteric service names likedpserve
,socalia
.See the comments for more options.