Rob, Thanks for the help. I did what you suggested and cleaned up the code. But I am getting some strange errors:
Use of uninitialized value in numeric gt (>) at ./script.pl line #. foreach $hostId ( @hostIds ) { my $pid = undef; $pid = fork if $CHILD_PIDS < $MAX_CHILDREN; if( $pid > 0 ) { $CHILD_PIDS++; #Add the children up until we hit the max }elsif (defined $pid) { #the rest is just like you suggested. the message if for the line that says: f( $pid > 0 ) { Not too sure what to make of it?? Thansk for the help CHad On Thursday 27 March 2003 11:59 am, Rob Dixon wrote: > Hi Chad. > > Chad Kellerman wrote: > > Hello, > > > > Got a little issue. Tyring ot under stand how things work but just > > not getting it. I am forking each element of the array . I have a > > maximum child count of 8. Which works. What I was wondering is if I get > > into the if statement in the until loop. How do I exit the pid clean up > > and go on to the next element in the array with out leaving any pids > > around? > > > > FORK: > > { > > > > HOSTID2: foreach $hostId ( @hostIds ) { > > > > #next if $CHILD_PIDS > $MAX_CHILDREN; > > redo HOSTID2 if $CHILD_PIDS >= $MAX_CHILDREN; > > > > if( my $pid = fork ) { > > $CHILD_PIDS++; #Add the children up until we hit the max > > next; > > }elsif (defined $pid) { > > my $failures = 0; > > > > #grab quota for each user and insert into the database > > until ( (BACKUP->QuotaIt( $hostId, $mysqluser, $mysqlpasswd ) > > or ( $failures == $maxtries ) ) ) { > > $failures++; > > if ( $failures == $maxtries ) { > > #BLA BLA code > > > > #clean up the pid and exit > > exit 0; > > waitpid(-1, &WNOHANG); > > > > #go to the next hostid > > next HOSTID2; > > > > } #if statememt > > > > } #until statement > > > > #rest of code. > > > > Thanks for the help, > > You'd do yourself a favour if you laid out your code better with > blocks indented neatly. It's very hard to see the loop structure > as it is. > > You seem to be getting confused over which process your code is > executing in. You're doing a waitpid from your child processes, > for instance, and looping on the host ID in all the processes. > > Take a look at the following. It almost certainly won't work as it > is, because I'm not sure of the sense of some of your tests, but it's > written without using loop labels, which are often a sign of something > going wrong. It's rarely necessary to label your loops unless you're > doing something quite tricky. > > Let us know if this helps. > > Rob > > > my $child_pids = 0; > > foreach $hostId ( @hostIds ) { > > my $pid = undef; > > $pid = fork if $child_pids < $MAX_CHILDREN; > > if ($pid > 0) { > > $child_pids++; > > } elsif ( defined $pid ) { > > # $pid == 0 so in the child process > > my $failures = 0; > > while ( $failures < $maxtries ) { > my $result = BACKUP->QuotaIt ( $hostId, $mysqluser, > $mysqlpasswd ); last if $result; > $failures++; > } > > #BLA BLA code > #clean up the pid and exit > > exit 0; > > } else { > > # $pid is undefined so fork failed - wait for a spare one > > waitpid -1, WNOHANG; > $child_pids--; > } > } -- chad kellerman Jr. Systems Administrator Alabanza Inc 10 East Baltimore Street Suite 1500 Baltimore, Md 21202 1-800-361-2662 Ext 3305 410-234-3305 direct -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]