in reply to Re^2: Testing whether a process has finished
in thread Testing whether a process has finished
Perhaps rovf's machine is one of the machines that doesn't?
He has Windows, and it works for Windows too.
>perl -MPOSIX=:sys_wait_h -le"my $pid = system 1, $^X=>(-e=>'sleep 5') +; while (waitpid($pid, WNOHANG) == 0) { print 'waiting'; sleep 1; } p +rint 'done'" waiting waiting waiting waiting waiting waiting done
To avoid suspending your program I'm guessing the code should look something like this?
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Testing whether a process has finished
by rovf (Priest) on Sep 11, 2009 at 09:56 UTC |