# How to kill a port on Mac (3000, 8080 and more) Source: https://portlivo.com/guides/kill-process-on-port-mac · Updated 2026-12-04 You want to close whatever is stuck on a port so you can start your project. Here’s the safe way to do it, a faster way for next time, and what to do when it keeps coming back. **In short:** Ask whatever is using the port to quit: `lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill` (swap in your port). If it’s still there after a few seconds, force it with `kill -9`. If it keeps coming back, it’s a background service or a Docker container, and it has to be stopped with `brew services stop` or `docker stop` instead. In Portlivo it’s one click, and it picks the right way for you. ## The one-liner Find the PID listening on the port and send it SIGTERM: ``` lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill ``` `-t` prints only PIDs, and `-sTCP:LISTEN` keeps it to the server, not to browsers or clients that happen to be connected to it. Without that filter the list also includes your browser, so you could end up quitting the browser instead of the server. A range of ports works too, for example every port from 3000 to 3010: ``` lsof -ti tcp:3000-3010 -sTCP:LISTEN | xargs kill ``` ## Step by step 1. List what listens on the port: `lsof -nP -iTCP:3000 -sTCP:LISTEN` 2. Check it is the right thing: `ps -p -o command=` 3. Ask it to quit: `kill ` 4. Wait a moment and check again. Only if it is still running: `kill -9 ` Not sure how to read the lsof output? [The port-in-use guide](https://portlivo.com/guides/port-already-in-use-mac#find) walks through each column. ## kill, kill -INT or kill -9? | Command | Signal | When to use it | | --- | --- | --- | | `kill ` | SIGTERM | First choice. The server closes files and connections, then exits. | | `kill -INT ` | SIGINT | What Ctrl-C sends. Useful when a server only cleans up on Ctrl-C. | | `kill -9 ` | SIGKILL | Last resort. It can’t be caught, so nothing gets cleaned up. | ## Shortcuts if you do this often Add a function to `~/.zshrc`, open a new terminal, then run `killport 3000`: ``` killport() { lsof -ti tcp:"$1" -sTCP:LISTEN | xargs kill; } ``` Or use an npm tool. `npx kill-port 3000` sends SIGKILL right away, with no grace period. `npx fkill-cli :3000` stops the process on a port, and `npx fkill-cli` on its own opens an interactive picker. ## Stop a server by name instead of port When you know what it is but not which port it took, match the command line with `pkill -f`: ``` pgrep -lf "vite" # list matching processes first pkill -f "vite" # then stop them (SIGTERM) ``` `-f` matches anywhere in the full command line, so `pkill -f node` stops every Node process, your editor’s helpers included. Always run `pgrep -lf` with the same pattern first and check the list. ## Check the port is free ``` nc -z localhost 3000 2>/dev/null && echo taken || echo free ``` `free` means you can start your server. If it still says `taken` a second after you stopped the process, a supervisor restarted it: see the next section. ## When it comes straight back A supervisor is restarting it. Stop it at the source: | What holds the port | Stop it with | | --- | --- | | Homebrew service (Postgres, MySQL, Redis) | `brew services stop ` | | Docker or OrbStack container | `docker stop ` | | pm2 | `pm2 stop ` | | nodemon or a file watcher | Ctrl-C in the terminal that runs it | | launchd agent | `launchctl bootout gui/$(id -u)/