A parent can fork as many times as it wants to (for that matter a child
could fork as well).  So your code would look like this:

$SIG{CHLD} = "IGNORE"; #works on unix platforms, auto reaps children
foreach $machine (get_machines()) {
        $pid = fork;
        if ($pid == 0) { #I am a child
                check_machine($machine);
        } elsif (not $pid) { 
                #if parent then $pid = process id, if error then 
                #$pid = undef
                error();
        }
}

On 28 Jun 2001 17:03:39 +0100, Pierre Smolarek wrote:
> The one thing in perl that gets my head all confused is fork.
> 
> Can someone point me in the right direction (be it book, website, or kind
> enough to offer code).
> 
> I need to make a script that has to check 16000 servers in around 6 minutes.
> My rough maths works out that 44 checks a second are needed. Each server
> check takes about 0.5 seconds to return, so the best bet is to fork each
> individual check, the result of which gets added to mysql so no need to have
> a conversation going on between child and parent. Idealy i would like to
> control the max amount children i have to, say, around 50.
> 
> Any help would be greatful.
> 
> (I have the cook book open but only seems to talk about a single parent
> child pair..?!)
> 
> 
> Pierre.
> 
> 
--
Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
Keep the Lasagna flying!


Reply via email to