Skip to content

Commit 64a1462

Browse files
committed
Use process group to kill children instead of parent PIDs
Using the process group (now that we've got one that's exclusive to the testrunner) allows us to also clean up children that have been detached from their original parent (and now have PID 1 as their parent).
1 parent a215104 commit 64a1462

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

tests/testrunner.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,23 @@ function testrunner::signal_children()
228228
local child_pids=()
229229

230230
IFS=
231-
res=$(ps -o ppid,pid)
231+
res=$(ps -o pgid,ppid,pid)
232232
unset IFS
233233
{
234234
read -r # Skip header
235-
while IFS=' ' read -r ppid cpid; do
236-
test $ppid -eq $pid && child_pids+=($cpid)
235+
while IFS=' ' read -r pgid ppid cpid; do
236+
# Child processes
237+
#test $ppid -eq $pid && child_pids+=($cpid)
238+
# Process group children
239+
test $pgid -eq $pid && test $cpid -ne $pid && child_pids+=($cpid)
237240
done
238241
}<<<"$res"
239242

240-
local p
243+
IFS=$'\n' child_pids=($(sort --reverse <<<"${child_pids[*]}"))
244+
241245
for p in "${child_pids[@]}"; do
242-
testrunner::signal_children $signal $p
246+
#testrunner::signal_children $signal $p
247+
#echo "Signaling $p ($(ps -o pid=,command= $p)) $signal"
243248
kill -$signal $p >/dev/null 2>&1
244249
done
245250
}
@@ -299,7 +304,8 @@ for testsuite in "${testsuites[@]}"; do
299304
printf "tests_total+=${tests_total}; tests_failed+=${tests_failed}" >&3
300305
301306
# Clean up if test didn't do it
302-
testrunner::signal_children TERM
307+
testrunner::signal_children TERM $$
308+
testrunner::signal_children KILL $$
303309
)
304310
exec 4>&-
305311
if [[ $interrupted -eq 1 ]]; then

0 commit comments

Comments
 (0)