Alex Rivera | Logout

Find (and kill) processes listening to port 3000 on Mac

Asked 2010-10-04T12:19:16.317
3185

How do I manually find (and kill) process using the terminal that listen to/use my TCP ports? I'm on macOS.

Sometimes, after a crash or bug, my Rails app gets locked to port 3000, and I can't find it using ps -ef...

When running

rails server

I get

Address already in use - bind(2) (Errno::EADDRINUSE)

The same issue happens when stopping the Node.js process. Even after the process is stopped and the app stops running, port 3000 is locked. When starting the app again, getting

Address already in use (Errno::EADDRINUSE)
Edit
Report

2 Answers

5054

For macOS El Capitan and newer (or if your netstat doesn't support -p), use lsof:

lsof -i tcp:3000

Alternatively, you can use netstat:

netstat -vanp tcp | grep 3000

Once you have the PID (Process ID) use:

kill -9 <PID>
answered 2010-10-04T12:48:57.843
67

In your .bash_profile, create a shortcut for terminate the 3000 process:

terminate(){
  lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9 
}

Then, call $terminate if it's blocked.

answered 2013-05-16T09:17:42.717

Your Answer