Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: wait for the next process to finish
- X-seq: zsh-users 16634
- From: Anthony R Fletcher <arif@xxxxxxxxxxxx>
- To: <zsh-users@xxxxxxx>
- Subject: Re: wait for the next process to finish
- Date: Tue, 13 Dec 2011 12:32:37 -0500
- In-reply-to: <alpine.DEB.2.00.1112131023060.13348@MyComp.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20111212154601.GA5198@cosy.cit.nih.gov> <CAHSx_Sv8g+tQQnytijXd=HOSHkyu-vwcmjCaDWoHhp2ba+whHw@mail.gmail.com> <alpine.DEB.2.00.1112130937120.13348@MyComp.localdomain> <alpine.DEB.2.00.1112131023060.13348@MyComp.localdomain>
On 13 Dec 2011 at 11:04:44, Rory Mulvaney wrote:
> pids=( )
> R=( $RANDOM $RANDOM )
> echo $R
> coproc () { sleep $(( $R[1]/32767.0*20 )) ; echo $$ }
> pids+=$!
> # copy the coproc fd
> exec 3<&p
> coproc () { sleep $(( $R[2]/32767.0*20 )) ; echo $$ }
> pids+=$!
> exec 4<&p
> zmodload zsh/zselect
> zselect -r 3 4
> echo $reply
>
> Then one could parse $reply.
>
> I don't know, maybe there's a much easier way to create file descriptors
> for those processes?
>
> -Rory
I was using this loop
for f in *.txt
do
what-ever-has-to-happen $f &
pwait 20
done
where pwait is a function
function pwait() {
while [ $(jobs -rp | wc -l) -ge $1 ]
do
# sleep 10
wait
done
}
(see http://superuser.com/questions/158165/parallel-shell-loops for one
example amongst many).
I was hoping that using "wait" would be better than using a "sleep 10".
But wait waits for them all and not just he last to finish. The nice
thing is that this is a small, easy loop and all the brains is in the
barrier function pwait. Sadly a sleep for 10 seconds is completely
arbitrary.
Anthony.
--
Anthony R Fletcher
Room 2033, Building 12A, http://dcb.cit.nih.gov/~arif
National Institutes of Health, arif@xxxxxxxxxxxx
12A South Drive, Bethesda, Phone: (+1) 301 402 1741.
MD 20892-5624, USA.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author