Ah, you're correct. Until something waits on the process it'll still have an entry in the process table and hence be "alive" as far as sending signal 0 goes. Sending signal 0 is probably of more use in checking if an unrelated process (or at least non-descendent process) is alive.

Update: And you can see this behavior with the code below.

#!/usr/bin/perl my $pid = fork; die "fork: $!\n" unless defined $pid; if( $pid ) { ## Parent print "Parent $$, child is $pid\n"; for( 1..5 ) { check_alive( $pid ); sleep 2; } } else { ## Child print "Child here, pid $$; sleeping 7 secs\n"; sleep 5; print "Child exiting\n"; exit 0; } print STDERR "Parent, waiting on child\n"; waitpid( $pid, 0 ) or warn "waitpid: $!\n"; check_alive( $pid ); exit 0; sub check_alive { my $pid = shift; my $kill = kill 0 => $pid or warn "kill: $!\n"; $kill = $kill == 1 ? "alive" : "$!"; print STDERR scalar localtime, ": kill sez $kill\n"; } __END__

In reply to Re^3: Finding if a child process has terminated by Fletch
in thread Finding if a child process has terminated by cog

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.