Operating System - Tru64 Unix
1828667 Members
1814 Online
109984 Solutions
New Discussion

cron and daylight saving time

 
SOLVED
Go to solution
Aco Blazeski
Regular Advisor

cron and daylight saving time

Hi all,

What happens with cron jobs when time goes back: for example I have a cron job starting every day at 2:15am.

Because of daylight saving time once per year 2:15am will be twice at the same day (between saturday and sunday).

Will crontab job be executed twice in the same day ?
5 REPLIES 5
Johan Brusche
Honored Contributor
Solution

Re: cron and daylight saving time


As always, time on the system is stored and handled as a universal UTC time reference that ALWAYS increments.

So cron also stores the time to execute a job at a unique UTC value, and that value never occurs twice in a day. (except if there is a bug in cron as in old V4.0 versions or if you restart the deamon during the hour of change)

What a human sees is just the human readable representation of the same UTC value and that representation changes depending on zoneinfo and dayligth saving settings.

Regards,
Johan.

_JB_
Ann Majeske
Honored Contributor

Re: cron and daylight saving time

There was a patch in V5.1B Patch Kit 4 (BL25) related to this:

This patch fixes cron scheduling for Daylight Savings time event.
Cron jobs scheduled to run at 2am and 3am were not run when switching
from EST to EDT.( DST change over ). This patch fixes this problem.

Aco Blazeski
Regular Advisor

Re: cron and daylight saving time

Ok,

Thank you people !

Regards
Ivan Ferreira
Honored Contributor

Re: cron and daylight saving time

A question related to this:

What if you don't handle a TIMEZONE with daylight saving on it. If you change the time, let's say, step back one hour, will cron note this?
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Han Pilmeyer
Esteemed Contributor

Re: cron and daylight saving time

Ivan, this is an educated guess.

Timers in UNIX are recorded on the callout queue. The requests on the queue are ordered by when they go off and relative to the current time. When the system time is changed, nothing happens to the callout queue. Which is fine for interval timers which are supposed (for instance) to go off every couple of seconds. But for requests that are originally based on an absolute time, these may go off at the wrong time.

I believe the cron daemon places requests on the callout queue too to handle its job.

Of course it would be better not to have to change the time of the system. When changing time because of daylight savings time, it would be better to setup a timezone. As I suggested in another thread, you can define your own zone. Using timezones nothing has to change (the callout queue is relative to UTC time, which doesn't change).