Vincent Lefevre <vincent-o...@vinc17.net> wrote:

> I wonder how the following script is supposed to behave.
>
> The POSIX spec seems ambiguous about SIGCHLD trap in a shell. It says:
> "[...] a signal specified using a symbolic name, without the SIG prefix,
> as listed in the tables of signal names in the <signal.h> header defined
> in XBD Headers"; there, SIGCHLD is listed as "Child process terminated,
> stopped, [XSI] or continued". From this spec, I would assume that the
> trap would be executed for any child process that terminates, stops, or
> continues. But this is not what I observe.
>
> Only bash, ksh93 and zsh document what happens concerning SIGCHLD traps.

Do you believe every shell should document SIGCHLD?
Wouldn't it be sufficient if SIGCHLD is handled the same way as other signals?


> Note: For practical reasons, I assume a sleep implementation with
> a floating-point number; this is the case with /bin/sleep under
> Debian (coreutils). It could be any external command with a similar
> behavior.
>
> ------------------------------------------------------------------------
> #!/bin/sh
>
> n=${1:-30}
> n=$((n+0))
>
> c=0
> trap 'c=$((c+1))' CHLD
>
> for i in `seq $n`; do /bin/sleep 0.1 & done
>
> while true
> do
>   echo $c
>   /bin/sleep 0.1
> done
> ------------------------------------------------------------------------
>
> I call this script with:
>
>   <shell> <script_name>
>
> Under Debian unstable:
>
> * With ash, dash, mksh and yash, I get:
>
> 1
> 2
> 3
> 4
> 5
> 6
> [...]
>
> and each time, $c is increased by 1.

Well, /bin/sleep 0.1 is definitely not portable, I used /bin/sleep 1
instead...

I get this behavor with:

        dash, bosh (the POSIXyfied Bourne Shell), mksh and yash.


zsh delivers:

0
9
30
30
30
30
^C

ksh88 delivers:
0
0
0
0
^C

ksh93 delivers:
0
1
2
2
2
2
2
^C

bash delivers:
0 
0 
0 
0 
^C 

zsh delivers:
0
7
30
30
^C

which looks similar to what ksh93 does.

> * With bash and posh, I get:
>
> 0
> 0
> [...]
>
> i.e. no trap executions at all.
>
> If I add "set -m", then bash behaves like ash, etc., except that it

bash -m script does not work for me...


>From my interpretation, only:

        dash, bosh (the POSIXyfied Bourne Shell), mksh and yash

and probably zsh

work as expected.

Jörg

-- 
 EMail:jo...@schily.net                    (home) Jörg Schilling D-13353 Berlin
    joerg.schill...@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
 URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'

Reply via email to