exec is a little different to how you describe, although the effect may be similar. The exec command does a rather peculiar thing: it replaces the current program with a different one in the same process. There is no return from a successful exec, since the original code is lost. Some things do survive an exec, the PID, open file handles, DEFAULT or IGNORE signal disposition, and ENVironment variables, to mention a few.

You imply you are doing some processing after the call to system, yet looking at your code you appear to be doing an exit(0). If it got to that point then the exec did not work, so a die (showing $!) might be better.

In the parent it is perfectly normal to call waitpid, there is no need to place it in a CHLD signal handler. Using an argument of -1 (no need for WNOHANG) will wait on the next child to finish, and return its PID. For example (untested):
while (keys %fhlist) { my $pid = waitpid(-1, 0); delete $fhlist{$pid}; }

By the way, if you call waitpid (or its sister wait) for each of your children then you avoid zombies.

In reply to Re^3: rsh <defunct> processes appear when using fork and system calls by cdarke
in thread rsh <defunct> processes appear when using fork and system calls by whatwhat

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.