bug-bash
[Top][All Lists]
Advanced

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

Re: wait -n shouldn't collect multiple processes


From: Chet Ramey
Subject: Re: wait -n shouldn't collect multiple processes
Date: Sat, 23 Mar 2019 11:48:33 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.0

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



reply via email to

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