portfind

How to kill the process using a port on macOS

Updated

On macOS, lsof tells you which process is listening on a port, and kill stops it. The examples use port 3000.

Quick answer

Terminal: find it
lsof -nP -iTCP:3000 -sTCP:LISTEN
output
COMMAND  PID  USER  FD  TYPE  ...  NAME
node    4242  you   19u IPv6  ...  *:3000 (LISTEN)
stop it
kill 4242

One line

If the process ignores it, use kill -9 with the PID. That ends it immediately without letting it clean up, so only do it when the normal kill hasn't worked.

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

Ports 5000 and 7000: AirPlay Receiver

Since macOS Monterey, the AirPlay Receiver listens on ports 5000 and 7000, the default for Flask and some other dev servers. lsof shows it as ControlCenter. Don't kill it; turn it off instead:

  • System Settings → General → AirDrop & Handoff → AirPlay Receiver: switch it off.
  • Or run your server on another port, for example flask run --port 5001.

Nothing shows up, but the port is taken

Without sudo, lsof only shows your own processes. Run sudo lsof -nP -iTCP:3000 -sTCP:LISTEN to see processes owned by other users.

If it is a service started by Homebrew, stop it there so it doesn't come back: brew services list, then brew services stop postgresql@16.

If the process is com.docker.backend, the port belongs to a Docker container: run docker ps --filter "publish=3000".

See what you are killing first, with portfind

portfind shows every listening port with the process, its project folder, uptime, risk level and Docker container, and kills it with a keypress. It refuses to kill processes like launchd or WindowServer that would end your session.

install
curl -fsSL https://raw.githubusercontent.com/rpratap2111/portfind/main/install.sh | sh
then
portfind