gator2003 has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that times itself out after an hour using alarm. It worked last week and now is not working. Now, alarm is raised immediately ignoring whatever timeout (seconds) I set. I haven't really changed much in the script, and haven't changed anything in the eval block (below). What could be causing it to "alarm" immediately? It times out in less than a second according to the timestamps.
If there is an error in the main() block will it raise an alarm during execution? Is there a better way to see where the script was when the alarm was raised?
I've also included the entire script on my scratch pad, just in case. Thanks for any help! I'm using Perl 5.8.4 on Solaris 5.1 (and I cannot change system Perl or add my own, unfortunately).
my scratchpadmy @output; eval { # Get the timeout value from the properties file $properties_file = $properties_directory."/".$properties_file; %values_hash = load_properties($properties_file); $script_timeout = $values_hash{'script.timeout'}; # Prepare the lockfile my $lock_file_directory = ""; $lock_file = "emc_backups.lck"; $lock_file_directory = abs_path($0); $lock_file_directory =~ s/(.*)\/.*/$1/; $lock_file = $lock_file_directory."/".$lock_file; # Start logging my $log = $values_hash{'logfile'}; startLog($log); # If script is already running, then exit. If not, create a lock f +ile. verify_lockfile($lock_file, $script_timeout); # Kill the script if it runs longer than the timeout value (in sec +onds) local $SIG{ALRM} = sub { die "Timeout\n" }; alarm $script_timeout; @output = main(); alarm 0; }; if ($@) { # Script timed out # Delete aborted copy, if any if ($currentBackupCopying) { purge_backups($currentBackupCopying); } print LOGFILE "ERROR: Backup timed out - ".localtime()."\n"; # Delete Lock File unlink($lock_file); } else { # Script ran successfully print LOGFILE "Backup finished - ".localtime()."\n"; # Delete Lock File unlink($lock_file); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Alarm firing immediately instead of waiting for timeout
by 1arryb (Acolyte) on Dec 15, 2011 at 17:04 UTC | |
by gator2003 (Initiate) on Dec 15, 2011 at 19:03 UTC | |
|
Re: Alarm firing immediately instead of waiting for timeout
by BrowserUk (Patriarch) on Dec 15, 2011 at 16:59 UTC |