On 2017-04-27 08:45:37 +0700, Robert Elz wrote:
> ps: the seq command in your example cannot (properly) have caused the
> SIGCHLD that you (think you) counted,

Well, I assume that this depends on the shell. But for most shells (if
not all in practice), it is the seq command that causes the SIGCHLD.

> as it is running in a sub-shell, and traps get reset there (and even
> if they didn't, that would update a different copy of the counter
> 'c')

In most shells, the subshell is replaced by the seq command with just
an execve, since it is the last command and there are no traps in the
subshell. I suppose that this is not forbidden by POSIX, i.e. with the
following example, getting the same value twice is not forbidden.

echo `sh -c 'echo $PPID'; sh -c 'echo $$'`

> You can see that background processes do generate SIGCHLD with a
> script like...
> c=0
> trap 'c=$((c + 1))' CHLD
> while [ $c -lt 3 ]; do
>         echo $c
>         read junk
>         sleep 0.5 &
> done

OK, I confirm.

Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to