in reply to Alarm and blocking I/O.

Read http://search.cpan.org/~jesse/perl-5.12.1/pod/perlipc.pod#Deferred_Signals_(Safe_Signals). It explains the problem and offers various solutions.

Replies are listed 'Best First'.
Re^2: Alarm and blocking I/O.
by expresspotato (Beadle) on May 29, 2010 at 17:55 UTC
    Hmm I am using perl 5.10.0, so perlio is used by default. I also tried setting the signal handler with use POSIX qw(SIGALRM);. No luck there either. The alarm eventually gets called but about a minute later, most likely when the NFS operation times out because of its mount options. Any help would be greatly appreciated :)
        Thanks for your prompt reply BrowserUK. That still doesn't do the trick. The following code is used to include the Perl::Unsafe::Signals module.
        use Perl::Unsafe::Signals; print "Evaluating... \n"; #eval{ local $SIG{ALRM} = sub { $sys_check_mount{$mount_server} = 0; print "Alarm!"; exit(); }; alarm(5); print "Alarm Set... Trying system commands... \n"; UNSAFE_SIGNALS { print "Using unsafe signals... \n"; if (-e $mount_server_check_path && utime(undef, undef, "$m +ount_server_check_path/mount_check")){ #print "OK\n"; $sys_check_mount{$mount_server} = 1; }else{ #print "Broken\n"; $sys_check_mount{$mount_server} = 0; push (@mount_server_broken,$mount_server); } }; alarm(0); print "Reset Alarm... \n";
        Any other suggestions are appreciated :) Upon further investigation it seems something must be a-miss somewhere else in the program. The following code sniplet alarm's just fine:
        perl -e 'alarm shift @ARGV; exec @ARGV' 3 touch /node/store1/videos/mo +unt_check
Re^2: Alarm and blocking I/O.
by expresspotato (Beadle) on May 29, 2010 at 22:04 UTC
    It seems replacing the default signal is the cause of the alarm failing to go off. I do not understand why, even this simple replacement causes the alarm to not go off.
    $SIG{ALRM} = sub { die "alarm" };
    Without it, the alarm does fire. Anyone can clarify why this is?

      Sorry, my needs of alarm are relatively simple, which is just as well because as with anything signalish, simple is all you get on Win32.

      I've previously used the environment variable PERL_SIGNALS=unsafe, but recently discovered Perl::Unsafe::Signals which works for me and limits the scope. All I could do was pass on the information, as you're doing things I don't understand on a platform I don't use.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      Huh... To anyone curious on how it is now working: Not checking for the file's existence before touching it and not touching it with utime.
      if (system(qq~ touch "$mount_server_check_path/mount_check"; ~)){ ...
      Perl :p