bug-bash
[Top][All Lists]
Advanced

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

Re: wait -n shouldn't collect multiple processes


From: Robert Elz
Subject: Re: wait -n shouldn't collect multiple processes
Date: Tue, 26 Mar 2019 19:12:06 +0700

    Date:        Tue, 26 Mar 2019 10:55:53 +0100
    From:        Andreas Schwab <schwab@suse.de>
    Message-ID:  <mvmimw6t0wm.fsf@suse.de>

  | Even better, IMHO: "wait waits for the next job to terminate"

Something should allow for there being no waiting involved at all
if some job has already terminated but has not been waited for.

I modified Chet's script to be:


echo Running @${SECONDS}
{ sleep 1; exit 1; } &
{ sleep 5; exit 2; } &
{ sleep 5; exit 3; } &
{ sleep 5; exit 4; } &

jobs

echo Pausing @${SECONDS}
sleep 2

echo Looping @${SECONDS}
for f in 1 2 3 4; do
        wait -n
        echo wait return status: $? @${SECONDS}
done
echo Finishing @${SECONDS}

jobs

which results in:

jinx$ bash /tmp/AA
Running @0
[1]   Running                 { sleep 1; exit 1; } &
[2]   Running                 { sleep 5; exit 2; } &
[3]-  Running                 { sleep 5; exit 3; } &
[4]+  Running                 { sleep 5; exit 4; } &
Pausing @0
Looping @2
wait return status: 1 @2
wait return status: 2 @5
wait return status: 3 @5
wait return status: 4 @5
Finishing @5

jinx$ bash /tmp/AA
Running @0
[1]   Running                 { sleep 1; exit 1; } &
[2]   Running                 { sleep 5; exit 2; } &
[3]-  Running                 { sleep 5; exit 3; } &
[4]+  Running                 { sleep 5; exit 4; } &
Pausing @0
Looping @2
wait return status: 1 @2
wait return status: 4 @5
wait return status: 2 @5
wait return status: 3 @5
Finishing @5

When the first wait is done, the first job would have already
been finished for a second.   "wait -n" simply collected that
one and did not pause at all.  The next "wait -n" then waited
the remaining 3 seconds until there was more to collect.

This is all as it should be.   The manual should reflect this.

kre

ps: those tests run with bash5, but bash4 is just the same.






reply via email to

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