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

Re: How to run the child process parellel to the parent process with fork

by bart (Canon)
on Mar 15, 2013 at 12:01 UTC ( #1023675=note: print w/ replies, xml ) Need Help??


in reply to How to run the child process parellel to the parent process with fork

What you do wrong? You don't have $| on, so the output is buffered.

Also, your code executes very shortly. Too short to reliably state which comes first.

Let the run for a while longer. Use else to have the child and parent run side by side.

$| = 1; use Time::HiRes qw(sleep); # allows sleep in fractions of seconds if(fork){ foreach my $i (1 .. 10) { print "I am the parent\n"; sleep 1; } print "parent exiting now.\n"; } else { foreach my $i (1 .. 30) { print "I am the child\n"; sleep 0.3; } print "Bye.\n"; }


Comment on Re: How to run the child process parellel to the parent process with fork
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-12-25 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls