title: How do you tell if a pipe opened process has terminated?
body: <p>Assuming a handle created with the following code:</p>
  
  <pre><code>use IO::File;
  
  my $fh = IO::File-&gt;new;
  
  my $pid = $fh-&gt;open('some_long_running_proc |') or die $!;
  
  $fh-&gt;autoflush(1);
  $fh-&gt;blocking(0);
  </code></pre>
  
  <p>and then read with a loop like this:</p>
  
  <pre><code>while (some_condition_here) {
      my @lines = $fh-&gt;getlines;
      ...
      sleep 1;
  }
  </code></pre>
  
  <p>What do I put as <code>some_condition_here</code> that will return false if the process on the other end of the pipe has terminated?</p>
  
  <p>Testing for <code>$fh-&gt;eof</code> will not work since the process could still be running without printing any new lines.  Testing for <code>$fh-&gt;opened</code> doesn't seem to do anything useful.</p>
  
  <p>Currently I am using <code>$pid =! waitpid($pid, WNOHANG)</code> which seems to work in POSIX compliant environments.  Is this the best way?  What about on Windows?</p>