Created
December 16, 2015 19:51
-
-
Save loranbriggs/90998f9f46f38281fdeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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