in reply to Cannot catch ALRM signal for timeout

I think alarm is working but you call close on WORKER when you catch the signal, put some prints before the close statements.

from close
Closing a pipe also waits for the process executing on the pipe to complete..
  • Comment on Re: Cannot catch ALRM signal for timeout

Replies are listed 'Best First'.
Re^2: Cannot catch ALRM signal for timeout
by Magice (Novice) on Dec 08, 2009 at 13:03 UTC
    I have tried that also (print out some string in the if checking for timeout), but it does not print anything, so I believe that it does not catch the signal.
      open(WORKER,"yes >/dev/null |"); eval{ local $SIG{ALRM} = sub { die "alarm\n" }; alarm 1; $str = <WORKER>; alarm 0; }; if ($@) { print "timeout\n"; close WORKER; return 0; }
      for me, this prints "timeout" and hangs on close.
      what happens if you run this code ?

      UPDATE: the eof function also hangs on pipes.
        Thank you for your code, it behaves as you expected (print out "timeout\n" and hang). But it does not exactly solve the problem. When I tried earlier on mine, it does not even print out "timeout\n" equivalent :(.