Andrew Clarke wrote:
> 
> On Thu, 27 Nov 2008 17:59, you wrote:
> > wait(1) with no operands waits for all jobs to complete

Actually, it doesn't even always do that; I tested a couple of ideas
using wait, and it would sometimes return with at least one job still
running. Go figure.

> Whoopsie.
> 
> Now that I think of it, there's probably a lot of scope for using SIGCHLD
> intelligently too. /ponders

At first I thought this could be easily implemented using a CHLD trap
to decrement the counter (don't forget set -o monitor) although you
still need to spin waiting for the signal handler to get called; as
the experts have pointed out, ksh doesn't offer anything that works
like wait(2).

However, consider this:

  count=0

  set -o monitor
  trap 'count=$((count-1))' CHLD

  while read task; do
    count=$((count+1))
    $task &
    while [[ $count -ge 3 ]]; do sleep 1; done
  done

Unfortunately, it doesn't always work. I found that if two tasks exit
at about the same time, the CHLD trap will only fire once, and the
count will be off.

Given that ksh offers no reliable process monitoring, no programmatic
access to job status (short of parsing `jobs`), and no clean way to
block on job state change, I humbly submit that this kind of thing is
better written in a different language. :-)

--
Ron Isaacson
Morgan Stanley
[EMAIL PROTECTED] / (212) 276-1144
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to