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 offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 25 April 2017, 4:22 PM EDT
Location: Switzerland - GE
Posts: 6,408
Thanks: 270
Thanked 537 Times in 499 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: 25 April 2017, 7:27 PM EDT
Location: NM
Posts: 11,022
Thanks: 515
Thanked 1,045 Times in 968 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: 25 April 2017, 2:08 PM EDT
Location: Saskatchewan
Posts: 22,077
Thanks: 1,070
Thanked 4,151 Times in 3,841 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 08:55 AM
List all daily scheduled cron jobs from my cronfile sureng Shell Programming and Scripting 1 07-27-2010 02:02 PM
where to check scheduled jobs in SunOS dba Solaris 2 03-29-2008 01:34 PM
problem when the script is scheduled to run as cron job forumthreads UNIX for Dummies Questions & Answers 6 07-19-2007 12: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 10:35 PM



All times are GMT -4. The time now is 08:19 PM.