Created
September 14, 2009 04:37
-
-
Save alecthegeek/186500 to your computer and use it in GitHub Desktop.
Kill a proccess identifed vy a string
This file contains 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/sh | |
# See http://partmaps.org/era/unix/award.html#uuk9letter | |
string="$1" ; export string | |
scriptname=`basename $0` ; export scriptname | |
kps=`ps -ef|nawk '$0 ~ ENVIRON["string"] && $0 !~ ENVIRON["scriptname"] {print $2}'` | |
echo $string has PID \"$kps\" | |
if test -z "$kps" ; then | |
echo "Cannot find process identified by $string" | |
exit 1 | |
fi | |
for i in 15 2 1 ; do | |
kill -$i $kps | |
sleep 10 | |
kps=`ps -ef|nawk '$0 ~ ENVIRON["string"] && $0 !~ ENVIRON["scriptname"] {print $2}'` | |
if test -z "$kps" ; then | |
echo Killed $string $kps with signal $i | |
exit 0 | |
fi | |
done | |
echo "Unable to kill $string, PID = $kps" | |
exit 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment