Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Howdy monks,

I have a script that needs to look up prices on our intranet for about 40 items. Each inquiry takes about 15-20 secs, so I'd like to fork off several children to minimize the execution time. (I'm using Linux now, but plan on using perl2exe to place it on some win98 boxes.) Using the example here: how to fork?, I've got fork working, but how do I get the data back to the parent? The data that needs to get back are: price, description, and department. I know I can write the output to a file, and have the parent read out of that, but is there a better way?

Also, I'm unclear on the $SIG{CHLD} = sub { wait; };. Is this how I can make sure that my parent waits until the children are done? It doesn't seem to be doing that as written.

forktest.pl #!/usr/bin/perl -w use strict; use LWP::Simple qw(get); my $loops = shift || 10; my $pid; open (OUT, "+> out"); print "Testing with $loops children...\n"; for my $i (0..$loops-1) { if ($pid = fork) { ## Parent $SIG{CHLD} = sub { wait; }; next; } if (defined $pid) { ## ...children my ($price,$desc,$dept); # So everyone can play along at home: my $url ="http://www.perlmonks.org/index.pl?node_id=".(6000+$i); my $page = get ($url); # extract data to $price,$desc,$dept # Now what? print OUT "$i $price $desc $dept\n"; print "$i done\n"; exit; } else { die "Fork failed at number $i: $!\n"; } } while <OUT> { # get data here? } print "I'm done\n";
Many Thanks,

Pepik

Of all the causes that conspire to blind
Man's erring judgment, and misguide the mind,
What the weak head with strongest bias rules,
Is pride, the never-failing vice of fools.
-- Pope.
(Humble to be American.)


In reply to How do I get the child's data? by pepik_knize

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found