Unix/Linux Go Back    


Fedora is an operating system centered on the Linux open source kernel and is developed by the community-supported Fedora Project. Fedora is sponsored by Red Hat. Fedora contains software distributed under a free and open-source license. Fedora focuses on innovation, integrating and adopting new technologies and working closely with various Linux communities. The default desktop in Fedora is the GNOME desktop environment and the default user interface is the GNOME Shell. Other desktop environments include KDE Plasma, Xfce, LXDE, MATE and Cinnamon. Security is an important aspect of Fedora with one specific security feature, Security-Enhanced Linux, implementing a variety of software security policies, including mandatory access controls.

Accuracy of jobs scheduled in cron

Fedora


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-11-2013
faka faka is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 8 October 2014, 9:42 AM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Accuracy of jobs scheduled in cron

Hello, I have several cron jobs scheduled but looking at the results of running I see in some cases it takes more than 2 seconds, is there any way to adjust the accuracy of execution of cron?
Is there any other tool or way to fix the problem?
Sponsored Links
    #2  
Old Unix and Linux 12-11-2013
vbe's Unix or Linux Image
vbe vbe is online now Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 23 January 2017, 3:22 AM EST
Location: Switzerland - GE
Posts: 6,365
Thanks: 255
Thanked 530 Times in 493 Posts
Whats 2 seconds ??? peanuts!
Try to reproduce the same case twice, then you will realise how difficult it can be... for you say nothing about your boxes, what they are running how many users, are there concurent cron jobs scheduled?, any network issue at that time?, was someone printing?
...
Sponsored Links
    #3  
Old Unix and Linux 12-11-2013
faka faka is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 8 October 2014, 9:42 AM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by vbe View Post
Whats 2 seconds ??? peanuts!
Try to reproduce the same case twice, then you will realise how difficult it can be... for you say nothing about your boxes, what they are running how many users, are there concurent cron jobs scheduled?, any network issue at that time?, was someone printing?
...
There I have one job in /etc/crontab

Code:
00 12 * * * root /script.sh

in script.sh

Code:
#!/bin/bash
DATE=`date +%d_%m_%Y_%_A_%T_%N`
DIR=/
echo "$DATE" > $DIR/exec

Result file exec

Code:
11_12_2013_Wednesday_12:00:01_354995160


Code:
executing stat -c "%y" exec
2013-12-11 12:00:01.360761572 -0200

At the same time it`s only 1 job running, I don`t have other jobs.
You can see the delay in the execution of more than 1 second.
There is no network problem or overload in the machine, its a virtual machine vmware running Fedora 11.
    #4  
Old Unix and Linux 12-11-2013
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 January 2017, 8:51 PM EST
Location: NM
Posts: 10,930
Thanks: 474
Thanked 1,005 Times in 934 Posts
Unless you are running realtime this is normal, expected behavior.

crond runs exactly once a minute. It has to check anyone of dozens of cron entries, then exec anything that needs to start.

If you need something to execute to within nanoseconds of a time frame you will have to:
1. write C code with a realtime clock, like clock_gettime()
http://www.users.pjwstk.edu.pl/~jms/...k_gettime.html
2. have cron start your C job 1 minute early, make your C job check time constantly then execute the date command as close to the time you need.

You have a bad assumption I think.

You need to understand on a multiprocessing (not realtime) system that the scheduler tries to give all processes a shot at the cpu. That means all of the services you have running, ex.: on the zoned solaris 10 box I am on that is about 140+ processes. Many of them run at high or realtime priority, like zsched. These can preempt a cronjob at any time.

Do not attempt realtime priority on your own unless you are willing to have your code completely lock up the system. I noticed you seem to have root access, so you could do that. Given your question, this is a fair statement.
Sponsored Links
    #5  
Old Unix and Linux 12-11-2013
faka faka is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 8 October 2014, 9:42 AM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jim mcnamara View Post
Unless you are running realtime this is normal, expected behavior.

crond runs exactly once a minute. It has to check anyone of dozens of cron entries, then exec anything that needs to start.

If you need something to execute to within nanoseconds of a time frame you will have to:
1. write C code with a realtime clock, like clock_gettime()
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/clock_gettime.html
2. have cron start your C job 1 minute early, make your C job check time constantly then execute the date command as close to the time you need.

You have a bad assumption I think.

You need to understand on a multiprocessing (not realtime) system that the scheduler tries to give all processes a shot at the cpu. That means all of the services you have running, ex.: on the zoned solaris 10 box I am on that is about 140+ processes. Many of them run at high or realtime priority, like zsched. These can preempt a cronjob at any time.

Do not attempt realtime priority on your own unless you are willing to have your code completely lock up the system. I noticed you seem to have root access, so you could do that. Given your question, this is a fair statement.
Ok I understand what you're explaining to me, but in practice I have to compile with gcc and run this source to ejectue anticipates the execution of the script before and at the time more precisely to that process is going to run it?

Which is executed by the sample source code program? as I can modify it to run my script.

thanks
Sponsored Links
    #6  
Old Unix and Linux 12-11-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 January 2017, 5:46 PM EST
Location: Saskatchewan
Posts: 21,780
Thanks: 1,027
Thanked 4,038 Times in 3,746 Posts
Quote:
Originally Posted by faka View Post
Ok I understand what you're explaining to me, but in practice I have to compile with gcc and run this source to ejectue anticipates the execution of the script before and at the time more precisely to that process is going to run it?
Come again? I don't think that quite crossed the language barrier.

Why exactly does your compile job need to be run at exactly the correct millisecond?
Sponsored Links
    #7  
Old Unix and Linux 12-11-2013
faka faka is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 8 October 2014, 9:42 AM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
Come again? I don't think that quite crossed the language barrier.

Why exactly does your compile job need to be run at exactly the correct millisecond?
Dear Corona, I need to parse some text files and send the results in more precise or approximate time, 1 second after the data no longer serve because they change constantly.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cron Jobs not running at scheduled time vamshigvk475 Red Hat 2 08-12-2013 09:55 AM
List all daily scheduled cron jobs from my cronfile sureng Shell Programming and Scripting 1 07-27-2010 03:02 PM
where to check scheduled jobs in SunOS dba Solaris 2 03-29-2008 02:34 PM
problem when the script is scheduled to run as cron job forumthreads UNIX for Dummies Questions & Answers 6 07-19-2007 01:27 PM
Jobs scheduled in crontabs are not running after a migration to oracle 9i alexcol UNIX for Advanced & Expert Users 4 03-27-2007 11:35 PM



All times are GMT -4. The time now is 04:35 AM.