Created
October 8, 2023 00:10
-
-
Save ryodeushii/1884095e6687ae8396e17dcde98d7e24 to your computer and use it in GitHub Desktop.
Kill process holding port provided by argument, defaults to port 80
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 | |
PORT=:${1:-80} | |
echo "Searching for process listening on port $PORT to kill..." | |
PROCESS_PID=$(lsof -ti $PORT) | |
if [$PROCESS_PID -eq ""] | |
then | |
echo "Process helding port $PORT not found, exit" | |
exit 0 | |
fi | |
echo "Found PID $PROCESS_PID, killing process" | |
kill -9 $PROCESS_PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment