Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: wait for the next process to finish
- X-seq: zsh-users 16636
- From: Jérémie Roquet <arkanosis@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: wait for the next process to finish
- Date: Tue, 13 Dec 2011 19:04:12 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=NVIzzGOII0x46oKPp2Zq7xNgGPJ0568h5ZnWNUmLAr8=; b=HVrGkDYpZ1hN7Et5ETahcFiN+JLLqfCmeQnWa0Wyb2qT9oep67rle7AQIBWoiuIl8y lBYHmdM3uvglpvjTQc54zNUNSDPWi4+2cTftpzmhRB0XD93LgKDBdmPt4q2IwAka2msz 7R5BRT8cKRt/SEbYP8y1+39SWQ5MtToXFm+RA=
- In-reply-to: <20111213173237.GA10838@cosy.cit.nih.gov>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- 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> <20111213173237.GA10838@cosy.cit.nih.gov>
2011/12/13 Anthony R Fletcher <arif@xxxxxxxxxxxx>:
> 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.
I'm wondering if you're not just looking for zargs :-)
autoload -U zargs
zargs -n 1 -P 20 *.txt -- what-ever-has-to-happen
Best regards,
--
Jérémie
Messages sorted by:
Reverse Date,
Date,
Thread,
Author