bug-bash
[Top][All Lists]
Advanced

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

Re: `wait -n` returns 127 when it shouldn't


From: Chet Ramey
Subject: Re: `wait -n` returns 127 when it shouldn't
Date: Wed, 17 May 2023 12:13:07 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0

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




reply via email to

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