How do I find processes that listens to/uses my tcp ports? I'm on mac os x.
Sometimes, after a crash or some bug, my rails app is locking port 3000. I can't find it using ps -ef... How do I find the stupid thing and kill it, brutally... ?
When doing
rails server
I get
Address already in use - bind(2) (Errno::EADDRINUSE)
2014 update:
To complete some of the answers below: After executing the kill commands, deleting the pid file might be necessary rm ~/mypath/myrailsapp/tmp/pids/server.pid
One of the ways to kill a process on a port is to use the python library: freeport (https://pypi.python.org/pypi/freeport/0.1.9) . Once installed, simply:
This will give you just the pid, tested on MacOS.
Find PID and kill the process.
To forcefully kill a process like that, use the following command
Where 3000 is the port number the process is running at
this returns the process id(PID) and run
Replace PID with the number you get after running the first command
Here's a helper bash function to kill multiple processes by name or port
Usage:
Example:
I made a little function for this, add it to your rc file (
.bashrc
,.zshrc
or whatever)then you can just type
kill-by-port 3000
to kill your rails server (substituting 3000 for whatever port it's running on)failing that, you could always just type
kill -9 $(cat tmp/pids/server.pid)
from the rails root directory