[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Change in behaviour between 4.2.53 and 4.3 series

From: Dmitry Mikhin
Subject: Change in behaviour between 4.2.53 and 4.3 series
Date: Thu, 04 Jun 2015 15:25:13 +1000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

Hello everyone.

Lately we experienced some strange termination issues in our system. The problem was traced down to bash "wait" not waiting for process groups.

The original implementation has been done under bash 4.2 series, and apparently works there, but not under 4.3 variants that we tried.

I'm not sure if our approach is indeed correct, and any alternative suggestions for achieving the same goals in a compliant way are welcome.

To the problem: roughly, we want to start some software (a test instance, as an example) in a separate process group, and then terminate it all at once. Something along the lines:

timeout -s TERM 1000 our_server_script & script_pid=$!


later on:

kill -s TERM -- -$script_pid
wait $script_pid

The "kill" above sends the signal to the entire process group. In bash 4.2, the "wait" will not return until all processes in the given process group terminate. In bash 4.3, however, the wait returns immediately. (Termination in our case would take a few seconds, and the delay is visible. As some process in the group are still running, they corrupt data.)

A small test is attached. It reproduces the pattern above. The test builds a small C executable using gcc to trace and report the signals received. The test checks for the last line of output from running main.sh script. It is a race condition, so, has to be run a few times. On Ubuntu 14.04 (bash --version gives "GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)"), the test produces something like:
$ ( for i in $( seq 10 ) ; do ./test ; done ) | sort -u
last="./baz.sh: finally exiting"
last="./foo.sh: finally exiting"
last="main terminated"

On the same system with a custom old version of bash (bash --version gives "GNU bash, version 4.2.53(1)-release (x86_64-unknown-linux-gnu)"): $ ( export PATH="$HOME/usr/bash-4.2.53/bin:$PATH"; for i in $( seq 10 ) ; do ./test ; done ) | sort -u
last="main terminated"

I.e., in the older bash the last line is always from the main, i.e., the wait indeed waited until all subprocesses are over, while on 4.3 some of the processes in the group return after the wait completed. The 4.2 behaviour checked for 10000 repetitions of the test, and seems to be always the same.


1. are our expectations for waiting for the entire process group correct? If not, is this a bug in 4.3?

2. if our expectations are wrong, what would be the recommended ways to achieve the same effect, i.e., wait for the process group to complete?

Best regards,
Dmitry Mikhin

Attachment: test.04.tar.gz
Description: application/gzip

reply via email to

[Prev in Thread] Current Thread [Next in Thread]