File: ctest-background-kill.sh

package info (click to toggle)
libwebsockets 4.3.5-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 31,404 kB
  • sloc: ansic: 194,409; javascript: 1,550; sh: 1,387; cpp: 505; java: 461; perl: 405; xml: 118; makefile: 76; awk: 5
file content (67 lines) | stat: -rwxr-xr-x 1,116 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# $SAI_INSTANCE_IDX - which instance of sai, 0+
# $1  - background fixture name, unique within test space, like "multipostlocalsrv"
# $2  - executable
# $3+ - args

echo "$0 $1 $2 $3 $4"

J=`basename $2`.$1.$SAI_INSTANCE_IDX
PI=`cat /tmp/sai-ctest-$J`

#
# We expect our background process to initially still be around
#

kill -0 $PI
GONESKI=$?

echo "Background task $PI: $J"

if [ $GONESKI -eq 1 ] ; then
	echo "Background Process $PI unexpectedly dead already, their log"
	cat /tmp/ctest-background-$J
	exit 1
fi

echo "Trying SIGTERM..."

kill $PI

#
# 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
	BUDGET=$(( $BUDGET - 1 ))
done

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

echo "Couldn't kill it"
exit 1