Developers

How to find which process is using a port on Mac

Updated · Applies to macOS 14 Sonoma through macOS 27 Golden Gate

Short answer

Run `lsof -nP -iTCP:3000 -sTCP:LISTEN` in Terminal (replace 3000 with your port). It prints the command and PID of the process listening there. Stop it with `kill <PID>`.

“Port 3000 is already in use.” Usually it’s a dev server from a project you forgot was running. Here’s how to find it, check it’s the one you think it is, and stop it cleanly.

What’s listening on a specific port

lsof -nP -iTCP:3000 -sTCP:LISTEN

-iTCP:3000 limits the list to TCP port 3000, -sTCP:LISTEN to processes accepting connections, and -nP shows raw addresses and port numbers, which is faster. The output includes the COMMAND and PID.

Or enter the port in the port finder to get these commands ready to copy.

Everything that’s listening

lsof -nP -iTCP -sTCP:LISTEN

You’ll see some system processes like rapportd and ControlCenter. Leave those alone. Look for node, bun, python, ruby, and com.docker.backend.

Which project did it come from?

Two commands tell you what it is and where it was started:

ps -o pid,etime,command -p <PID>     # full command line and how long it's been running
lsof -a -p <PID> -d cwd -Fn | tail -1  # its working directory (starts with "n")

The command line usually names the tool (next dev, vite, rails server), and the working directory is the project folder.

Stop it

kill <PID>

kill asks the process to exit, giving it a chance to clean up. Only if it ignores that, use kill -9 <PID>, which ends it immediately.

Without Terminal

In Activity Monitor, find the process, double-click it, and open the Open Files and Ports tab. It works, but you need to know which process to look at first.

Common development ports