From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7759 invoked by alias); 13 Dec 2011 18:04:49 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16636 Received: (qmail 8475 invoked from network); 13 Dec 2011 18:04:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.83.43 as permitted sender) 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= MIME-Version: 1.0 In-Reply-To: <20111213173237.GA10838@cosy.cit.nih.gov> References: <20111212154601.GA5198@cosy.cit.nih.gov> <20111213173237.GA10838@cosy.cit.nih.gov> From: =?UTF-8?B?SsOpcsOpbWllIFJvcXVldA==?= Date: Tue, 13 Dec 2011 19:04:12 +0100 Message-ID: Subject: Re: wait for the next process to finish To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2011/12/13 Anthony R Fletcher : > I was using this loop > > =C2=A0for f in *.txt > =C2=A0do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0what-ever-has-to-happen $f & > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pwait 20 > =C2=A0done > > where pwait is a function > > =C2=A0function pwait() { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while [ $(jobs -rp | wc -l) -ge $1 ] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# sleep 10 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wait > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0done > =C2=A0} > > (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, --=20 J=C3=A9r=C3=A9mie