Skip to content
86% off$349 $48.86code BF2026

Guides

How to Find and Kill a Process on a Port on Mac

Find what's using a port on your Mac with lsof, stop it with kill, fix root-owned ports and the AirPlay port 5000 clash, and see every dev server at once.

GuideUpdated 9 min read

On this page

To kill a process on a port on a Mac, open Terminal and run lsof -nP -iTCP:3000 -sTCP:LISTEN (replace 3000 with your port). This shows which process is listening. Then run kill followed by the number in the PID column. If the process is still there a few seconds later, kill -9 <PID> ends it immediately.

This fixes "port 3000 already in use", Node's EADDRINUSE and Python's OSError: [Errno 48] Address already in use. Before you kill anything, check whether the old server is still running in another Terminal tab. If it is, pressing ⌃C (Control-C) in that tab stops it cleanly.

Find what's listening on a port with lsof

lsof ("list open files") comes with macOS. Network sockets count as open files, so it can tell you which process owns a port.

bash
lsof -nP -iTCP:3000 -sTCP:LISTEN

This lists only processes that are listening for TCP connections on port 3000. Each flag does one job:

  • -n skips turning IP addresses into host names, which makes the command faster.
  • -P shows port numbers instead of service names, so you see 3000 rather than a name from /etc/services.
  • -iTCP:3000 limits the output to TCP sockets on port 3000.
  • -sTCP:LISTEN keeps only sockets in the listening state. Without it, you also get every client connected to that port, including browser tabs that have the page open.

The output looks similar to this:

text
COMMAND   PID  USER   FD   TYPE  DEVICE  SIZE/OFF NODE NAME
node    48213  alex   23u  IPv6  0x...        0t0  TCP *:3000 (LISTEN)

The PID column holds the number you need. lsof cuts the COMMAND name to 9 characters by default, so long names look truncated.

The NAME column shows where the server accepts connections. *:3000 means it listens on every network interface, so other devices on your network may be able to reach it. 127.0.0.1:3000 or [::1]:3000 means only this Mac can connect.

For UDP, swap the protocol and drop the state filter, because UDP sockets don't have a listening state:

bash
lsof -nP -iUDP:4000

Without sudo, lsof only lists processes you have permission to examine. If it prints nothing but your app still says the port is in use, see "Ports owned by root or another user" below.

Kill the process on the port, and when to use kill -9

bash
kill 48213

This sends SIGTERM to process 48213. SIGTERM asks the process to exit cleanly: a dev server closes its connections, writes what it needs to and releases the port. Run the lsof command again to confirm the port is free.

kill -INT 48213 is another clean option. It sends SIGINT, the same signal ⌃C sends, which some servers handle more gracefully than SIGTERM.

If the process ignores both, force it:

Warning: kill -9 ends the process instantly. It gets no chance to save data, delete temporary or lock files, or stop its own child processes.

bash
kill -9 48213

Use -9 only after a plain kill has failed. None of these commands change a setting, so there is nothing to undo. You start the server again the usual way.

A one-liner to free a port

lsof -t prints only PIDs. You can feed that output straight into kill:

bash
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)

This sends SIGTERM to every process listening on TCP port 3000. If nothing is listening, kill prints a usage error. That error is harmless.

If you free ports often, add a small function to your shell. Put this line at the end of ~/.zshrc, then open a new Terminal window:

zsh
freeport() { kill $(lsof -t -iTCP:"$1" -sTCP:LISTEN); }

Now freeport 3000 stops whatever listens on port 3000. To undo it, delete the line from ~/.zshrc.

npx kill-port

If you work in Node projects, kill-port does the same job without memorizing flags:

bash
npx kill-port 3000

It can free several ports at once (npx kill-port 3000 5000 9000) and supports UDP with --method udp. There are trade-offs. It needs Node.js and npm, and it only kills: it doesn't list what owns the port first, so you won't see what you stopped. As of November 2026, its latest version on npm is 2.0.1, published about four years ago. The lsof one-liner above does the same thing with tools already on your Mac.

Ports owned by root or another user

If plain lsof shows nothing but the port is clearly taken, the listener probably belongs to root or another user account. Add sudo to see it:

bash
sudo lsof -nP -iTCP:3000 -sTCP:LISTEN

Terminal asks for your administrator password. Stopping the process also needs sudo:

bash
sudo kill 48213

Read the COMMAND and USER columns before you do this. A root-owned listener is usually a system service or something installed to start at boot, such as a database. launchd restarts many of these as soon as they exit. Stop them through the tool that installed them, or run your own server on a different port.

Port 5000 or 7000 in use? It's AirPlay Receiver

Since macOS Monterey, the AirPlay Receiver feature listens on ports 5000 and 7000. This clashes with Flask, whose development server uses port 5000 by default, and with other tools that pick these ports. lsof shows the owner as ControlCe, which is Control Center cut to 9 characters.

Killing it doesn't help, because macOS starts Control Center again. You have two fixes:

  1. Turn off AirPlay Receiver. Open System Settings, search for "AirPlay Receiver" and switch it off. On Sonoma and Sequoia it sits under General ▸ AirDrop & Handoff. To undo this, switch it back on.
  2. Keep AirPlay Receiver and move your server to another port, for example flask run --port 5001.

See every listening port and dev server at once

To list every TCP port your processes are listening on, drop the port number:

bash
lsof -nP -iTCP -sTCP:LISTEN

This works. In a busy setup with a frontend, an API, a database and a couple of forgotten servers from yesterday, though, it's a wall of PIDs. It doesn't tell you which project each one belongs to.

We built the Ports and Projects sections of Procowl, our Mac activity monitor, for this.

Procowl Ports with 3000 typed in the field: node on port 3000, This Mac only, with the browser and Stop… buttons
Type a port number to see which process holds it.

