How to kill a process by port on MacOS, a la fuser -k 9000/tcp

lsof -P | grep ':PortNumber' | awk '{print $2}' | xargs kill -9

Change PortNumber to the actual port you want to search for.


Adding the -t and -i flags to lsof should speed it up even more by removing the need for grep and awk.

lsof -nti:NumberOfPort | xargs kill -9

Add -n to lsof and you remove the reverse DNS lookup from the command and reduce the run time from minutes to seconds.

lsof -Pn | grep ':NumberOfPort' | awk '{print $2}' | xargs kill -9