Fw: Perl maximum execution time

Fw: Perl maximum execution time

am 14.04.2008 15:45:23 von anthony brooke

Thanks for the reply, but sometimes I don't know where is the code that cau=
se the infinite loop. Is there such as thing as perl configuration file, to=
set the execution time for any code, any where in the program just like ph=
p.ini file. Thanks. ----- Original Message ----=0AFrom: Chas. Owens has.owens@gmail.com>=0ATo: Keenlearner =0ACc: beginners@p=
erl.org=0ASent: Friday, April 11, 2008 16:05:07=0ASubject: Re: Perl maximum=
execution time On Thu, Apr 10, 2008 at 9:25 PM, Keenlearner mail.com> wrote:=0A> Hello, I have had been programming in PHP for a while,=
new to perl. I=0A> got a perl code bug where it will go to infinite loop.=
So is there a=0A> maximum execution time that I could set in perl just li=
ke in PHP ?=0A> Thanks=0Asnip You can set an signal to go off after X=
seconds with the alarm* function: #!/usr/bin/perl use strict;=0A=
use warnings; my $timeout =3D 5*60; #timeout after five minutes e=
val {=0A local $SIG{ALRM} =3D sub { die "timeout\n" };=0A alarm $time=
out;=0A #stuff you want to run in under five minutes=0A};=0Adie unle=
ss $@ eq "timeout\n" if $@; * http://perldoc.perl.org/functions/alarm.=
html -- =0AChas. Owens=0Awonkden.net=0AThe most important skill a prog=
rammer can have is the ability to read. -- =0ATo unsubscribe, e-mail: =
beginners-unsubscribe@perl.org=0AFor additional commands, e-mail: beginners=
-help@perl.org=0Ahttp://learn.perl.org/ =0A Send instant me=
ssages to your online friends http://uk.messenger.yahoo.com =0AS=
end instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Fw: Perl maximum execution time

am 14.04.2008 16:31:35 von Jenda Krynicky

From: anthony brooke
> Thanks for the reply, but sometimes I don't know where is the code
> that cause the infinite loop. Is there such as thing as perl
> configuration file, to set the execution time for any code, any where
> in the program just like php.ini file. Thanks.

Depends. Perl is not just for Web!

Most likely your webserver has some settings for this, but without
knowing what server do you use we can't tell you where.

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Fw: Perl maximum execution time

am 14.04.2008 16:49:50 von anthony brooke

Thanks, I am using Apache 2 and Opera browser. So you mean configure throug=
h my web server ? How if I run the code through the shell ? ----- Orig=
inal Message ----=0AFrom: Jenda Krynicky =0ATo: beginner=
perl mailling list =0ASent: Monday, April 14, 2008 22:=
31:35=0ASubject: Re: Fw: Perl maximum execution time From: anthony bro=
oke =0A> Thanks for the reply, but sometimes I don't kno=
w where is the code=0A> that cause the infinite loop. Is there such as thin=
g as perl=0A> configuration file, to set the execution time for any code, a=
ny where=0A> in the program just like php.ini file. Thanks. Depends. =
Perl is not just for Web! Most likely your webserver has some settings=
for this, but without =0Aknowing what server do you use we can't tell you =
where. Jenda ===== Jenda@Krynicky.cz ===3D http://Jend=
a.Krynicky.cz ===== When it comes to wine, women and song, wiza=
rds are allowed =0Ato get drunk and croon as much as they like.=0A -- Te=
rry Pratchett in Sourcery =0A-- =0ATo unsubscribe, e-mail: beginners-u=
nsubscribe@perl.org=0AFor additional commands, e-mail: beginners-help@perl.=
org=0Ahttp://learn.perl.org/ =0ASend instant messages to y=
our online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Fw: Perl maximum execution time

am 14.04.2008 16:50:58 von chas.owens

On Mon, Apr 14, 2008 at 9:45 AM, anthony brooke wrote:
>
> Thanks for the reply, but sometimes I don't know where is the code that cause the infinite loop.
> Is there such as thing as perl configuration file, to set the execution time for any code, any where
> in the program just like php.ini file. Thanks.

No, but you could just create a script like

#!/usr/bin/perl

use strict;
use warnings;

my $timeout = shift;
my $rc;
my $pid = fork;
eval {
$SIG{ALRM} = sub { die "timeout\n" };
die "could not fork" unless defined $pid;
if ($pid) {
alarm $timeout;
waitpid $pid, 0;
$rc = $? >> 8;
} else {
exec "/usr/bin/perl", @ARGV;
}
};
if ($@) {
kill "SIGTERM", $pid;
print "died with: $@\n";
} else {
print "exit code was: $rc\n";
}

and then run it like this:

timout.pl 60 script_that_should_die_in_60_seconds.pl

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Fw: Perl maximum execution time

am 15.04.2008 01:11:07 von Jenda Krynicky

From: anthony brooke
> Thanks, I am using Apache 2 and Opera browser. So you mean configure through my web server ? How if I run the code through the shell ?

Normaly it's the web server's job to kill scripts that take too long.
I bet there are people here that can help you with Apache, I've never
used it myself.

If you run the code through shell you seldom need it to be killed
automaticaly after some time. I don't think I ever wanted to do that
myself actually.

And would definitely not like there to be some systemwide setting
that would cause all my long running programs to have to be restarted
every N minutes or something.

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/