Mac Os Open Ports App

Mac

By default, it is assumed on macOS that ports will not need tools from Xcode.app unless (1) Command Line Tools aren't installed, (2) you are on an old version of Mac OS X that does not support the xcode-select mechanism, or (3) the port uses build.type xcode or includes the xcode PortGroup. 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. How do I find (and kill) processes that listen to/use my tcp ports? I'm on mac os x. Sometimes, after a crash or some bug, my rails app is locking port 3000.

Mac

How to find ports that are already 'in use' on macOS:

This is helpful if you are trying to figure out which process is using a port so that you can kill that process — for example, if you have a web server running in the background but now want to re-use that port for a different server.

Output of this command looks as follows:

This shows the results for a node http-server listening on port 8080. One could then kill this server using the PID shown.

Explanation

lsof is a program to 'list open files' and variants exist for major UNIX dialects such as macOS and Linux.

Open Port On Mac

  • sudo: you need sudo privileges to determine which files are open by other users on your system (and ports are just open files in a large sense)
  • -P: 'inhibits the conversion of port numbers to port names for network files'. Port numbers can be mapped to names for commonly used services, such as http for port 80. If you are trying to find which which process is running on a port number, it makes it more difficult if you need to think through the names as well. You can see which names are mapped on your system by viewing the /etc/services files.
  • -i TCP: filter the listing of files to internet addresses matching the argument. The argument here is just TCP but more general internet addresses of the form [46][protocol][@hostname|hostaddr][:service|port] are accepted as well. For example, if you are looking for processes using port 8080, you could provide that here, such as -i TCP:8080.
  • -s TCP:LISTEN: used together with -i TCP, causes only network files with TCP state LISTEN to be listed.

The command output varies significantly based on the type of file, but here, as we have filtered to only TCP network files with a LISTEN state, the output can be understood as follows:

  • command: partial command name
  • PID: process ID
  • NAME: the local host name or IP number followed by a colon, the port, and the two-part remote address (if applicable)

Source: man lsof

Apps For Mac

Please enable JavaScript to view comments.