#!/usr/bin/perl
use strict;
use warnings;
# number of times to fork
# DO NOT RAISE ABOVE 10.
my $maxfork = 10;
# do not edit the below variables
my $forkcount = 1;
my $count = 0;
my %settings;
my $pid;
#$SIG{CHLD} = 'sub_to_do';
for ($forkcount = 0; $forkcount < $maxfork; $forkcount++) {
sleep 1; # so we don't overload ourselves
if (!defined(my $pid = fork())) { # fork
die "cannot fork: $!"; # die fork if fork fails
} elsif ($pid == 0) { # fork successful, in child, do stuff
print STDERR "CHILDDEBUG: in child $pid, forkcount: $forkcount\n";
#sub_to_do(); # stuff to do
sleep(1);
exit 0; # kills child
} else { # parent
print STDERR "PARENTDEBUG: last child: $pid\n";
waitpid($pid, 0);
}
} while (1) { sleep 1; print STDERR "PARENTDEBUG: in spinloop: ", $count++, "\n";} # waits for all children to die
sub sub_to_do {
# print " fork number " . $forkcount;
# print STDERR "DEBUG: child: $pid\n";
}