<- Back

How to Find and Kill a Process Using a Port on Mac

Fast solution to kill processes using specific ports on Mac with a simple one-line command.

Quick Solution

Kill a process on port 8080:

lsof -ti:8080 | xargs kill -9

Replace 8080 with your port number.

Step-by-Step

1. Find what's using the port

lsof -i :8080

Output:

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    12345  ashish   23u  IPv6 0x...      0t0  TCP *:8080 (LISTEN)

2. Kill the process

kill -9 12345

The PID is 12345 in this example.

Create a Shortcut

Add to ~/.zshrc:

killport() {
  lsof -ti:$1 | xargs kill -9
}

Then use:

killport 8080

Common Issues

Permission denied? Use sudo:

sudo lsof -ti:8080 | xargs sudo kill -9

Nothing found? The port might not be in use, or check:

lsof -PiTCP -sTCP:LISTEN  # See all listening ports

That's it. Bookmark this for next time.