All pastes #31600 Raw Edit

Miscellany

public text v1 · immutable
#31600 ·published 2005-11-28 22:27 UTC
rendered paste body
#!/usr/bin/perl

$maxfork = 10;

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

                print "LOLDONGZ forked $forkcount\n";
        }
} while (1) { sleep 1; }           # waits for all children to die