ParsaLabs | Blog

A publication about the web and more.

Kill PIDs on a Certain Port in Mac

| Comments

I use Phusion Passenger (in conjunction with foreman) for some of my projects, and one problem I face is that even after I stop the standalone server by pressing Ctrl-C, passenger continues to occupy port 5000. So when I do foreman start to run the server again, I get an error saying port 5000 is already in use. However, this issue fades away when I manually start Phusion Passenger’s standalone server using the following command in terminal:

1
bundle exec passenger start -p $PORT --max-pool-size 3

as opposed to the normal foreman start. But anyways, this was a chance to learn (on Mac OS) how to find processes that are using certain ports, and kill them. Here’s the script that works for me:

1
lsof -P | grep ':5000' | awk '{print $2}' | xargs kill -9

Cheers

Comments