Skip to content

Commit

Permalink
Improve cleanup of processes that don't terminate.
Browse files Browse the repository at this point in the history
btest-bg-wait signaled btest-bg-run-helper processes to terminate in
the event of a timeout, but that did not always follow through with
making sure to kill off the actual process on which it was waiting.
  • Loading branch information
jsiwek committed Aug 15, 2013
1 parent be7c653 commit 793c7a7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions btest-bg-run-helper
Expand Up @@ -2,9 +2,23 @@
#
# Internal helper for btest-bg-run.

trap "kill 0" 0
cleanup ()
{
if [ ! -e .exitcode ]; then
echo 15 >.exitcode
kill 0 &>/dev/null

eval $@ &
if [ ! -z "$pid" ]; then
kill -0 $pid &>/dev/null && kill $pid
sleep 1
kill -0 $pid &>/dev/null && kill -9 $pid && echo 9 >.exitcode
fi
fi
}

trap "cleanup" EXIT

eval "$@ &"

pid=$!
echo $$ >.pid
Expand Down

0 comments on commit 793c7a7

Please sign in to comment.