<?xml version="1.0" encoding="windows-1252"?>
<node id="633770" title="Backticks and SIGALRM" created="2007-08-20 07:16:41" updated="2007-08-20 03:16:41">
<type id="115">
perlquestion</type>
<author id="633754">
nemo</author>
<data>
<field name="doctext">
Hi,
   I have a small piece of code that executes an external application that may hang. I use backticks to execute the external app. and collect output. I have been trying to use an alarm(3) call to timeout if the app. takes too long to execute. The alarm call is not timing out, if the external application hangs the entire perl script hangs. Is this an incorrect use of the alarm call?
&lt;br/&gt;
Thanks for all responses.&lt;br/&gt;
Nemo&lt;br/&gt;
&lt;code&gt;
my @result;
$SIG{ALRM} = sub { die "timeout" };

eval {
    alarm(3);
    @result = `extApp $_`;   #Not returning if extApp hangs
    alarm(0);
};

if ($@) {
    if ($@ =~ /timeout/i) {
      push(@result, "App has hanged itself.");
    } else {
        alarm(0);           # clear the still-pending alarm
        die;                # propagate unexpected exception
    } 
} 
&lt;/code&gt;</field>
</data>
</node>
