On 3/23/19 1:33 AM, Ben Elliston wrote:
> In bash 4.4.19, wait -n will collect the exit status of multiple
> processes if there are any -- not just one:

Yes. It waits for the next process to exit and then reaps all exited
children.

> 
> bje@bapbop:~$ sleep 10 & sleep 10 & sleep 10 & sleep 10 &
> [1] 13296
> [2] 13297
> [3] 13298
> [4] 13299
> bje@bapbop:~$ wait -n
> [1]   Done                    sleep 10
> [2]   Done                    sleep 10
> [3]-  Done                    sleep 10
> [4]+  Done                    sleep 10
> 
> This makes it impossible to wait for the completion of any process and> then 
> individually collect the exit status of each command.

If you want to associated an exit status with a process, changing wait -n
wouldn't make a difference.

> I think
> wait -n should be guaranteed to only return one of the available
> (terminated) processes. If there are multiple, they can be collected
> by calling wait -n multiple times or calling wait without '-n'.

What's your goal here? If you want to associate an exit status with a
process, you're going to have to save $! and wait for each process in
turn.


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

Reply via email to