If you open a pipe in a parent process via open(), then spawn a child, which then runs the close() on the open handle, close() fails with "No child processes":

open PIPE, "| cat" or die $!; my $pid = fork(); if( $pid == 0 ) { # child close PIPE or die $!; exit 0; } sleep 1; my $reaped = waitpid(-1, 0 ); print "pid $reaped\n";
Now you'll certainly say "Don't do that!" but the problem is that the open() happens in a module I maintain and the close() happens in its DESTROY method. If the user of the module decides that they want to spawn a child process, the error occurs! Who's to blame here? The module? The user? Perl? Should every module opening a pipe implement logic to check if the close fails for this obscure reason and suppress an error that's otherwise reported and will confuse the user?

In reply to close() on opened pipe fails in forked child by saintmike

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.