Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

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

( #24429=categorized answer: print w/ replies, xml ) Need Help??

Q&A > programs and processes > What is the best way to run periodic tasks (once per minute)? contributed by Corion

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 ); }

Comment on Answer: What is the best way to run periodic tasks (once per minute)?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-04-18 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (464 votes), past polls