Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Fork Results in thousands of processes

by anshumangoyal (Scribe)
on Nov 28, 2011 at 10:56 UTC ( [id://940344]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://940344]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2026-03-11 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.