-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkms_functions
25 lines (23 loc) · 956 Bytes
/
kms_functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function killmesoftly {
PID=$1
echo -n "Now sending SIGTERM to PID ${PID}... "
kill ${PID}
[ 0 -ne "$?" ] && { echo "Could not kill process. You are probably not allowed to perform the operation"; exit 3; }
# wait 15 seconds by default between SIGTERM and SIGKILL and between SIGKILL and abandon the operation.
COUNT=0
SIGKILL_SENT=1
while kill -0 "${PID}" &>/dev/null; do
sleep 0.2
COUNT=$((COUNT+1))
[ "${COUNT}" -gt 150 ] && SIGKILL_SENT && { echo "Could not stop. Probably stuck in kernel call. Abandoning the whole kill chain."; exit 2; }
[ "${COUNT}" -gt 75 ] && { echo -n "didn't terminate, sending SIGKILL... "; kill -9 ${PID}; COUNT=0; SIGKILL_SENT=0; }
done
echo "killed successfully"
}
# return 0 if a PID exists, 1 in any other case (regardless of ps exit code)
function checkPsExists {
PID=$1
ps -p ${PID} >/dev/null
[ 0 -eq $? ] && return 0
return 1
}