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

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

Thread Previous | Thread Next
From:
LRMK
Date:
December 2, 2002 09:25
Subject:
Re: how do i make a script run for a certain period of time?
Message ID:
01b901c29a27$f4064990$345e5ecb@lrmk
$check=1;
while($check){

check the time;
set $check to 0 when the time is right to exit

}


but this will make your program little slow because it check time in each
round

send if others have better ideas

----- Original Message -----
From: "david" <dzhuo@looksmart.net>
To: <beginners@perl.org>
Sent: Sunday, December 01, 2002 9:59 AM
Subject: RE: how do i make a script run for a certain period of time?


> Nyimi Jose wrote:
>
> > I'm writing a script that has to be automatically
> > executed every day at 6:00 AM via 'dollar universe' scheduler software.
> > I want my script to stop itself at 23:00 PM
> > (I think to timeout via alarm function).
> > The script is mainly a while(1) loop and I want my loop
> > to sleep few seconds before going to the next iteration.
> > How can handle this without mixing alarm and sleep ?
> >
>
> you have a few options:
>
> 1. just mix alarm and sleep. Not all sleep functions are implemented using
> alarm. If yours doesn't, you won't have to worry about it.
>
> 2. use the 4 argument version of the select() function with the first
three
> arguments being undef so you can delay any time you want. you can even get
> finer granularity than a second if your system supports it.
>
> 3. Implement your own "sleep" function. Not really recommanded but I have
> seen people doing things like:
>
> #!/usr/bin/perl -w
> use strict;
>
> while(1){
>         delay(3);
>         #-- task
> }
>
> sub delay{
>         my $time = $_[0] * 999999;
>         for(my $i = 0; $i < $time; $i++){}
> }
>
> __END__
>
> which is NOTHING close to the sleep function and it's wasting your
system's
> CPU resource. it merely slows down the program in a bad way!
>
> 4. check perldoc if you haven't do so. I am sure there are other methods
> that works better since this is a fairly command task. There might even be
> a module in CPAN that deals with that.
>
> david
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>



Thread Previous | Thread Next


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