http://www.perlmonks.org?node_id=940344

anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I am having an issue with Fork in Perl. I want to execute 10 Fork Processes at a go from one single script and all 10 Child (Forked) processes will do the same thing (Copy files from one place to another).
while ($callCount <= $totalCalls) { for (1..$TotalProcessToFork) { print "Call -> $callCount"; if($pid = fork) { #in Parent Process print " :: PID -> $pid\n"; push(@list_of_pid, $pid); } else { #in Child Process `touch $callCount`; } $callCount++; } }
Now when I execute this code, there are around 1000 child processed which are executed. Can any one tell me what wrong I am doing here.

Replies are listed 'Best First'.
Re: Fork Results in thousands of processes
by ikegami (Patriarch) on Nov 28, 2011 at 10:59 UTC
    { # in Child Process ... exit(0); <- Missing }
    Or:
    { # in Child Process exec('touch', $callCount); die $!; }
Re: Fork Results in thousands of processes
by ikegami (Patriarch) on Nov 28, 2011 at 11:00 UTC
    { # in Child Process ... exit(0); <- Missing }
    Or:
    { # in Child Process exec('touch', $callCount); die $!; }
    A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.