Go to content
Blog / Tools /

How to kill a process by port on MacOS

Every now and then I find myself in need to kill a process, knowing only the port it’s using.

Below you can read the magic spell to kill a process in Unix-like system, running on a specific port.

lsof -nti:<PORT> | xargs kill -9

Copy, and replace <PORT> with the port number.

Kill a process programatically

There are numerous npm modules that allow to kill a process programatically; fkill is my favorite.