bug-bash
[Top][All Lists]
Advanced

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

Re: Possible race condition in bash


From: Chet Ramey
Subject: Re: Possible race condition in bash
Date: Sat, 21 Nov 2020 13:09:22 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.4.3

On 11/21/20 3:06 AM, Nikolay Borisov wrote:

> The output is:
> 
> my pid 12186
> 12186 subfun xxx 0
> funpid=12186 twopid=12187 mypid=12185
> killing 12186 12187
> waiting on everything
> my pid 12187
> 12187 subfun yyy 0
> received term for xxx
> 12187 subfun yyy 1
> 12187 subfun yyy 2
> 12187 subfun yyy 3
> 
> 
> and 12187 keeps printing. It would seem there $! can return a pid of the
> subshell before it's in a state that it can be killed. 

This is a potential race condition, but it's not with the shell. The
parent shell sets $! as soon as the child pid returns from fork(), and
that doesn't have anything to do with when the child gets scheduled or
runs. You might have better luck running this under strace or truss and
seeing what happens with the timing: whether the child sets SIGTERM to
the trap handler before the signal arrives, or whether the child resets
the SIGTERM handler to what the parent had before the trap before the
signal arrives.


-- 
``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]