Skip to content

Instantly share code, notes, and snippets.

@hyperh
Last active May 28, 2020 15:58
Show Gist options
  • Save hyperh/248156d4b2c5a7a4b3e1e251f6cfddba to your computer and use it in GitHub Desktop.
Save hyperh/248156d4b2c5a7a4b3e1e251f6cfddba to your computer and use it in GitHub Desktop.
#!/bin/bash
# Kills processes located at specific ports
# killport 8000
# killport 8001 8001
for port in "$@"
do
# Echoes pid of process at port
pid=$(lsof -t -i:$port)
# $? = exit status of last command, 0 = success, 1 = failure
if [ "$?" = "0" ]; then
kill $pid
echo "Killed process $pid at port $1 🎉"
else
echo "No process found at port $1 👎"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment