Last active
May 28, 2020 15:58
-
-
Save hyperh/248156d4b2c5a7a4b3e1e251f6cfddba to your computer and use it in GitHub Desktop.
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
#!/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