<?xml version="1.0" encoding="windows-1252"?>
<node id="964533" title="trying to get timeout to work" created="2012-04-11 08:58:32" updated="2012-04-11 08:58:32">
<type id="115">
perlquestion</type>
<author id="253915">
Skeeve</author>
<data>
<field name="doctext">
&lt;p&gt;
I'm desperately trying to get timeouts to work and came up with this test code:
&lt;code&gt;
use Sys::SigAction qw( set_sig_handler );
eval {
    my $h = set_sig_handler( 'ALRM' ,sub {
        die "TIMEOUT\n";
    }, {
         mask=&gt;[ 'ALRM' ],
         safe=&gt;1,
    });
    eval {
        alarm 3;
        $opened= open my $check, '-|', 'sleep 60';
        if ($opened) {
            # slurp its output
            $line= do { local $/; &lt;$check&gt;; };
            $exit_code= $!+0;
            $closed= close $check;
        }
        alarm 0;
    };
    alarm 0;
    die $@ if $@;
};
alarm 0;
print $@;
&lt;/code&gt;
Of course I can't really ready something from a "sleep" command, But I expected this to return after 3 seconds with a "Timeout". Instead I have to wait 60 seconds, so the full sleep-time.
&lt;/p&gt;
&lt;p&gt;
I also tried a different command than "sleep" like, for example, a long running "find" command but still the sleep does not die.
&lt;/p&gt;
&lt;p&gt;
What am I doing wrong or what do I misunderstand?
&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-253915"&gt;
&lt;hr&gt;&lt;code&gt;s$$([},&amp;%#}/&amp;/]+}%&amp;{})*;#$&amp;&amp;s&amp;&amp;$^X.($'^"%]=\&amp;(|?*{%&lt;/code&gt;
&lt;br&gt;&lt;font color="red"&gt;&lt;code&gt;+&lt;/code&gt;&lt;/font&gt;&lt;code&gt;.+=%;.#_}\&amp;"^"-+%*).}%:##%}={~=~:.")&amp;e&amp;&amp;s""`$''`"e&lt;/code&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
