Hello dizzyd719, and welcome to the Monastery!

If your code:

system("ping ... &"); $result = $?;

worked as you expect, what advantage would there be in backgrounding the ping process? Whether running in the foreground or the background, it would still have to complete before the system call returned.

But with ping backgrounded you report a significant speedup. I suspect what is happening is this: the call to system("ping ... &") spawns a shell subprocess (1) which in turn spawns the call to ping as a background process (2). Process (1) then immediately returns to the system call a status code indicating whether process (2) was spawned successfully. So of course you aren’t getting the correct exit statuses, since the return values from (2) never make it back to your Perl script.

The speedup you are seeing suggests that you will indeed benefit from running the ping commands in parallel (asynchronously). So you need another way to do this and get their exit statuses. Have a look at fork or a module such as Parallel::ForkManager. (And see perlfaq8#How-do-I-start-a-process-in-the-background%3f.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Problem with exit status of bash script by Athanasius
in thread Problem with exit status of bash script by dizzyd719

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.