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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/