Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 browsing the Monastery: (5)
As of 2015-07-05 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls