Skip to content

Instantly share code, notes, and snippets.

@noahlt
Last active September 15, 2017 16:25
Show Gist options
  • Save noahlt/2662634 to your computer and use it in GitHub Desktop.
Save noahlt/2662634 to your computer and use it in GitHub Desktop.
killport - kill whatever process is running on a given port
# 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