Last active
January 23, 2021 00:37
-
-
Save dillonhafer/d5a8c221ed4764b6b9c1b365a56d7c9c 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
function freethousand() { | |
port="${1:-3000}" | |
death_level="${2:-SIGINT}" | |
programs=$(lsof -i tcp:$port | grep "[0-9]" | awk '{print $2" "$1 }' | uniq) | |
if [ -z "$programs" ]; then | |
echo "No processes running on port $port" | |
return | |
fi | |
TMPFILE=$(mktemp) | |
options=$(echo "$programs" | wc -l) | |
dialog --menu "Kill($death_level) processes running on $port:" 15 50 $options $programs 2>$TMPFILE | |
pid=$(cat $TMPFILE) | |
rm $TMPFILE | |
if [ -z "$pid" ]; then | |
return | |
else | |
kill -$death_level $pid | |
fi | |
} |
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
function freethousand() { | |
port="${1:-3000}" | |
death_method="${2:-SIGINT}" | |
echo "Processes running on port $port" | |
PS3="Select process: " | |
programs=$(lsof -i tcp:$port | grep "[0-9]" | awk '{print $1"-"$2 }' | uniq) | |
if [ -z "$programs" ]; then | |
echo "No processes running on port $port" | |
fi | |
select pro in $programs | |
do | |
pid=$(echo "${pro//-/ }" | awk '{print $2}') | |
if [ -z "$pid" ]; then | |
echo "You did not make a selection" | |
else | |
echo "kill -$death_method $pid" | |
kill -$death_method $pid | |
fi | |
break | |
done | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment