Skip to content

Instantly share code, notes, and snippets.

@fewstera
Last active May 10, 2018 10:21
Show Gist options
  • Save fewstera/0500e5c041420f55577d6b5a9c8d486c to your computer and use it in GitHub Desktop.
Save fewstera/0500e5c041420f55577d6b5a9c8d486c to your computer and use it in GitHub Desktop.
Shell function to kill process running on port
# Taken from https://github.com/kevinSuttle/dotfiles/commit/9458141f40094d96952adc7c423cbdddeb909a81#diff-0eaa46c12c8190dcb4e4b46838220683
# Usage: `kill-port 8080` to kill the process running on port 8080
kill-port() {
if [ -z "$1" ]; then
echo "Usage: kill-port [port number]" >&2
return 1
fi
lsof -i TCP:$1 | awk '/LISTEN/{print $2}' | xargs kill -9
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment