use Parallel::ForkManager;
$pm = new Parallel::ForkManager(100);
my @all_data = qw/1/;
foreach $data (@all_data) {
# Forks and returns the pid for the child:
my $pid = $pm->start;
print "PID $pid\n";
$pid and next;
print "$data", "\n";
my $pid2 = fork();
unless ($pid2) {
exec $^X, '-e', 'while(){}';
}
print "Real PID $pid2\n";
waitpid $pid2, 0;
$pm->finish; # Terminates the child process
}
$pm->wait_all_children;
####
exec $^X, '-e', 'while(){}';
####
exec "perl -e 'while(){}'";