Skip to content

Instantly share code, notes, and snippets.

@antoniopresto
Last active May 25, 2021 12:14
Show Gist options
  • Save antoniopresto/1244b50833bebc8018e3061829d79d62 to your computer and use it in GitHub Desktop.
Save antoniopresto/1244b50833bebc8018e3061829d79d62 to your computer and use it in GitHub Desktop.
Kill process
# kp 3000 node # kill if node is running on port 3000
# kp 3000 # kill process running on port 3000
PORT=$1;
MATCH=$2;
if [ -n "$MATCH" ]; then
kill -9 `lsof -i :$PORT | awk -v MATCH=$2 '$0 ~ MATCH{ print $2; }'`
exit;
fi;
kill -9 `lsof -i :$PORT | awk '{ if($2 != "PID"){ print $2; }}' `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment