in reply to Timeout with SIG{ALRM} not working as expected

Why can you not do the relatively simple ?

$cmd="myCommand"; # Timeout evaluation: eval { # Set action to be done when alarm occurs: local $SIG{ALRM} = sub { die "ALARM_COMMAND_TIMEOUT" }; # Schedule alarm in $CMD_TIMEOUT seconds: alarm($CMD_TIMEOUT); ### execute the command that can block $Results = `$cmd`; if ($?) {# optional error handling} } wait; alarm(0); close(PIPE); }; alarm(0);

The backticks spawn a child to run the command and block 'till it returns

Update

OK, I tried that, well this perl -le'$SIG{ALRM}=sub{die "TIMEOUT"};eval{alarm 1;`sleep 100`};print $@' and it did not work for me, this did however

perl -le'$SIG{ALRM}=sub {die "TIMEOUT"}; eval{alarm 10; open PIPE, "while [ 1 ] ;do echo \"foo\";sleep 5;done|"; while (<PIPE>){print}}; print $@'
If you trust the child to die on SIGPIPE then it will die when the eval exits

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!