Bash Version: 3.1
Patch Level: 17
Release Status: release
Description:
According to POSIX.1 (both 2004 <http://www.opengroup.org/onlinepubs/009695399/utilities/wait.html>
and 2008 <http://www.opengroup.org/onlinepubs/9699919799/utilities/wait.html> versions),
the "wait" command should wait until the process TERMINATES.
(The exact wording is "If one or more pid operands are specified
that represent known process IDs, the wait utility shall wait
until all of them have terminated.")
The POSIX.1 standard also describes the "-o monitor" option, and
mentions nothing about it having any effect on the "wait" utility.
But in bash, if the "-o monitor" option is set, the wait command
finishes when the named process CHANGES STATUS, e.g. due to SIGSTOP
or SIGCONT, rather than until it TERMINATES.
In other words, when "-o monitor" is set, the observed behaviour
of the wait command is like using the WUNTRACED and WCONTINUED
options to waitpid(), whereas the wait command ought to behave
like waitpid() _without_ those options.
Repeat-By:
#!/bin/bash
set -o monitor
sleep 5 &
child1=$!
(sleep 1; kill -STOP $child1; sleep 1; kill -CONT $child1) &
child2=$!
wait $child1
if [ $? == 147 ]; then
echo "TEST FAILED: wait returned 147 (=128+SIGSTOP)" >&2
wait $child2
exit 1
else
echo "TEST PASSED"
fi
This wait command should wait until the sleep process terminates, and then report its status
as successful (0), so the script ought to print out "TEST PASSED". But instead the wait
command terminates as soon as the sleep process gets the SIGSTOP signal, and returns 147
(i.e. 128 + SIGSTOP), so the test prints out "TEST FAILED".
Exactly, having the same problem here.
Charles