LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cron / second precision ? (https://www.linuxquestions.org/questions/linux-general-1/cron-second-precision-571539/)

TrAvIkK 07-23-2007 03:49 AM

Cron / second precision ?
 
Hi there!

I'm wondering - CRON entry allows to set up a cron job with minutes, hours, days etc.
But what if i need to do something at 6:23:38 ? I mean, i need second precision?

rupertwh 07-23-2007 04:10 AM

Quote:

Originally Posted by TrAvIkK
But what if i need to do something at 6:23:38 ?

I don't know if cron can be relied upon to always start jobs at the full minute. If it can, then adding your job as
Code:

23 6 * * * sleep 38 && myjob
should do the trick.

TrAvIkK 07-23-2007 04:16 AM

Yeah, but sleep 38 means processor usage by 38 sec?
If yes, that is not the answer i was expecting on. I need to take carve about processor usage.

slakmagik 07-23-2007 04:56 AM

Quote:

Originally Posted by rupertwh
I don't know if cron can be relied upon to always start jobs at the full minute.

My cron jobs always start after the minute, and not precisely - at least 9 out of 10 times it's :01, with the rest being :02. I wouldn't be surprised if on a more heavily loaded system it would vary more and sometimes run later.

Quote:

Originally Posted by TrAvIkK
Yeah, but sleep 38 means processor usage by 38 sec?

Sleep uses no (or virtually no) CPU.

/me wonders what cron job could require second precision, though. ;)

TrAvIkK 07-23-2007 05:20 AM

Hmm what job?
Well, i'm a developer of Web-Based MMO, and some operation (as Battle calculations etc.), which calculating them by users interaction would take too much time.

Matir 07-23-2007 01:10 PM

Cron is not intended for high-accuracy timing. It CAN be and is frequently off by several seconds (due to process start-up, etc.). If you need that kind of precision, I suggest running a daemon of your own to avoid process start-up overhead.

TrAvIkK 07-23-2007 02:15 PM

Quote:

Originally Posted by Matir
Cron is not intended for high-accuracy timing. It CAN be and is frequently off by several seconds (due to process start-up, etc.). If you need that kind of precision, I suggest running a daemon of your own to avoid process start-up overhead.


How to do such thing?
Coz I think i like it ;)

I mean, i know I have to write it by my own (well, as for now - i'm onyl learning C++, so it could be kind of hard :P), but may be there are on internet some examples?

Matir 07-23-2007 02:25 PM

Write a daemon (basically any continuously-running application) that handles the updates you need.

http://www.google.com/search?q=daemo...ient=firefox-a

TrAvIkK 07-23-2007 03:08 PM

Quote:

daemonize();
while(1) sleep(1); /* run */
Well, so that is the continously handler ^^


All times are GMT -5. The time now is 11:15 PM.