LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 07-21-2007, 06:54 PM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Question Cron job or Sleep timer??? Which is best in my situation


Well basically, firstly the question is i was looking into a cron job running every so many seconds, but it seems the best available i can see is every minute, unless there is a way to do it??? say if possible show me an example of setting a cron job for something that runs every 20 seconds.

OR

At the moment in my scripts i just use a sleep timer to cause the required delay, and then let it loop basically.

What i want to know is what would cause the greater over heads (CPU wise) and be the most reliable.
A cron job that executes every 20 seconds and then the script exits, or a script in a constant loop that will just sleep for 20 seconds?? Does the sleep command use any overheads or is it more like the command isn't in execution anyway?

Thanks for any info
Mark
Karoshi Team
 
Old 07-21-2007, 06:59 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
First, I'm fairly sure that the cron job would take more overhead than the simple sleep loop.

Second, if the job is being run once every 20 seconds, the difference in overhead won't matter at all.

Third, if the interval itself is critical, don't sleep for 20 seconds, but sleep for as long as it takes to start the job 20 seconds after the last time it started.

Fourth, when I read the man page for crontab I don't see any granularity finer than one minute.

Hope this helps.
 
Old 07-21-2007, 07:08 PM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Excelent thanks, i got asked to change my already sleep timed scripts to be put into cron, couldn't see much point in it myself wanted to make sure it didn't matter much

Cheers
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job rust8y Linux - Newbie 3 05-18-2006 10:06 AM
How can I implement an accurate timer under the heavey loading situation! appforce Programming 3 10-04-2005 07:58 PM
cron job? dr_zayus69 Linux - Newbie 14 12-01-2004 07:16 PM
Linux C : A better way to sleep/timer? jimmy416 Programming 8 10-14-2003 01:58 PM
Cron job T-Rex Linux - Newbie 1 09-26-2001 12:28 PM


All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration