Hi All... I have perl program that used to work fine...The parent process would wait for all the children (using waitpid()) before proceeding... However, when I add LWP request command in the code before forking the child process, then the Parent process does not wait for the children to finish execution and exit...AND it also does not execute the rest of the code after waitpid statement. I have tried different ways to figure out how to make the parent to wait, but somehow the HTTP request statement is making a difference and it is not waiting for children. Any help/suggestions would be appreciated Below is the code snippet... . . .

use File::Copy; use Net::FTP; use Win32::Process; use File::Path; use LWP::UserAgent; use HTTP::Headers; use HTTP::Cookies; use HTTP::Response; . . . . #IMP: Below are the few request lines mainly the $res = $ua->request($ +req); statement which makes parent not to wait for the child processe +s ######## Process the URL response ua = new LWP::UserAgent; $ua->agent("$0/0.1 " . $ua->agent); $req = new HTTP::Request 'GET=> 'http://www.cpan.org/RECENT'; $req->header('Accept' => 'text/html'); # send request $res = $ua->request($req); my $url_response = $res->content; print $url_response . "\n"; print $res->status_line . "\n"; print $res->code . "\n"; . . . my @pids; # Process every Unlink item foreach $extractItem (@extractItemLines) { . . . . my $childpid = fork(); if ($childpid) { push @pids, $childpid; print "I am parent: $childpid\n\n"; } # elsif (defined $childpid) { elsif ($childpid==0) { exec($command); die "Error: Cannot exec EXTRACT command:'$command': $!\n"; print "I am child: $childpid\n\n"; } else { die "Error: Cannot fork EXTRACT process: $!\n" } ######### Check for successful execution #if ($? != 0) #{ # print "Error: $C4C_TCENG_DOWNLOAD_ITK exited with fatal error +code.\n"; # die "Error: $C4C_TCENG_DOWNLOAD_ITK exited with fatal error co +de.\n"; #} print logFP "############## Processed $extractItem ############### +#\n"; } # foreach $extractItem... #### wait for all extract processes to finish before zipping the d +irectory waitpid($_,0) for @pids;
. . . . Rest of the parent code

In reply to Parent process does not wait for Child processes to finish and exits after the waitpid statement by scriptstudent

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.