Skip to content

Instantly share code, notes, and snippets.

@loranbriggs
Created December 16, 2015 19:51
Show Gist options
  • Save loranbriggs/90998f9f46f38281fdeb to your computer and use it in GitHub Desktop.
Save loranbriggs/90998f9f46f38281fdeb to your computer and use it in GitHub Desktop.
#!/bin/bash
PORT=$1
if ! [[ "$PORT" =~ ^[0-9]+$ ]] ;
then
printf "error: '$PORT' is not a number.\n\nUsage killport <port number>\n"
exit 1
fi
PID=$(lsof -ti:$PORT)
if ! [[ "$PID" =~ ^[0-9]+$ ]] ;
then
printf "no proccess found, nothing to kill.\n"
exit 0
fi
printf "killing process $PID running on $PORT\n"
kill -9 $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment