• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# $SAI_INSTANCE_IDX - which instance of sai, 0+
4# $1  - background fixture name, unique within test space, like "multipostlocalsrv"
5# $2  - executable
6# $3+ - args
7
8echo "$0 $1 $2 $3 $4"
9
10J=`basename $2`.$1.$SAI_INSTANCE_IDX
11PI=`cat /tmp/sai-ctest-$J`
12
13#
14# We expect our background process to initially still be around
15#
16
17kill -0 $PI
18GONESKI=$?
19
20echo "Background task $PI: $J"
21
22if [ $GONESKI -eq 1 ] ; then
23	echo "Background Process $PI unexpectedly dead already, their log"
24	cat /tmp/ctest-background-$J
25	exit 1
26fi
27
28echo "Trying SIGTERM..."
29
30kill $PI
31
32#
33# 100ms intervals, 100 = 10s
34# need to allow time for valgrind case
35#
36BUDGET=100
37while [ $BUDGET -ne 0 ] ; do
38	sleep 0.1
39	kill -0 $PI 2>&1
40	if [ $? -eq 1 ] ; then
41		echo "Went down OK"
42		exit 0
43	fi
44	BUDGET=$(( $BUDGET - 1 ))
45done
46
47echo "Trying SIGKILL..."
48
49kill -9 $PI
50
51#
52# 100ms intervals, 100 = 10s
53# need to allow time for valgrind case
54#
55BUDGET=20
56while [ $BUDGET -ne 0 ] ; do
57	sleep 0.1
58	kill -0 $PI 2>&1
59	if [ $? -eq 1 ] ; then
60		echo "Went down OK after SIGKILL"
61		exit 0
62	fi
63	BUDGET=$(( $BUDGET - 1 ))
64done
65
66echo "Couldn't kill it"
67exit 1
68