in reply to Yet another fork() w/ win32 (activeperl) question

I guess I posted a bit too soon, I have something which seems to work. Can anybody tell me whether or not i'm doing the forking right?
#!c:\perl\bin\perl use Net::AIM; use strict; use warnings; my $counter = 0; my $done; while (1==1) { if ($counter <= 3) { my $pid = fork(); if ($pid) { print "forking process $counter.\n"; $counter++; } else { ############meat########################### # pretty much just # straight copy/pasted from main script ###########/meat########################### exit $counter; } } else { $done = wait(); $counter--; } }
It seems to work brilliantly.

Replies are listed 'Best First'.
Re: Re: Yet another fork() w/ win32 (activeperl) question
by tcf22 (Priest) on May 24, 2003 at 22:33 UTC
    Since you are running on windows, fork() isn't exactly forking a new process, it forks a pseudo-process. However it looks to be correct if you want to spawn multiple copies of the same script. When the original script terminates so do the child processes as they live in the memory of the parent process. One way to get around this is to use Win32::Process with the DETACHED_PROCESS flag, if you want the children to live on.