Portmoleby techynARDownload

How to kill the process on a port on Mac

By techynAR · Updated

Short answerTo kill the process on a port on Mac, run kill $(lsof -t -iTCP:3000 -sTCP:LISTEN), replacing 3000 with your port. If it doesn't stop, add -9. You can also run npx kill-port 3000, or click ✕ next to the port in Portmole.

The one-liner

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

lsof -t prints only the PID, and kill sends it SIGTERM, the polite “please shut down” signal. A well-behaved server closes its sockets and exits within a second or two.

When it won't die

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

-9 is SIGKILL: the kernel ends the process immediately and it gets no chance to clean up. Use it only after plain kill has failed, because it can leave lock files or half-written data behind.

With npx

npx kill-port 3000

If you already have Node installed, the kill-port package does the lookup and the kill in one command and accepts several ports at once.

A server that comes back

If the port is taken again right after you kill it, something is restarting it: nodemon, a process manager, Docker, or an editor task. Stop the parent, not the child. Portmole's expanded view shows which runner started a server.

One click

In Portmole, ✕ sends SIGTERM and flags servers that ignore it so you can Force Quit; ⌥-click force-quits straight away. Closing ports is free. Portmole Pro adds restarting the server in the same folder with the same command.

Frequently asked questions

What is the difference between kill and kill -9?

kill sends SIGTERM and lets the process shut down cleanly. kill -9 sends SIGKILL, which ends it immediately without cleanup, so use it as a last resort.

How do I kill a port without knowing the PID?

Use kill $(lsof -t -iTCP:PORT -sTCP:LISTEN), which looks up the PID for you, or npx kill-port PORT.

Why do I get 'Operation not permitted' when killing a process?

The process belongs to another user or is protected by the system. You can only stop your own processes without sudo, and you shouldn't force system services.

Skip the terminal

Portmole shows every port your Mac is listening on and closes any of them with one click. Free, signed and notarized, about 7 MB.

Download Portmole for Mac

Keep reading