Created
February 15, 2021 22:49
-
-
Save jeffypooo/34ab94e4b2de93170baf16a39d7e687b to your computer and use it in GitHub Desktop.
Kill a process using a port
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
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