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

Re: wait for the next process to finish



On Tue, 13 Dec 2011, Rory Mulvaney wrote:

> > On Mon, Dec 12, 2011 at 7:46 AM, Anthony R Fletcher <arif@xxxxxxxxxxxx>wrote:
> > 
> > > How can I wait for just the next job to finish?
> > >
> > 
> > One thing that may help you is TRAPCHLD.  Sadly, the signal handler doesn't
> > tell you what pid it is reacting to, nor the exit code.
> > 
> > TRAPCHLD() {
...
> > }
...
> > It might be nice to set an environment parameter with the pid and status
> > info right before the dotrap(SIGCHLD) call in jobs.c.
...

This sounds very promising, because you then could 'parallelize'
a loop by feeding it new processes when 'one of the runnig' dies.

I hope for something in the line of:

TRAPCHILD() { ... ... ... }
pids=( )
for i in some paramters given
do
        if [[ $#pids >= $MAXPARALLEL ]]
        then sleep 1 # and TRAPCHILD will remove 'done's
        else
                call $i &
                pids+=$!
        fi
done

SO one might be able to keep a bunch of CPUS working
for 'one given loop' without needing to know which
case is done first? (And only if the parallelities
do not break something like tempfiles, stderr, etc ...)

Stucki


-- 
Christoph von Stuckrad      * * |nickname |Mail <stucki@xxxxxxxxxxxxxxx> \
Freie Universitaet Berlin   |/_*|'stucki' |Tel(Mo.,Mi.):+49 30 838-75 459|
Mathematik & Informatik EDV |\ *|if online|  (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin   * * |on IRCnet|Fax(home):   +49 30 77 39 6601/



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