Good morning, afternoon, night,
I have been trying to work on a script that does forking. But
the script dies in the fork. Here is what I have:
I push some information about a server into an array.
<snip>
use POSIX "sys_wait_h";
my $child_limit = 1;
my $child_pids = 0;
$SIG{CHLD} = \&CHILD_COUNT($child_limit);
push @server_list, $href;
FORK:
{
while ( $#server_list > -1 ) {
next if $child_pids > $child_limit;
my $server_todo = pop @server_list;
if (my $pid = fork) {
# sleep 1; # failing due to bad
subroutine?
#do the parent
$child_pids++;
next;
}
elsif (defined $pid) {
# ok now the child.
do_stuff($server_todo); #subroutine
exit;
}
elsif ($! =~ /No more process/) {
print " No more process ...sleeping\n";
sleep 5;
redo FORK;
}
else {
die " Can't fork: $! \n";
}
}
}
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);
}
}
</snip>
I get the error:
Not a subroutine reference at serverbackup.pl line 65.
Line 65 is the next if statement.
I am at a loss here. It seems that the more I read about this the
more I get confused.
Can anyone give me a hand with this? Or a push in the right direction?
It would be much appreciated.
Thanks
--chad
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]