1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/scripts/ctest-background-kill.sh

68 lines
1.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
#
# $SAI_INSTANCE_IDX - which instance of sai, 0+
# $1 - background fixture name, unique within test space, like "multipostlocalsrv"
# $2 - executable
# $3+ - args
2021-01-25 06:26:10 +00:00
echo "$0 $1 $2 $3 $4"
J=`basename $2`.$1.$SAI_INSTANCE_IDX
PI=`cat /tmp/sai-ctest-$J`
#
2021-01-25 06:26:10 +00:00
# We expect our background process to initially still be around
#
2021-01-25 06:26:10 +00:00
kill -0 $PI
GONESKI=$?
2021-01-25 06:26:10 +00:00
echo "Background task $PI: $J"
2021-01-25 06:26:10 +00:00
if [ $GONESKI -eq 1 ] ; then
echo "Background Process $PI unexpectedly dead already, their log"
cat /tmp/ctest-background-$J
exit 1
fi
2021-01-25 06:26:10 +00:00
echo "Trying SIGTERM..."
2021-01-25 06:26:10 +00:00
kill $PI
2021-01-25 06:26:10 +00:00
#
# 100ms intervals, 100 = 10s
# need to allow time for valgrind case
#
BUDGET=100
while [ $BUDGET -ne 0 ] ; do
sleep 0.1
kill -0 $PI 2>&1
if [ $? -eq 1 ] ; then
echo "Went down OK"
exit 0
fi
2021-01-25 06:26:10 +00:00
BUDGET=$(( $BUDGET - 1 ))
done
2021-01-25 06:26:10 +00:00
echo "Trying SIGKILL..."
kill -9 $PI
#
# 100ms intervals, 100 = 10s
# need to allow time for valgrind case
#
BUDGET=20
while [ $BUDGET -ne 0 ] ; do
sleep 0.1
kill -0 $PI 2>&1
if [ $? -eq 1 ] ; then
echo "Went down OK after SIGKILL"
exit 0
fi
BUDGET=$(( $BUDGET - 1 ))
done
2021-01-25 06:26:10 +00:00
echo "Couldn't kill it"
exit 1