macOS – fuser -k Analogue

bashmacos

I want to kill process that runs at some port. In ubuntu I used fuser -k 8000/tcp. What is the Mac OS way?

I found out this way:

lsof -i tcp:8000
kill -9

But it's very long. I need one short command like fuser

Thanx

Best Answer

Save this in some file that is in your PATH, call it kill-server for example. Make sure to chmod +x on it.

#! /bin/bash

lsof -i tcp:8000 | grep -v PID | awk '{print $2}' | xargs kill

Then invoke it with kill-server or whatever you decided to call it. This is about as short as it gets.