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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |