Hello Everyone,
     I got a script that spawns off a few children.  But for some reason
before the children are finished doing what they are suppose to do they
die.

code:
use POSIX "sys_wait_h";
my $child_limit = 1;
my $child_pids = 0;
$SIG{CHLD} = \&CHILD_COUNT;
FORK:
             {
                while ( $#server_list > -1 ) {
                     sleep 1;
                     next if $child_pids > $child_limit;
                     my $server_todo = pop @server_list;
                     if (my $pid = fork) {
                             #do the parent
                             $child_pids++;
                             next;
                     }
                     elsif (defined $pid) {
                             # ok now the child.
                             do_stuff($server_todo);
                             exit;
                     }
                     elsif ($! =~ /No more process/) {
                             print " No more process ...sleeping\n";
                             sleep 5;
                             redo FORK;
                     }
                     else {
                     die " Can't fork: $! \n";
                     }
                }       
             }
wait;

sub CHILD_COUNT {
        #my $child_limit = @_;
        my $child;
        $child = waitpid(-1, WNOHANG);
        while ( $child > 0 && ( $child_pids > 0)) {
                $child_pids-- if ( $child_pids > 0);
                $child = waitpid(-1,WNOHANG);
        }
}

  The program goes into the sub routine do_stuff but in the middle
spawns a new child and kills the first spawned pid.
  The sub works like a charm by itself but when I try to fork it dies.  
I have checked perlmonks and oreilly.  But still nothing works.

Thanks for the help...

chad 
   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to