Skip to content

Instantly share code, notes, and snippets.

@tysonwolker
Last active November 18, 2015 04:10
Show Gist options
  • Save tysonwolker/0aa9d2ae75ef6b5afb01 to your computer and use it in GitHub Desktop.
Save tysonwolker/0aa9d2ae75ef6b5afb01 to your computer and use it in GitHub Desktop.
Kill process by port
zmodload zsh/zutil
zparseopts -A ARGUMENTS -p:
PORT=$ARGUMENTS[--p]
processToKill=$(lsof -n -i4TCP:$PORT | grep LISTEN | awk '{print $2}')
if [ -n "$processToKill" ]; then
kill $processToKill
printf 'Killed port: "%s"\n' "$PORT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment