The general definition of a fork is that a thread spawns a process that begins execution from the same program location as its parent, while the parent then continues in parallel.

Your code calls the perl fork function six times, three of which are controlled by returning the pid and issuing a waitpid to hold up parent execution until completion of the child. But not only will these children run through to the end of the code unchecked, but the three uncontrolled forks will triplicate everything from where they are placed - I don't dare to test (or rather inflict) your code on my machines under these circumstances, but if you were to place a sleep 60 at the end of the code and then repeatedly examine what is running using the ps command, I wager you will see far more parallel processes being spawned than you imagine should take place even after reading the above definition.

To fix this code in the simplest way:

1) yes, as already replied, replace all exec with system BUT

2) also remove all "unless fork" lines reducing the code to a single non-parallel process.

-M

Free your mind


In reply to Re: Waiting for an External Program to Finish Executing by Moron
in thread Waiting for an External Program to Finish Executing by awohld

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.