macosprocess

Find (and kill) process locking port 3000 on Mac


How do I find (and kill) processes that listen to/use my TCP ports? I'm on macOS.

Sometimes, after a crash or some bug, my Rails app is locking port 3000. 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 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)

Solution

  • 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>