delirium has asked for the wisdom of the Perl Monks concerning the following question:
Today I hacked together this wrapper script with the simple idea that if the problem binary's logfile hasn't been updated in 3 minutes, the process is dead, and is safe to kill. This is our standard criteria for killing this process.
It works famously in testing, but before I migrate it, I wanted to get some feedback about using the alarm function the way I am. Is it safe to reset the alarm in the $SIG{ALRM} intercept? Is it possible for $SIG{ALRM} to not get called after the timeout? Are there handy modules I've never stumbled across that account for wacky edge cases?
This is for AIX Unix with Perl 5.6.0.
my $timeout = 60; my $logfile = 'logfile.txt'; my @array = ('the_binary -option1', 'the_binary -option2', 'the_binary + -option3'); for (@array) { print "Running command $_\n"; eval { local $SIG{ALRM} = sub { my $mod_time = time - (stat($logfile))[9]; if ( $mod_time > 180 ) { die "alarm\n"; } else { alarm 0; alarm $timeout; } }; alarm $timeout; system($_); alarm 0; }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Safety of using alarm
by Abigail-II (Bishop) on Mar 10, 2004 at 21:54 UTC | |
by delirium (Chaplain) on Mar 11, 2004 at 13:17 UTC | |
by Abigail-II (Bishop) on Mar 11, 2004 at 13:27 UTC | |
by delirium (Chaplain) on Mar 11, 2004 at 15:22 UTC | |
by Abigail-II (Bishop) on Mar 11, 2004 at 17:09 UTC | |
|
Re: Safety of using alarm
by ambrus (Abbot) on Mar 10, 2004 at 21:46 UTC | |
|
Re: Safety of using alarm
by bluto (Curate) on Mar 11, 2004 at 16:32 UTC |