Ports (⌘4, Command-4) has a search field that reads "Who is using port… (e.g. 3000, :5432, node)". It accepts 3000, :3000, port 3000, localhost:5173 or the plain question "who is using port 3000?". Digits search by port prefix, and other text searches process names.

Each row shows:

  • the port and protocol
  • whether the server is This Mac only or Reachable from the network
  • the process (click it to open it in the process list)
  • a container tag when a running Docker container publishes the port

There's also a browser button that opens http://localhost:PORT and a Stop… button. Tick UDP to include bound UDP sockets.

Stop… always asks first. For a command-line server, Procowl sends SIGTERM, the same as kill. If the process won't exit, open it in the process list and use Force Quit…, which sends SIGKILL.

Projects (⌘5) groups running dev servers by project folder. Procowl uses the nearest .git (or .hg, .svn) folder, or else a manifest such as package.json, go.mod, Cargo.toml or pyproject.toml. It recognizes Node, Deno, Bun, Python, Ruby, Java, Go, PHP, Rust, .NET, Elixir and databases. Each card shows the folder, the server's port chips and a Stop… button for each process.

You can get the same answers from other places:

  • Command palette: press ⌘K (Command-K) and type :5432 or show port 5432. You can also type kill node, which still goes through the confirmation dialog.
  • Command line: install the procowl tool from Settings ▸ General ▸ Command-Line Tool ▸ Install…, then run procowl port 3000, procowl ports (add --udp for UDP), procowl projects or procowl stop <pid>. stop asks [y/N] first and refuses protected processes. Add --force to force quit, --yes to skip the question in scripts, and --json to any command for machine-readable output. procowl port exits with code 1 when nothing is listening. The tool works with Procowl's window closed. The procowl command-line tool docs cover installing and every option.
  • Shortcuts: the Who Is Using Port action returns entries like "node (pid 4242)", or an empty list when the port is free.
  • Links: procowl://port/3000 opens Ports with the query filled in.

One limit applies to all of these. Procowl shows your own processes' sockets, but not those of root or other users ("System services (root) are hidden without admin rights."). This stays true even with Procowl's optional Enhanced Access helper installed. For a root-owned listener, use sudo lsof as described above.

Procowl is part of MacSuite; you can try it free for 7 days.

Stop idle dev servers and Docker containers

A server you forgot about is a common cause of "port already in use". Procowl marks a dev server as idle after 15 minutes with CPU below 0.2% of a core and disk activity below 256 KB/s. When some are idle, Projects shows a banner listing them with their memory and ports.

Procowl Projects with the idle dev servers banner and the Stop idle dev servers sheet listing node and python3.12
Stop Idle… lists the idle servers; checked ones get SIGTERM.

To stop them:

  1. Open Projects (⌘5, Command-5).
  2. Click Stop Idle… in the banner.
  3. In the Stop idle dev servers sheet, make sure only the servers you want to stop are checked.
  4. Click Stop N Servers… and confirm.

The checked servers get SIGTERM. A message then shows the memory and ports that were freed.

Docker needs different handling. When a container publishes a port, lsof shows a process belonging to your Docker engine (Docker Desktop, OrbStack and so on) as the owner, not the app inside the container. Killing that process can take down the engine and every container with it. Stop the one container instead:

bash
docker ps
docker stop <container-name>

docker ps lists running containers and their published ports. docker stop stops one container. Start it again with docker start <container-name>.

In Procowl, the Containers list sits above the dev servers in Projects. It reads the local socket of Docker Desktop, OrbStack, Colima, Rancher Desktop, /var/run/docker.sock or a DOCKER_HOST Unix socket. Each container's ⋯ menu has Start, Stop…, Restart… and Copy Container ID. The Ports, dev servers and Docker docs cover every state and message.

Which method to use

MethodShows what's listeningStops itNeeds
lsof + killYes: PID, user, addressYesTerminal (built in)
npx kill-portNoYes, without showing what it stoppedNode.js and npm
Procowl Ports / ProjectsYes, plus project folder, reachability and Docker containerYes, after a confirmationMacSuite license or trial
procowl CLIYesYes, asks firstProcowl installed, license or trial

For listeners owned by root or another user, only sudo lsof and sudo kill help. Procowl hides those sockets.

Pick based on how you work:

  • lsof and kill: enough if a port clashes now and then and you know which server it is.
  • Procowl: useful if you run several projects at once, lose track of which server holds which port, or want idle servers and containers stopped from one place.

If the port is still in use

lsof shows nothing. The owner is probably root or another user. Run the same command with sudo. If the service uses UDP, check with -iUDP:<port> instead.

The process comes back right after you kill it. A parent process is restarting it. Common culprits are a file watcher like nodemon, a process manager, or launchd for services set to keep running. Find the parent with this command:

bash
ps -o ppid= -p 48213

It prints the parent's PID. Run ps -p <that PID> to see what the parent is, and stop that instead. In Procowl, the inspector shows the full Parents chain and a Launched by line naming the launch agent or daemon, if there is one.

kill says "operation not permitted". The process belongs to another user or to the system. Use sudo kill, after checking what the process is.

kill says "no such process". The process already exited. Run lsof again, because another process may have taken the port in the meantime.

Port 5000 or 7000 keeps getting taken. That's AirPlay Receiver. Turn it off or use another port, as described in the AirPlay section above.

The process won't die even with kill -9. This is rare. A process stuck waiting on a disk or network drive can't act on signals until that operation finishes. Wait, or reconnect the drive it's waiting on. If the process belongs to a frozen app, see how to force quit on a Mac.

If you want to see which apps send and receive traffic, rather than which ones listen on a port, read how to see which apps use the network on Mac.

Every app.
One purchase.