Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: What is the best way to run periodic tasks (once per minute)?

by Corion (Patriarch)
on Jul 26, 2000 at 12:53 UTC ( [id://24429]=note: print w/replies, xml ) Need Help??


in reply to What is the best way to run periodic tasks (once per minute)?

First of all, most operating systems already have services for scheduling program runs. UNIX has the cron program and Windows NT has the AT program and service. Look first into these before you think of rolling your own.

If you still want to roll your own, look into the sleep() function call, which will put your script to sleep for the amount of time you specify. Note that running such a script on a server without the administrators knowledge could have bad consequences for you. First talk to your admin and think if using cron would do the job for you as well.

Here is a small program that prints a line every 10 seconds (tested) :

#!/usr/bin/perl -w use strict; my $tick = "tick\n"; # loop until this process is terminated from the outside while (1) { print $tick; # Make "tick" into "tock" and "tock" into "tick" $tick =~ tr/io/oi/; # sleep 10 seconds sleep( 10 ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://24429]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found