A bug report from Harald van Dijk:
test2.sh:
trap 'kill $!; exit' TERM
{ kill $$; exec sleep 9; } &
wait $!
The above script ought exit quickly, and not leave a stray
"sleep" child:
(1) if "kill $$" signal is delivered before "wait",
then TERM trap will kill the child, and exit.
(2) if "kill $$" signal is delivered to "wait",
it must be interrupted by the signal,
then TERM trap will kill the child, and exit.
The helper to loop the above:
test1.sh:
i=1
while test "$i" -lt 100000; do
echo "$i"
"$@" test2.sh
i=$((i + 1))
done
To run: sh test1.sh <shell_to_test>
bash 4.4.23 fails pretty quickly:
$ sh test1.sh bash
1
...
581
_ <stops here for ~9 seconds>
Under strace, it seems that "wait" enters wait4() syscall
and waits for the child. (The fact that the pause is
9 seconds is another hint).