title: Perl, Parallel::ForkManager - how to implement timeout for fork
body: <p>Is it possible to implement some kind of timeout (time limit) for fork using Parallel::ForkManager ?</p>
  
  <p>Basic Parallel::ForkManager script looks like this</p>
  
  <pre><code>use Parallel::ForkManager;
  my $pm = Parallel::ForkManager-&gt;new( 10 );
  for ( 1 .. 1000 ) {
      $pm-&gt;start and next;
      # some job for fork
      $pm-&gt;finish;
  }
  $pm-&gt;wait_all_children();
  </code></pre>
  
  <p>I would like to limit time for "# some job for fork". For example, if its not finished in 90 secs. then it (fork) should be killed/terminated.
  I thought about <a href="https://stackoverflow.com/questions/2423288/ways-to-do-timeouts-in-perl">using this</a> but I have to say, that I dont know how to use it with Parallel::ForkManager.</p>
  
  <h3>EDIT</h3>
  
  <p>Thanks hobbs and ikegami. Both your suggestions worked..... but only in this basic example, not in my actual script :(.
  <img src="https://i.stack.imgur.com/Emjaw.jpg" alt="screenshot">
  These forks will be there forever and - to be honest - I dont know why. I use this script for couple of months. Didnt change anything (although many things depends on outside variables). 
  Every fork has to download a page from a website, parse it and save results to a file. It should not take more than 30 secs per fork. Timeout is set to 180 secs. Those hanging forks are totally random so its very hard to trace the problem. Thats why I came up with a temporary, simple solution - timeout &amp; kill.</p>
  
  <p>What could possibly disable (interrupt) your methods of timeout in my code ? I dont have any other <code>alarm()</code> anywhere in my code.</p>
  
  <h3>EDIT 2</h3>
  
  <p>One of the forks, was hanging for 1h38m and returned "timeout PID" - which is what I type in <code>die()</code> for <code>alarm()</code>. So the timeout works... but its late about 1h36,5m ;). Do you have any ideas?</p>