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