Skip to content

Instantly share code, notes, and snippets.

@andrewriveradev
Last active March 16, 2023 03:08
Show Gist options
  • Save andrewriveradev/6fa70a3fb9247c47c6d1f413d3014047 to your computer and use it in GitHub Desktop.
Save andrewriveradev/6fa70a3fb9247c47c6d1f413d3014047 to your computer and use it in GitHub Desktop.
killport.sh
#!/bin/bash
# Context:
# - add killport.sh to path export PATH="$HOME/bin:$PATH" assuming $HOME/bin is where you keep your scripts
# - make killport.sh executable chmod +x killport.sh
# write the command to kill the process running on the port
kill -9 $(lsof -t -i:$1)
# write command to notify the user that the process has been killed or not
if [ $? -eq 0 ]
then
echo "Process running on port $port has been killed"
else
echo "No process running on port $port"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment