in reply to How to monitor an NFS mount with perl

You could try using an alarm (untested code)
$SIG{ALRM} = sub { die "Seems hung"; }; # 30 seconds alarm(30); if (open(TESTFILE, $testfile)) { alarm(0); # disable alarm }
Edit: Make sure to listen to Fletches advice below as well.

Replies are listed 'Best First'.
Re^2: How to monitor an NFS mount with perl
by Fletch (Bishop) on Feb 08, 2005 at 17:41 UTC

    Make sure that the filesystem was mounted with the intr option (or soft,intr depending on the OS; consult your local sysadmin and/or mount(8) manpage), otherwise the open(2) system call will get stuck in system wait and won't return until the NFS server's responding again alarm or no.

      This will probably work, but I've seen systems that don't respond if you wait too long to interrupt the process.

      One of the problems with hard NFS mounts is that anything you do underneath the mount point will cause a hang if the server is unavailable and sometimes not even a SIGKILL can get rid of the process. One way to handle this might be to fork a child process, which performs the check and quits. As long as the child doesn't exit you know the mount point is down.

Re^2: How to monitor an NFS mount with perl
by w3ntp (Beadle) on Feb 08, 2005 at 19:01 UTC
    Hi I tried the Sig alarm idea and found the Signal was blocked by the open file hanging. Had the following code The Sigalarm subroutine never got called after the NFS got dropped.. $SIG{SIGALRM)=sub {do something}; while(true) { alarm 5; # set a 5 second alarm if(!open(TESTMOUNT,"$testfile")) { do something } else { do somethineelse } close(TESTMOUNT); alarm 0; # disable alarm sleep 5; }
Re^2: How to monitor an NFS mount with perl
by w3ntp (Beadle) on Feb 08, 2005 at 20:22 UTC
    Tried the above and it did not work thanks W3NTP