bug-bash
[Top][All Lists]
Advanced

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

Re: jobs race condition


From: Chet Ramey
Subject: Re: jobs race condition
Date: Mon, 16 May 2016 20:50:53 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.0

On 5/16/16 7:16 PM, Grisha Levit wrote:
> I would expect the following loop to exit after one (or maybe two)
> iterations but it runs until PIDs get recycled:
> 
> |$ : & while [[ $(jobs) ]]; do :; done [1] 61589 TRACE: pid 51259:
> delete_old_job: found pid 61589 in job 0 with state 4 |
> 
> The loop does not terminate because |jobs| just keeps printing |[1]+ Done :|.

It's not a race condition.  Since you're running an interactive shell,
jobs don't get removed from the jobs table until the user is notified
by the interactive shell.  That never happens, since it happens before
the next prompt is printed.

The subshell started to run the command substitution inherits the jobs
list (special cased; so you can do joblist=$(jobs)), so all the command
substitutions get the same list.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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