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

2023-05-22 Thread Robert Elz
Date:Mon, 22 May 2023 02:43:18 -0300 From:Aleksey Covacevice Message-ID: | I fail to see where the race condition in `true & wait -n` is. It wasn't in the script - but in the implementation inside bash. Chet has (apparently, I don't look at bash sources, and

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

2023-05-22 Thread alex xmb ratchev
On Mon, May 22, 2023, 07:43 Aleksey Covacevice wrote: > On Thu, May 18, 2023 at 3:07 PM Chet Ramey wrote: > > > > On 5/18/23 7:51 AM, Robert Elz wrote: > > > > > Apparently, in bash, if the code is running in a (shell) loop (like > inside > > > a while, or similar, loop) then each iteration

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

2023-05-21 Thread Aleksey Covacevice
On Thu, May 18, 2023 at 3:07 PM Chet Ramey wrote: > > On 5/18/23 7:51 AM, Robert Elz wrote: > > > Apparently, in bash, if the code is running in a (shell) loop (like inside > > a while, or similar, loop) then each iteration around the loop, any jobs > > that > > have exited, but not been cleaned

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

2023-05-19 Thread Chet Ramey
On 5/19/23 6:24 AM, Robert Elz wrote: Date:Thu, 18 May 2023 14:07:32 -0400 From:Chet Ramey Message-ID: | This isn't a problem, and is a red herring. The code that manages that list | makes sure to keep as many jobs in the list as POSIX requires, subject

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

2023-05-19 Thread Robert Elz
Date:Thu, 18 May 2023 14:07:32 -0400 From:Chet Ramey Message-ID: | This isn't a problem, and is a red herring. The code that manages that list | makes sure to keep as many jobs in the list as POSIX requires, subject to | the maxchild resource limit. That is

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

2023-05-18 Thread Chet Ramey
On 5/18/23 7:51 AM, Robert Elz wrote: Apparently, in bash, if the code is running in a (shell) loop (like inside a while, or similar, loop) then each iteration around the loop, any jobs that have exited, but not been cleaned already, are removed from the queue (the jobs table in practice,

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

2023-05-18 Thread Chet Ramey
On 5/18/23 12:16 AM, Martin D Kealey wrote: If there is silent reaping going on (other than “wait -n” or “trap ... SIGCHLD”) shouldn't the exit status and pid of each silently reaped process be retained in a queue that “wait -n“ can extract from, in order to maintain the reasonable expected

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

2023-05-18 Thread Robert Elz
Date:Thu, 18 May 2023 07:35:35 -0400 From:Greg Wooledge Message-ID: | I'm fairly sure most (or all?) shells do this, not just bash. Interactive shells are "different" from those running a script in this regard. kre

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

2023-05-18 Thread Robert Elz
Date:Thu, 18 May 2023 14:16:17 +1000 From:Martin D Kealey Message-ID: | I know that some platforms (used to?) lack all of the “waitpid()”, This is irrelevant to the issue at hand (and in general, for shells, is irrelevant anyway, as shells usually always

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

2023-05-18 Thread Greg Wooledge
On Thu, May 18, 2023 at 02:16:17PM +1000, Martin D Kealey wrote: > If there is silent reaping going on (other than “wait -n” or “trap ... > SIGCHLD”) [...] Yes, bash silently reaps child processes. unicorn:~$ tty /dev/pts/2 unicorn:~$ sleep 5 & sleep 7 & [1] 942813 [2] 942814 unicorn:~$ tty

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

2023-05-17 Thread Martin D Kealey
On Thu, 18 May 2023 at 02:13, Chet Ramey wrote: > 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. > I know that some platforms (used

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

2023-05-17 Thread Chet Ramey
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

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

2023-05-17 Thread Phi Debian
On Wed, May 17, 2023 at 12:21 PM Oğuz İsmail Uysal < oguzismailuy...@gmail.com> wrote: > > This boils down to the following > > true & > false & > wait -n > > There is no guarantee that `wait -n' will report the status of `true', > the shell may acquire the status of `false' first.

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

2023-05-17 Thread Robert Elz
Date:Wed, 17 May 2023 17:23:21 +1000 From:Martin D Kealey Message-ID: | I suspect putting "local" in a loop is doing something strange. "local" is an executable statement, not a declaration (shell really has none of the latter) - every time it is executed it

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

2023-05-17 Thread Oğuz İsmail Uysal
On 5/17/23 3:27 PM, Martin D Kealey wrote: On Wed, 17 May 2023 at 20:20, Oğuz İsmail Uysal wrote: On 5/16/23 8:35 PM, Aleksey Covacevice wrote: [original code elided as it's been mangled by line-wrapping] This boils down to the following true & false &

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

2023-05-17 Thread Oğuz İsmail Uysal
On 5/16/23 8:35 PM, Aleksey Covacevice wrote: 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 This boils down

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

2023-05-17 Thread Martin D Kealey
On Wed, 17 May 2023 at 03:35, Aleksey Covacevice < aleksey.covacev...@gmail.com> wrote: > Description: > `wait -n` sometimes returns with status code 127 even though there are > unwaited-for children. > > Repeat-By: > The following script does finish after a while: > > waitjobs() { > local