On 4/25/17 9:15 PM, Vincent Lefevre wrote: > On 2017-04-25 23:49:56 +0200, Jilles Tjoelker wrote: >> On Tue, Apr 25, 2017 at 03:21:24PM +0200, Vincent Lefevre 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. >> >> I would not assume that. Since trap actions are not executed while >> waiting for a foreground process to exit, it is likely that multiple >> instances of SIGCHLD will be coalesced into a single trap action >> execution. > > IMHO, this would be a bug. A shell should be able to know when all > its children have terminated. IMHO, all the pending traps should > be executed before the next command.
There is no requirement that a trap be executed each time a particular signal is generated. There is no requirement that the system keep a count of instances of a particular pending signal; only that the signal is pending. SIGCHLD isn't different from any other signal in this regard. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/