On 5/16/23 1:35 PM, Aleksey Covacevice wrote:

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:
`wait -n` sometimes returns with status code 127 even though there are
unwaited-for children.

There are not. That's why `wait -n' returns 127.


Repeat-By:
The following script does finish after a while:

waitjobs() {
     local status=0
     while true; do
     local code=0; wait -n || code=$?
         ((code == 127)) && break
         ((!code)) || status=$code
     done
     return $status
}

# Eventually finishes:
while true; do (
     true &
     false &
     waitjobs
) && break; done

It's possible for the shell to reap both background jobs before `wait -n'
is called. The underlying function returns < 0 when there aren't any
unwaited-for jobs, which the wait builtin translates to 127.

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