Skip to content

Instantly share code, notes, and snippets.

@ryodeushii
Created October 8, 2023 00:10
Show Gist options
  • Save ryodeushii/1884095e6687ae8396e17dcde98d7e24 to your computer and use it in GitHub Desktop.
Save ryodeushii/1884095e6687ae8396e17dcde98d7e24 to your computer and use it in GitHub Desktop.
Kill process holding port provided by argument, defaults to port 80
#!/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