From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8499 invoked by alias); 13 Dec 2011 17:31:39 -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: 16633 Received: (qmail 25095 invoked from network); 13 Dec 2011 17:31:38 -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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <111213093119.ZM3642@torch.brasslantern.com> Date: Tue, 13 Dec 2011 09:31:19 -0800 In-reply-to: <20111213164906.GH20573@localhost.mi.fu-berlin.de> Comments: In reply to "Christoph (Stucki) von Stuckrad" "Re: wait for the next process to finish" (Dec 13, 5:49pm) References: <20111212154601.GA5198@cosy.cit.nih.gov> <20111213164906.GH20573@localhost.mi.fu-berlin.de> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: wait for the next process to finish MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 13, 5:49pm, Christoph (Stucki) von Stuckrad wrote: } } This sounds very promising, because you then could 'parallelize' } a loop by feeding it new processes when 'one of the runnig' dies. That much you can do already. TRAPCHLD() { while (( ${#jobstates} < MAXPARALLEL )) do the background task & done } (Of course you need some sort of other loop-ending condition, but you get the idea.) You don't really even need the trap for this, your original loop will work fine as long as you examine ${(k)jobstates} as the list of PIDs instead of trying to maintain your own array.