develooper Front page | perl.beginners | Postings from November 2002

Re: how do i make a script run for a certain period of time?

Thread Previous
From:
david
Date:
November 27, 2002 10:42
Subject:
Re: how do i make a script run for a certain period of time?
Message ID:
20021127184258.62406.qmail@onion.perl.org
Nix Juban wrote:

> i want to insert this script in one of my programs appearing like its
> processing or doing something..since my loop is while(1), meaning always
> true, it will run forever until i halt it.
> 1)How do I time it to run for only few seconds?
> 2) What if im really processing something like extracting data through ftp
> and parsing it, how do i run this while its doing all that?
> 

try the alarm function along with $SIG{ALRM}. example:

#!/usr/bin/perl -w
use strict;

$SIG{ALRM} = sub { die "see ya\n" };

alarm(2);
while(1){
        print time,"\n";
}

__END__

the above will end in about 2 seconds. check:

perldoc -f alarm

for more. HTH

david

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About