Kill the process listening to a port

Riley Tomasek

It's inevitable if you work on enough projects, or with flakey enough servers, that when you start a server there is already something running on that port.

Here's an easy way to kill the process listening on port 8000:

kill $(lsof -t -i:8000)

What's going on here?

lsof -t -i:8000 returns the process number listening to port 8000 and kill $() kills the process.

You can also use lsof to get more details without killing the process by running:

lsof -i:8000