From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9855 invoked by alias); 13 Dec 2011 10:02:13 -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: 16626 Received: (qmail 10966 invoked from network); 13 Dec 2011 10:02:10 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Tue, 13 Dec 2011 10:01:54 +0000 From: Peter Stephenson To: Subject: Re: wait for the next process to finish Message-ID: <20111213100154.0da5d421@pwslap01u.europe.root.pri> In-Reply-To: <20111212154601.GA5198@cosy.cit.nih.gov> References: <20111212154601.GA5198@cosy.cit.nih.gov> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.11.233] X-Scanned-By: MailControl 7.6.5 (www.mailcontrol.com) on 10.68.0.113 On Mon, 12 Dec 2011 10:46:01 -0500 Anthony R Fletcher wrote: > I just realised that the 'wait' command will either wait for specified > jobs or all jobs and nothing in between. The manual says "If job is not > given then all currently active child processes are waited for.". > > So > sleep 30 & > sleep 10 & > sleep 30 & > sleep 30 & > wait > waits for all the sleeps to finish. > > How can I wait for just the next job to finish? Certainly the shell internals don't help you here. There's code to look at a specific job, decide if it's still going, and exit when it isn't, which is behind the wait builtin with an argument. There's nothing to loop over all jobs, decide what's still going, wait for something to happen, then work out what it was and hence if it can stop waiting. The reason waiting for all jobs works is simply that it waits for jobs in order; if an earlier job exits first it gets handled by the signal handler, but the shell foreground doesn't notice until the job it's actually waiting for exits, then it carries on down the list and picks up anything that's already exited. -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog