J
Jim
I'm having a hard time using fork() and throttling it. Perhaps it is
because I am using the fork() emulation in Activestate Perl for
Windows. Basically, what I want to do is loop through an array and run
a process on each element. I need to fork each process but the array
is hundreds of elements big and I can only run 8 processes at a time.
my $parent = $$;
$StartProc = 1;
$TotProcs = 8;
# Trap signals from child processes and run this subroutine.
$SIG{CHLD} = \&ChldStopped;
foreach $x (@array) {
if ($parent == $$){ # this is parent process
while ($StartProc > $TotProcs) { # limit to 8 at a time
sleep 1;
}
$StartProc ++;
my $child = fork();
if ($child == 0) { # This is a child process.
# run process on $x
exit 1;
}
}
sub ChldStopped {
$StartProc --;
}
because I am using the fork() emulation in Activestate Perl for
Windows. Basically, what I want to do is loop through an array and run
a process on each element. I need to fork each process but the array
is hundreds of elements big and I can only run 8 processes at a time.
my $parent = $$;
$StartProc = 1;
$TotProcs = 8;
# Trap signals from child processes and run this subroutine.
$SIG{CHLD} = \&ChldStopped;
foreach $x (@array) {
if ($parent == $$){ # this is parent process
while ($StartProc > $TotProcs) { # limit to 8 at a time
sleep 1;
}
$StartProc ++;
my $child = fork();
if ($child == 0) { # This is a child process.
# run process on $x
exit 1;
}
}
sub ChldStopped {
$StartProc --;
}