How to find and kill a running process by its port number in Mac OS

Back to all
Dev
27th March '26

I run into this fairly regularly due to a particular set up on my work laptop which I can't do much about - I start Podman (an open source alternative to Docker Desktop), start a bunch of containers, and inevitably at least one of them doesn't start.

No obvious errors, nothing at all really, it just doesn't start. In my experience this is almost always because the the port the container was trying to run on is already in use.

Sometimes this might be something you know about - a local server running in your terminal or something like that which you can just quit and run on another port if you need to. But other times this will be a process you know nothing about, which is where the following solution comes in.

I just wanted to quickly note this down, as much as anything so I have a quick reference when I inevitably have to do this in future.

1. Find the port in question

For this example, lets just say our container is trying to run on port 1234

2. Use that port number to find the Process ID (PID) of the process which is using it

lsof -i tcp:1234

This will return a table in your terminal, in which you should clearly be able to see the PID. For this example, lets assume the PID is 9876

3. Use that PID to kill the process

kill -9 9876

Done!

More.

Other links — Email fraser@boag.online · Github · LinkedIn