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
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
If you trust the child to die on SIGPIPE then it will die when the eval exitsperl -le'$SIG{ALRM}=sub {die "TIMEOUT"}; eval{alarm 10; open PIPE, "while [ 1 ] ;do echo \"foo\";sleep 5;done|"; while (<PIPE>){print}}; print $@'
Cheers,
R.
In reply to Re: Timeout with SIG{ALRM} not working as expected
by Random_Walk
in thread Timeout with SIG{ALRM} not working as expected
by MorgothSauron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |