macOS Monterey Port 5000

Luis Castillo
2 min readMay 8, 2022

--

ControlCenter | AirPlay Receiver

As a Developer, when we are working on an application locally, we use local development servers, which is typical for a framework that takes a port from our computer to operate. For example, ReactJS uses default port 3000, and Express uses port 5000.

Today was working on an application with ReactJS and NodeJS, and Express. for the Backend, I encounter an issue where I can’t run my Express server because port 5000 is in used. I used the command line to kill what ever program is using port 5000 with npx kill-port 5000 but the macOS re-open the program and continue using the port 5000.

Finding the program using port 5000

Find the Process ID (PID) Using lsof

Type the code below in your terminal and replace <port-number> with the port you want to find

lsof -nP -iTCP -sTCP:LISTEN | grep <port-number>

Example:

lsof -nP -iTCP -sTCP:LISTEN | grep 5000

This will generate something like this:

node 63851 pogo 27u IPv6 0xfded4774db1c601f 0t0 TCP *:5000 (LISTEN)

In the output above the PID (process ID) is the second value, in this example output the process ID (PID) is “63851”. This command will also print out the port number, which is 5000 in the above output example.

Find the Process ID (PID) Using netstat

Using the nestat command we can find the process ID (PID) for a specific port. In the terminal replace “<port-number>” with our port number.

netstat -anv | grep <port-number>

Example:

netstat -anv | grep 5000

After this command it will generate something like this:

tcp46 0 0 *.5000 *.* LISTEN 131072 131072 63851 0 0x0100 0x00000106

In the output above the PID (process ID) is the 5000 value (the fourth value from the end), in this example output the process ID (PID) is “63851”. This command will also print out the port number, which is 5000 in the above output example.

Find the Process Name

We can now use the process status command ps to display the process name for the process ID (PID).

ps -Ao user,pid,command | grep -v grep | grep <PID>

This will generate something like this:

63851/System/Library/CoreServices/ControlCenter.app/Contents/MacOS/ControlCenter

The output above gives the path that is using the port 5000 and the path ends with ControlCenter

How to stop ControlCenter from using port 5000?

The process running on this port turns out to be an AirPlay server. You can deactivate it in System Preferences › Sharing, and unchecking AirPlay Receiver to release port 5000.

--

--

Luis Castillo
Luis Castillo

Written by Luis Castillo

Software Engineer at Lowe's Companies, Inc.

No responses yet