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)
function killport() { lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9 }
kill -9 $(lsof -ti:3000)
not working?