Zsh Mailing List Archive
Messages sorted by:
Re: Prompt expansion, multi-job for
- X-seq: zsh-users 2841
- From: Oliver Kiddle <opk@xxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx
- Subject: Re: Prompt expansion, multi-job for
- Date: Thu, 06 Jan 2000 15:21:01 +0000
- Cc: Thomas Köhler <jean-luc@xxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <20000106194432.A488@xxxxxxxxxxxxxxxxx> <3874847D.A2ED4AE3@xxxxxxxxxxxxx> <20000106151942.A18295@xxxxxxxxxxxxxxxxx>
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
echo Running sleep $i.
(( jobs=jobs+1 ))
sleep $i &
echo Wait for last job to finish
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
Messages sorted by: