bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "wait" loses signals


From: Chet Ramey
Subject: Re: "wait" loses signals
Date: Thu, 20 Feb 2020 10:27:41 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/20/20 3:02 AM, Denys Vlasenko wrote:
> On 2/19/20 9:30 PM, Chet Ramey wrote:
>> On 2/19/20 5:29 AM, Denys Vlasenko wrote:
>>> 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.
>>
>> This strikes me as a shaky assumption, dependent on when the shell receives
>> the SIGTERM and when it runs traps.
> 
> The undisputable fact is that after shell forks a child
> to run the "{...} &" subshell, it will receive the SIGTERM signal.
> 
> And since it has a trap for it, it should be run.
> 
>> (There's nothing in POSIX that says
>> when pending traps are processed. Bash runs them after commands.)
> 
> Yes, and here we are "after command", specifically after "{...} &" command.
> Since we got a trapped signal, we must run its trap.

Did you look at the scenario in my message?

Keep in mind that you can't run the trap out of the signal handler.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]