Accuracy of jobs scheduled in cron

 
Thread Tools Search this Thread
Operating Systems Linux Fedora Accuracy of jobs scheduled in cron
# 1  
Old 12-11-2013
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?
# 2  
Old 12-11-2013
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?
...
# 3  
Old 12-11-2013
Quote:
Originally Posted by vbe
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 12-11-2013
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.
# 5  
Old 12-11-2013
Quote:
Originally Posted by jim mcnamara
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
# 6  
Old 12-11-2013
Quote:
Originally Posted by faka
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?
# 7  
Old 12-11-2013
Quote:
Originally Posted by Corona688
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cron job scheduled is running once, but reports are generating twice

Team, Hope you all are doing fine I have one admin server which is being used dedicately to run cron jobs on hourly basis, fetching the details from Database which is in a different server.These cronjob are run on every hourly/5 minutes basis depending as per end user requirement.The script... (12 Replies)
Discussion started by: whizkidash
12 Replies

2. Red Hat

Cron Jobs not running at scheduled time

I've scheduled few jobs using cron. But they are not running ..... What might be the possible reasons ?? Also tell me how to troubleshoot............. Please help me ....... Thanks in Advance. (2 Replies)
Discussion started by: vamshigvk475
2 Replies

3. Solaris

Cron jobs and at jobs

There are two jobs in Solaris , Cron and at jobs.. I know how to disable or enable cron jobs. How can I enable at jobs and disable it. Kindly help. Rj (2 Replies)
Discussion started by: jegaraman
2 Replies

4. Shell Programming and Scripting

List all daily scheduled cron jobs from my cronfile

I had a cron file named mycron.cron and this file has cron jobs runs through out 365 days (jobs in the file mycron.cron run hourly, daily, weekly, monthly, quarterly and yearly). Is there an easy way to find what are the jobs scheduled today and what time they are scheduled to run? Thanks in... (1 Reply)
Discussion started by: sureng
1 Replies

5. Red Hat

How to find out jobs scheduled by "at" command?

How to find out jobs scheduled by "at" command? (1 Reply)
Discussion started by: johnveslin
1 Replies

6. Solaris

where to check scheduled jobs in SunOS

Hi SunOS Experts where will look up to correct the problem with my sunos, it normally shutdown on its own and reboot itself. i am suspecting that somebody has scheduled it to be doing like that . which file can i look up to correct this problem.this is a server that is suppose to be up 24/7.... (2 Replies)
Discussion started by: dba
2 Replies

7. UNIX for Dummies Questions & Answers

problem when the script is scheduled to run as cron job

Hello, I have problem in executing a shell script. When the shell script is executed at the shell prompt the script works successfully but when the same script is run as a cron job it fails to execute the files called within the shell script. I have scheduled the job in my crontab file as ... (6 Replies)
Discussion started by: forumthreads
6 Replies

8. UNIX for Advanced & Expert Users

Jobs scheduled in crontabs are not running after a migration to oracle 9i

Good Morning. The problem started after tha migration to a newer version of oracle - migration to oracle 9i. Before the migration jobs that were scheduled in crontabs were running ok. but after the migration they are not running. I understand that is not easy to find out what the problem is.... (4 Replies)
Discussion started by: alexcol
4 Replies

9. Shell Programming and Scripting

Conditional File Movement script scheduled using CRON job

Hi All, i am trying to automate a process and have to create a unix script like wise. I have a scenario in which i need to automate a file movement. Below are the steps i need to automate. 1. Check whether a file (Not Fixed name-Pattern search of file say 'E*.dat') is present in a... (2 Replies)
Discussion started by: imu
2 Replies

10. UNIX for Dummies Questions & Answers

Cron Jobs

Where can someone find info on Cron Jobs? Very new to UNIX and the PC I inherited looks to have several of them. Looks like they are some kind of background program that runs automatically at specified times. Would like to delete some of them and know more about them. (6 Replies)
Discussion started by: dereckbc
6 Replies
Login or Register to Ask a Question