Skip to content

Instantly share code, notes, and snippets.

@snow-swallow
Last active December 12, 2015 05:28
Show Gist options
  • Save snow-swallow/4721669 to your computer and use it in GitHub Desktop.
Save snow-swallow/4721669 to your computer and use it in GitHub Desktop.
It's a shell for killing process by your port in osx. 1) sudo mv killps.sh /usr/local/bin ## enter your local environment. 2) chmod +x killps.shell 3) killps 9001 ## enter the process port you wanna kill.
#! /bin/sh
lsof -n -i4TCP:$1 | grep LISTEN
pid=`lsof -n -i4TCP:$1 | grep LISTEN | awk '{print $2}'`
## when it is ubuntu, just replace '4TCP' to '6TCP' in line3.
if [ $pid ]
then
kill -9 $pid
echo "[`date "+%Y-%m-%d %H:%M:%S"`] Process kill successfull!"
else
echo "[`date "+%Y-%m-%d %H:%M:%S"`] No process exists on port $1."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment