bug-bash
[Top][All Lists]
Advanced

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

Re: wait -n ignores invalid pids when valid pids are listed


From: Oğuz
Subject: Re: wait -n ignores invalid pids when valid pids are listed
Date: Tue, 27 Apr 2021 10:34:56 +0300

27 Nisan 2021 Salı tarihinde Beer, Mathis <Mathis.Beer@funkwerk.com> yazdı:

> Given a background process that has exited before the script got to wait
> -n:
>
> function foo() { return 1; }
> foo & FOO_PID=$!
>
> function bar() { sleep 1; }
> bar & BAR_PID=$!
>
> sleep 0.1
> # should exit with 127 since FOO_PID is non-existent now
> wait -n $FOO_PID $BAR_PID
>
> Then wait -n will wait on BAR_PID to exit, despite the fact that FOO_PID
> is
> invalid. (Tested with 5.0.17.)
>
> Shouldn't it immediately exit with 127, as the docs suggest, since one id
> specifies a non-existent process?


`FOO_PID' is not invalid there because it hasn't been waited for yet; it's
still in the shell's job table. In an interactive shell this does what you
expect, but that's because interactive shells immediately report a
terminated child and update the job table. Non-interactive shells don't do
that.


>
> The way it currently works makes it hard to make a script that waits for
> one
> of a set of background processes to exit (ie. that fails if one of a set
> of
> background processes fails), since any error that happens before the
> script
> reaches the wait will simply be ignored.


Quite the contrary. The way it currently works makes it easier to keep tabs
on children that change state while the script is busy doing something else.


-- 
Oğuz


reply via email to

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