fork at windows
am 11.05.2005 14:26:48 von George Bouras# I have the following lines to fork some code and wait
# every thing to finish before continue. The problem at
# windows 2000 is that if there more than 6 forks Perl
# can not fork. Any idea ?
use threads;
use threads::shared;
$|= 1;
my %children;
my $pid_program= $$;
threads::shared::share(%children);
sub CodeToRunInParallel { print "Current = $_[0] , Clone = $_[1]\n" }
my $pid_child = fork;
my $pid_child = fork;
my $pid_child = fork;
my $pid_child = fork;
my $pid_child = fork;
die "$pid_current could not fork.\n" if $pid_child eq undef;
my $pid_current = $$;
$children{$pid_current} = 1;
CodeToRunInParallel($pid_current,$pid_child);
waitpid($pid_child,0) if $pid_child != 0;
if ( $pid_current ne $pid_program ) { delete $children{$pid_current} ;
exit }
do {sleep 0} until 1 == scalar keys %children;
print "The main code can continue now\n";