I am using Parallel::ForkManage. While running run_on_finish, I am checking what is the return code of the Child Process. Now, in child process i am running curl to download a file. While downloading some times the remote server goes down and curl terminates in between. Now, when this happens and I check the return exit code in run_on_finish, it is coming as zero while when i reproduce this same thing on shell prompt, it returns me error code ($? to be 175 or a non zero). Can you help me trap correct error code in run_on_finish? Here is my code:
$pm->run_on_finish ( sub { my ($pid, $exit_code, $ident, $signal, $core) = @_; if ($core) { #If there is a core, report it print "Process $pid dumped core\n"; } else { #Collecting process info in Hash to be reported at the end + of script. #print "Process $pid executed successfully\n"; } $pidInfoHash{$pid} = $exit_code; } ); for (1..$total_calls/$cps) { for (1..$cps) { my $pid = $pm->start and next; RunChild(); $pm->finish; } sleep(1); } sub RunChild { if (defined $proxy) { $ENV{http_proxy}="$proxy"; } $logFile = $logDir."/header_".$call; `curl -o /dev/null -m 222 \"$Link\" 2>> $logFile`; my $curlResult = `echo $?`; chomp($curlResult); if ($curlResult != 0) { print "Curl Result $curlResult :: Call Drop : $callDrop\n"; $callDrop++; print "Curl Result $curlResult :: Call Drop : $callDrop\n"; } }

In reply to Parallel::ForkManager run_on_finish Canot get Exit Code of Child process by anshumangoyal

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.