Finding Which Process is Locking a Port on macOS

How to find and kill a process using a specific port.

April 07, 2020 | Mike Buss

Occasionally, a process on my computer will open a port and refuse to release it. Here’s how to find the process and kill it.

lsof -i tcp:PORTNUMBER

For example, if I have a Rails server running in the background, I can run:

lsof -i tcp:3000 

To find the Rails process and its PID. To kill that process, I can then run:

kill -9 PIDNUMBER

Or, to combine searching for the process and killing it into one command:

kill -9 $(lsof -ti tcp:PORTNUMBER)

Previous Post

Connecting a Raspberry Pi, iPad, HoloLens, and Magic Leap ML1

I needed a way to connect and communicate between these devices in places with unreliable WiFi.

Next Post

No newer posts.


About the Author

Mike Buss is a software engineer from Ohio who works primarily in the healthcare space. His work has been featured on Apple.com and helped hundreds of thousands of patients. In his spare time, he writes about software development and more.


Follow @michaeltbuss on Twitter as he continues to document his software development journey.