Last active
July 26, 2023 17:27
-
-
Save johnhunter/bbc88d5d5424bc719f109fd71995a21c to your computer and use it in GitHub Desktop.
Kill node processes bound to a specific port (MacOS)
This file contains hidden or 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
#!/bin/bash | |
touch temp.text | |
lsof -n -i4TCP:$1 | awk '{print $2}' >temp.text | |
pidToStop=$( (sed '2q;d' temp.text)) | |
>temp.text | |
if [[ -n $pidToStop ]]; then | |
kill -9 $pidToStop | |
echo "Killed process $pidToStop running on port $1." | |
else | |
echo "Sorry nothing running on port $1" | |
fi | |
rm temp.text |
Will probably have to sudo to create the file, and sudo chmod a+x killnode
to make it executable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usr/local/bin/
killnode 3000