disciple01 has asked for the wisdom of the Perl Monks concerning the following question:
I was writing a script to 'probe' a number of servers one after another but found my script hung repeatedly on one particular server.
In order to find a workaround for this I found a section in the oreilly advancded perl programming book which outlined a method where the `eval` call could be used to simulate a timeout.
The following bit of code serves as an example :
$SIG{ALRM}=\&time_out; eval{ alarm(2); my $buf=<>; alarm(0); }; exit; sub time_out { die "FED UP WAITING"; }
The eval statement executes, when a die function is called within an eval, the eval section immediately ends. A die function can be called by use of the alarm function.
In other words, the eval starts, the alarm starts giving the user 2 seconds to enter data and hit carriage return, after 2 seconds the alarm kicks in which produces a die statement and causes the script to jump to the end of the eval statement and the script can then continue on and exit.
For my script I'd change the `my $buf=<>;` line for a line which probes a server and then throw a loop round the whole lot to iterate through each server in turn.....
The poblem is the above script works on unix but not on windows, on windows it just sits there forever. I think it's something to do with the way the alarm function is implemented on windows.
I like the above script because it's a simple implementation. Could anyone offer up any alternative methods or solutions on how to get such a timeout script to work on windows?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: windows eval-timeout with alarm
by BrowserUk (Patriarch) on Nov 05, 2004 at 13:33 UTC | |
|
Re: windows eval-timeout with alarm
by bpphillips (Friar) on Nov 05, 2004 at 13:08 UTC | |
by BrowserUk (Patriarch) on Nov 05, 2004 at 13:24 UTC | |
by disciple01 (Novice) on Nov 05, 2004 at 13:25 UTC | |
by vacant (Pilgrim) on Jan 24, 2005 at 22:12 UTC |