Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
Created February 15, 2021 22:49
Show Gist options
  • Save jeffypooo/34ab94e4b2de93170baf16a39d7e687b to your computer and use it in GitHub Desktop.
Save jeffypooo/34ab94e4b2de93170baf16a39d7e687b to your computer and use it in GitHub Desktop.
Kill a process using a port
function kill_process_using_port() {
echo "attempting to kill process on port $1"
PID=$(lsof -t -i ":${1}")
if [ -z "${PID}" ]; then
echo "no process found using port ${1}"
return 1
fi
echo "killing pid ${PID}"
kill -9 "${PID}"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment