Last active
December 7, 2018 17:18
-
-
Save spadin/cb3efe5b724b9e1846fbec11e8b1cb24 to your computer and use it in GitHub Desktop.
End the process that's using a specific 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
#! /usr/bin/env bash | |
function kill-port () { | |
local length=$(($#-1)) | |
local killargs=( "${@:1:$length}" ) | |
shift $(($# - 1)) | |
local port=$1 | |
local pid | |
pid=$(lsof -t -i :"$port") | |
if [ "$pid" = "" ]; then | |
echo "Port $port isn't being used." | |
exit 0; | |
fi | |
kill "${killargs[@]}" "$pid" | |
echo "PID $pid, matching port $port was terminated." | |
} | |
kill-port "$@" |
soulcutter
commented
Dec 6, 2018
•
Nice. I didn't know about shellcheck
. Found kill-port -s KILL 1234
wasn't working, but it is now. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment