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 | Thread Next
November 30, 2002 19:51
RE: how do i make a script run for a certain period of time?
Message ID:
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;

        #-- task

sub delay{
        my $time = $_[0] * 999999;
        for(my $i = 0; $i < $time; $i++){} 


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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About