Last active
January 29, 2024 00:05
-
-
Save evakdev/1b2aacef5bbf6c5a9c25a2fabc73fdc4 to your computer and use it in GitHub Desktop.
Find processes using a port and kill them
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
killport() { | |
if [ $# -ne 1 ]; then | |
echo "Missing port number: killport <port_number>" | |
return 1 | |
fi | |
local processes="$(sudo lsof -ti:$1)" | |
if [ -z "$processes" ]; then | |
echo "No process found for port $1" | |
return 1 | |
fi | |
echo "$processes" | xargs sudo kill -9 | |
echo "Killed process(es) bound to port $1" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment