From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15491 invoked from network); 6 Jan 2000 15:21:18 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 6 Jan 2000 15:21:18 -0000 Received: (qmail 26967 invoked by alias); 6 Jan 2000 15:21:06 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2841 Received: (qmail 26960 invoked from network); 6 Jan 2000 15:21:05 -0000 Message-ID: <3874B2DD.A80FBAFC@u.genie.co.uk> Date: Thu, 06 Jan 2000 15:21:01 +0000 From: Oliver Kiddle X-Mailer: Mozilla 4.7 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: zsh-users@sunsite.auc.dk CC: Thomas =?iso-8859-1?Q?K=F6hler?= Subject: Re: Prompt expansion, multi-job for References: <20000106194432.A488@bozar.ihug.com.au> <3874847D.A2ED4AE3@u.genie.co.uk> <20000106151942.A18295@picard.franken.de> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thomas Köhler wrote: > Well, bad idea if you have a few hundred wavs :) > > > The trouble with this is that it will attempt to run all the l3encs > > together. If you have say 4 processors, it may be most efficient to run > > a maximum of 4 l3encs at once. This would be a bit messy to implement in > > Zsh (compared to something like Ada) but can be done. > > Well - let's try something like this: That's certainly one way. I seem to remember seeing someone else's solution using a co-routine at some point (Bart maybe?). Here is my method which I think is quite simple: trap '(( jobs=jobs-1 ))' CHLD for i in 10 9 2 3 1 7 1 2 4; do while (( jobs >= 4 )); do : done echo Running sleep $i. (( jobs=jobs+1 )) sleep $i & done echo Wait for last job to finish wait For the original problem, you would want to replace sleep with l3enc and the list of numbers with your glob for .wav files. I just thought that this demonstrates it better. You might also want to use a 'sleep 1' instead of ':' so that the while loop loops more slowly. In theory you could have problems if the increment and decrement for $jobs didn't run atomicly and ran at the same time but this is hardly a safety-critical system and with jobs as long as l3enc, I'd doubt it would happen. At worst $jobs would end up a little out so you'd have more or less concurrent jobs. Other jobs finishing might also mess this up but you can always avoid that by running it all in a sub-shell. Anyone else got any other solutions (maybe using co-routines, fifos or something)? Oliver