#!/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) { # fork successful, do stuff
print "> doing thing\n"; # inform of success
print "new child: $forkcount\n";# number children
sub_to_do(); # stuff to do
exit 0; # kills child
} else { # parent
waitpid($pid, 0);
}
} while (1) { sleep 1; } # waits for all children to die
sub sub_to_do {
print " fork number " . $forkcount;
}