End the process that's using a specific port.
#! /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 "$@" |
This comment has been minimized.
This comment has been minimized.
Nice. I didn't know about |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.