skip to content
Just Change Direction

How to kill multiple processes for a port in one command

/ 1 min read

I have ran into an issue recently where I have had multiple processes running on the same port even after closing it. This then seems to cause some issues with a related gRPC server when I try to restart it.

Until now, I have been manually killing each process like this:

Terminal window
lsof -t -i:<port-number>
kill -9 <process-id> # repeat for each process

With the help of ChatGPT, I now use this command to kill all processes for a port in one go:

Terminal window
kill -9 $(lsof -t -i:<port-number>)

It’s a small thing but removes one of those small frictions to your workflow that build up over time.