On 02/10/2013 08:30 PM, Chet Ramey wrote:
On 2/9/13 12:02 AM, Pádraig Brady wrote:
$ rpm -q kernel glibc bash
kernel-2.6.40.4-5.fc15.x86_64
glibc-2.14.1-6.x86_64
bash-4.2.10-4.fc15.x86_64
I notice the following will wait for 5 seconds for
the timeout process to end with SIGALRM, rather than
immediately due to kill sending the SIGTERM.
I'll take a look at making the race window smaller; there is probably
some code reordering that will have a beneficial effect.
This race exists, to a certain extent, in all Bourne-like shells. This
problem only happens when run interactively, and it happens because
interactive shells ignore SIGTERM. No matter how quickly you modify a
child's signal handlers after fork() returns, there's always the chance
that a kernel's scheduling policies or aome global auto-nice of child
or background processes will cause it to happen.
You might be able to do something like:
sigprocmask(sigterm_block); // ensure parent shell doesn't get TERM
signal (SIGTERM, SIG_DFL); // reset to default for child to inherit
fork();
signal (SIGTERM, SIG_IGN); // continue to ignore TERM
sigprocmask(sigterm_unblock); // reset
cheers,
Pádraig.