Hi monks,

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?


In reply to windows eval-timeout with alarm by disciple01

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.