Created
July 7, 2020 03:16
-
-
Save hackerzgz/b1317317d38429ce0d72e660e5d1584c to your computer and use it in GitHub Desktop.
kill a process gracefully
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/sh | |
pid=$1 | |
count=$2 | |
n=0 | |
if [ ! -n $count ];then | |
count=10 | |
fi | |
while [[ $n -lt $count ]] | |
do | |
let "n++" | |
kill -0 $pid | |
if [ $? -ne 0 ] | |
then | |
echo "program not exist" | |
break | |
else | |
echo "send kill -15 to $pid" | |
kill -15 $pid | |
sleep 1 | |
fi | |
if [[ $n -eq $count ]] | |
then | |
echo "kill -9 $pid" | |
# after 10s , try to send kill -9 | |
kill -9 $pid | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment