From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11569 invoked by alias); 23 Nov 2009 00:55:51 -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: 14595 Received: (qmail 6019 invoked from network); 23 Nov 2009 00:55:48 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.217.225 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=YfO4dMcCb866+yO/Fi+jFC+yovwcikEipf6bmEeW7pA=; b=Ioy1aam3O5x0DEtC3OQU/p2N8I5b/2+Mdy+32/GqcSaA1a+1RVS6R80U5yWfuygUoT Zv1c9+kyYIStSpRN5KvP371hDVL9Pg5Pc5Yi074dTsTjBj1E8iYpvMPtVC+rjz4DMut0 R/2XsBw6FYKokeZhN8iWRkAEYM2SAb2a28n7A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=oBJKe4U7KUHHs9C9WOQN/Kd0kim3NecqvGNERReRt8j3wIyXpS6mRz9vIb3hdJhJSR SeNcZtsm129aDGaweppVQ3mkY1yAvT+Htzw8fKY+/Io84MG4UrXPp75JS6H2YyQOx0js 7JMullE+m8xEwi8O7i4+n9LRJ2OCqivZJYaD4= MIME-Version: 1.0 In-Reply-To: <5992e17f0911221634y4b42d567lfd75c2782487b637@mail.gmail.com> References: <20090628103129.GA15270@fermat.math.technion.ac.il> <5992e17f0911221305j53522ed6j55d8b1308fda2214@mail.gmail.com> <20091122221655.GA28699@fermat.math.technion.ac.il> <237967ef0911221440u66a3b80dqcaa0717670397a9f@mail.gmail.com> <5992e17f0911221634y4b42d567lfd75c2782487b637@mail.gmail.com> Date: Sun, 22 Nov 2009 22:48:18 -0200 Message-ID: <5992e17f0911221648g1d99d899w617cfcef508166d5@mail.gmail.com> Subject: Re: Multi-core loops From: Kazuo Teramoto To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I found a pretty/small solution (but not optimized) http://stackoverflow.com/questions/38160/parallelize-bash-script I'm quoting the solution (the solution can be used as-is in zsh too) > Here an alternative solution that can be inserted into .bashrc and used f= or > everyday one liner: > > function pwait() { > while [ $(jobs -p | wc -l) -ge $1 ]; do > sleep 1 > done > } > > To use it, all one has to do is put & after the jobs and a pwait call, th= e > parameter gives the number of parallel processes: > > for i in *; do > do_something $i & > pwait 10 > done > > It would be nicer to use wait instead of busy waiting on the output of jo= bs > -p, but there doesn't seem to be an obvious solution to wait till any of = the > given jobs is finished instead of a all of them. > --=20 =C2=ABDans la vie, rien n'est =C3=A0 craindre, tout est =C3=A0 comprendre= =C2=BB Marie Sklodowska Curie.