Skip to content

Instantly share code, notes, and snippets.

@pacozaa
Created May 10, 2021 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacozaa/f53a3a6a21b8266591b3291bd55723e3 to your computer and use it in GitHub Desktop.
Save pacozaa/f53a3a6a21b8266591b3291bd55723e3 to your computer and use it in GitHub Desktop.
findAndKillPort.sh
#!/bin/bash
read -p "Enter port number(ex. 7070): " PORT_NUMBER
echo "Here is $PORT_NUMBER"
if [ "$PORT_NUMBER" = "" ]; then
echo "No port number to target"
exit 0
fi
echo "Finding $PORT_NUMBER .... PID"
PID_FINDING=$(sudo lsof -iTCP -sTCP:LISTEN -n -P | grep $PORT_NUMBER)
echo $PID_FINDING
read -p "What's PID do you want to kill?: " PID_TARGET
if [ "$PID_TARGET" = "" ]; then
echo "No PID to target"
exit 0
else
echo "Killing $PID_TARGET"
kill -9 $PID_TARGET
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment