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 scratchpad
my @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); }

In reply to Alarm firing immediately instead of waiting for timeout by gator2003

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.