Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Prompt expansion, multi-job for



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



Messages sorted by: Reverse Date, Date, Thread, Author