Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 ( [id://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"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found