How to kill the process using a port on macOS
On macOS, lsof tells you which process is listening on a port, and kill stops it. The examples use port 3000.
Quick answer
lsof -nP -iTCP:3000 -sTCP:LISTENCOMMAND PID USER FD TYPE ... NAME
node 4242 you 19u IPv6 ... *:3000 (LISTEN)kill 4242One 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.
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.
curl -fsSL https://raw.githubusercontent.com/rpratap2111/portfind/main/install.sh | shportfind