Down Boy! (Kill processes by Port)
F1LT3R

F1LT3R @f1lt3r

About: My social credit score is net zero 🎯 100% of my CO2 emissions are chlorophyll 🌿 I fart pure oxygen 🫧 & generate free electricity ⚡ from old dirt.

Location:
Boston, USA
Joined:
Nov 25, 2018

Down Boy! (Kill processes by Port)

Publish Date: May 10 '19
8 2

Need to kill processes by port? Try this...

Cute dog

Setup

Save this bash script as downboy to your bin directory:

#!/bin/bash
for PORT in $@
do
    PID=$(lsof -i :$PORT | awk 'FNR ==2 {print $2}')
    echo "kill -9 $PID"
    kill -9 $PID
done
Enter fullscreen mode Exit fullscreen mode

Make downboy executable:

chmod +X ./downboy
Enter fullscreen mode Exit fullscreen mode

Usage

Now you can easily close any number of processes by their port:

sudo downboy 80 8080 3000
Enter fullscreen mode Exit fullscreen mode

Bye-bye.

Comments 2 total

  • Mark Lennox
    Mark LennoxMay 10, 2019

    Will save a lot of ps -ef | grep on my machine - I needed this, thanks!

  • Thomas H Jones II
    Thomas H Jones IIMay 10, 2019

    Back in the mists of time, I recall that either the IRIX or Solaris implementation of fuser had the ability to kill processes by port.

Add comment