Last active
September 15, 2017 16:25
-
-
Save noahlt/2662634 to your computer and use it in GitHub Desktop.
killport - kill whatever process is running on a given port
This file contains 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
# add this to your .bash_profile to use it | |
# source: https://gist.github.com/noahlt/2662634 | |
function killport { | |
if [ ! -n "$1" ] || [ $1 == '--help' ] || [ $1 == '-h' ] | |
then | |
echo '`killport <PORT>` finds the process listening to the specified port and kills it.' | |
else | |
process_line=`sudo lsof -i :$1 | tail -1` | |
if [ "$process_line" == "" ] | |
then | |
echo "no processes listening on $1" | |
else | |
process_name=`echo "$process_line" | awk '{print $1}'` | |
echo "killing $process_name" | |
sudo kill `echo "$process_line" | awk '{print $2}'` | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment