bug-bash
[Top][All Lists]
Advanced

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

Re: wait -n misses signaled subprocess


From: Chet Ramey
Subject: Re: wait -n misses signaled subprocess
Date: Tue, 30 Jan 2024 08:41:27 -0500
User-agent: Mozilla Thunderbird

On 1/28/24 10:26 PM, Dale R. Worley wrote:
Chet Ramey <chet.ramey@case.edu> writes:
echo "wait -n $pid return code $? @${SECONDS} (BUG)"

The job isn't in the jobs table because you've already been notified about
it and it's not `new', you get the unknown job error status.

The man page gives a lot of details and I'm trying to digest them into a
structure.

It looks like the underlying meaning of "-n" is to only pay attention to
*new* job completions, and anything "in the past" (already notified and
moved to the table of terminated background jobs) is ignored.

That was the original implementation, yes. The idea was to add something
to augment the `wait for all' strategy of wait without pid arguments.

The underlying meaning of providing one or more ids is that "wait" is to
only be concerned with those jobs.

Right, that's the current operation.


The man page doesn't make clear that if you don't specify "-n" and do
supply ids and one of them has already terminated, you'll get its status
(from the terminated table); the wording suggests that "wait" will
always *wait for* a termination.

Only if your mental model of the operation links the wait builtin and wait
system call. If the pid has already terminated, the wait is immediate, and
there's no reason to call the system call, but wait still returns the
status.

(As an aside, that is one long paragraph describing `wait'. I need to
break that up.)


There's also an interaction in that "wait" will only look at the
terminated table if "-n" is not specified *and* ids are specified.

This is to maintain POSIX semantics, with extensions. This is one of the
issues -- should `wait -n' with arguments look for terminated processes
in that table, the way `wait' without options does?

Chet

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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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