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

lsof arguments:

  • -n Avoids host names lookup (may result in faster performance)
  • -t Terse output; returns process IDs only to facilitate piping the output to kill
  • -i Selects only those files whose Internet address matches

kill arguments:

  • -9 Non-catchable, non-ignorable kill