From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23644 invoked by alias); 13 Dec 2011 20:45:15 -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: 16640 Received: (qmail 8824 invoked from network); 13 Dec 2011 20:45:14 -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 autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.41 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version:content-type; bh=4WDLWc9ALydzGD6sVx41n90Z9SB9faj5O8IWPce3xH8=; b=TdoaP+92F9o9ef1av/v3Nx6v5Uty1uF0IN3vj5uDdoZ4WoRTyXc7bYF+cyGVB7zItN RTuHBxP+IPYr9kaaVkKtco75CD7fh+oWsoZNchQORDDtotP4ttaST4+tzdIIoJu42v+Q 6N/nQ24J+mfU7Scj7j2ffQITvIX0wMUcntsng= Date: Tue, 13 Dec 2011 14:42:29 -0600 (CST) From: Rory Mulvaney To: Bart Schaefer cc: zsh-users@zsh.org, rorymulv@gmail.com Subject: Re: wait for the next process to finish In-Reply-To: <111213091049.ZM3465@torch.brasslantern.com> Message-ID: References: <20111212154601.GA5198@cosy.cit.nih.gov> <20111213100154.0da5d421@pwslap01u.europe.root.pri> <111213091049.ZM3465@torch.brasslantern.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 13 Dec 2011, Bart Schaefer wrote: > > In the realm of ugly hacks, you could run each child as a coprocess > that ends with "print $?". Stash away the coprocess file descriptor > each time you start one, and then when they're all running, start a > loop polling that list of descriptors with "read -t" until you find > one from which you can read. What you read will be the exit status. > Yes, this is what I demonstrated in my second email, but the idea about using TRAPCHLD is probably easiest, since you could have your child processes print out any info about the process such as the return code, redirecting it to a single file descriptor owned by a designated information-relay coproc (which merely echo's its stdin to stdout), and then parse the output from the coproc in TRAPCHLD, which is apparently one of the available trap functions running whenever a signal arrives, since SIGCHLD is a signal from signal(7) (I didn't realize that before). On Tue, 13 Dec 2011, Bart Schaefer wrote: > > 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. >