From 64a1462dfb6df4ad0bdfd15e31f2ffaa2985303f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 18 Sep 2018 00:23:37 +0200 Subject: [PATCH] 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). --- tests/testrunner.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/testrunner.sh b/tests/testrunner.sh index b1da0fe..afaf8b1 100755 --- a/tests/testrunner.sh +++ b/tests/testrunner.sh @@ -228,18 +228,23 @@ function testrunner::signal_children() local child_pids=() IFS= - res=$(ps -o ppid,pid) + res=$(ps -o pgid,ppid,pid) unset IFS { read -r # Skip header - while IFS=' ' read -r ppid cpid; do - test $ppid -eq $pid && child_pids+=($cpid) + while IFS=' ' read -r pgid ppid cpid; do + # Child processes + #test $ppid -eq $pid && child_pids+=($cpid) + # Process group children + test $pgid -eq $pid && test $cpid -ne $pid && child_pids+=($cpid) done }<<<"$res" - local p + IFS=$'\n' child_pids=($(sort --reverse <<<"${child_pids[*]}")) + for p in "${child_pids[@]}"; do - testrunner::signal_children $signal $p + #testrunner::signal_children $signal $p + #echo "Signaling $p ($(ps -o pid=,command= $p)) $signal" kill -$signal $p >/dev/null 2>&1 done } @@ -299,7 +304,8 @@ for testsuite in "${testsuites[@]}"; do printf "tests_total+=${tests_total}; tests_failed+=${tests_failed}" >&3 # Clean up if test didn't do it - testrunner::signal_children TERM + testrunner::signal_children TERM $$ + testrunner::signal_children KILL $$ ) exec 4>&- if [[ $interrupted -eq 1 ]]; then