The new process does remain a child of the parent process across exec, since the open(FROM_CHILD,'-|') does an implicit fork. Here's an example:
#!/usr/bin/perl use warnings; use strict; my $pid = open(F,"-|"); if (!defined($pid)) { die "fork error: $!\n"; } if ($pid) { # Parent print "PARENT: PID is $$\n"; sleep(1000); print <F>; close(F); } else { # Child exec("/bin/bash","-c", 'echo CHILD: PID is $$, PPID is $PPID >&2'); }

Below, notice that 20474 is the parent process, and its child 20476 is a zombie.

freenet{swgsh}~ $ perl tmp/t3 & [2] 20474 freenet{swgsh}~ $ PARENT: PID is 20474 CHILD: PID is 20476, PPID is 20474 freenet{swgsh}~ $ ps PID TTY TIME CMD 12912 pts/0 00:00:00 bash 13286 pts/0 00:00:39 emacs 20474 pts/0 00:00:00 perl 20476 pts/0 00:00:00 bash <defunct> 20487 pts/0 00:00:00 ps

In reply to Re^2: Protection from zombies by sgifford
in thread Protection from zombies by nomis80

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.