>perl -MPOSIX=:sys_wait_h -le"my $pid = system 1, $^X=>(-e=>'sleep 5'); while (waitpid($pid, WNOHANG) == 0) { print 'waiting'; sleep 1; } print 'done'" waiting waiting waiting waiting waiting waiting done #### use POSIX qw( WNOHANG ); # Returns false if alive. # Returns true if dead. (Reaps and sets $?) # Throws expection on error. (Sets $!) sub is_child_dead { my ($pid) = @_; my $rv = waitpid($pid, WNOHANG); die("waitpid: $!\n") if $rv == -1; return $rv; }