← Back to Blog

How to Kill a Process by Port on Mac

Need to free up a port fast? Here's how to find the process holding any port and kill it from Terminal, plus a one-liner that does both steps at once.

You want port 8080 free. You don’t care what’s using it. You just need it gone. macOS gives you the tools to do this in one Terminal command, once you know the right flags.

Find the Process First

lsof tells you which process owns a port. The -i flag filters by network socket, and :PORT narrows it to a specific port number:

lsof -i :8080

Sample output:

COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java     4821  aaron   42u  IPv6 0x...            0t0  TCP *:http-alt (LISTEN)

The PID column is what you need. In this case it’s 4821.

Kill It

kill -9 4821

The -9 flag sends SIGKILL, which forces the process to exit immediately. The process cannot catch or ignore it. The OS terminates it and reclaims the port.

One-Liner: Find and Kill in One Shot

If you just want the port free and don’t need to inspect the process first, you can do both steps at once:

kill -9 $(lsof -ti :8080)

The -t flag tells lsof to output only the PID: no headers, no extra columns. That makes it safe to substitute directly into kill.

SIGTERM vs SIGKILL

The -9 flag is not always the right choice. There are two common signals:

  • SIGTERM (signal 15): asks the process to exit gracefully. The process can catch this and do cleanup (flush writes, close database connections, save state) before exiting. This is kill 4821 with no flag.
  • SIGKILL (signal 9): forces the process to exit immediately. No cleanup, no warning. Use kill -9 4821.

For a stuck dev server that’s blocking your port, SIGKILL is fine. For a database or anything writing to disk, try SIGTERM first and give it a few seconds. If it doesn’t exit, then use SIGKILL.

When the Port Has Multiple Processes

Sometimes lsof returns more than one PID. This happens when a parent process forks worker processes, all sharing the same socket:

COMMAND     PID   USER  FD   TYPE  DEVICE  SIZE/OFF  NODE  NAME
nginx      1100  root   6u  IPv4  ...          0t0   TCP  *:80 (LISTEN)
nginx      1101  aaron  6u  IPv4  ...          0t0   TCP  *:80 (LISTEN)
nginx      1102  aaron  6u  IPv4  ...          0t0   TCP  *:80 (LISTEN)

To kill all of them at once:

kill -9 $(lsof -ti :80)

Because -t outputs each PID on its own line, the shell passes all of them to kill as separate arguments. All three processes get terminated.

Protect Yourself from the Wrong PID

A typo or off-by-one in the port number can kill the wrong process. Before running a kill command on a shared or production system, confirm the process name in lsof output matches what you expect.

If the COMMAND column shows something like postgres, redis-server, or a database daemon, and you were expecting a Node.js dev server, stop and investigate. Killing a database mid-write can corrupt data.

Using Portie

Portie shows every open port on your Mac in a live list, updated every 3 seconds. You can see the process name and PID for each port at a glance. No flags to remember.

The free tier covers local monitoring. The $8.99 one-time unlock adds the ability to kill a process directly from the list with a single click. You choose SIGTERM or SIGKILL from a menu. No Terminal required.

Try Portie Free

See every open port on your Mac, which app owns it, and kill processes from the list.

Download Free