夏令时和Cron

时间:2012-11-02 13:17:28

标签: cron dst

如果Cron的工作计划在凌晨2点和凌晨3点运行,那么这些工作将如何受到夏令时的影响?

当时间向后移动一小时的时间是从上午2:59:59直到凌晨2:00:00吗?这意味着凌晨2点的工作会运行两次而凌晨3点的工作会运行一次?或者是时间首先变为凌晨3:00:00然后凌晨2:00:00导致两个作业都运行两次?

当时间向前移动一小时的时间是从早上1:59:59到凌晨3:00:00导致凌晨2点的工作没有运行而凌晨3点的工作运行一次?或者时间从2:00:00变为凌晨3:00:00,导致两个作业都运行一次?

简而言之,我想知道的是,当上午3点一小时发生一次或两次时失去一小时,凌晨2点就会发生。在Google上查看时,我无法找到任何相关信息。

2 个答案:

答案 0 :(得分:37)

答案取决于您使用的cron的变体/扩展名。某些变体不处理夏令时,导致丢失作业和两次运行。

如果您使用的是Paul Vixie cron,那么它确实可以处理DST更改。根据{{​​3}}:

  

cron每分钟检查一下它的假脱机目录   modtime(或/ etc / crontab上的modtime)已更改

此外,参考夏令时(第二段明确解释了你的答案)

  

夏令时和其他时间变化

   Local time changes of less than three hours, such as  those  caused  by
   the  start or end of Daylight Saving Time, are handled specially.  This
   only applies to jobs that run at a specific time and jobs that are  run
   with  a    granularity  greater  than  one hour.  Jobs that run more fre-
   quently are scheduled normally.

   If time has moved forward, those jobs that would have run in the inter-
   val that has been skipped will be run immediately.  Conversely, if time
   has moved backward, care is taken to avoid running jobs twice.

   Time changes of more than 3 hours are considered to be  corrections  to
   the clock or timezone, and the new time is used immediately.

因此,每当时间转移可能是2:59:59或3:00:00时,cron通过处理情况并仅运行错过的工作来运行,并避免运行已经运行的作业。< / p>

答案 1 :(得分:0)

要清楚地说,这取决于您的住所,如何安排cron作业(需要照顾的Unix cron)和java调度程序,该调度程序可以自行处理!

在美国,时钟在当地时间凌晨2:00更改。在春天,时钟从凌晨1:59向前移动到凌晨3:00;在秋天,时钟从凌晨1:59降到1:00

在欧盟,时钟在世界标准时间凌晨1:00更改。在春季,时钟从上午12:59向前移动到凌晨2:00;在秋天,时钟从凌晨1:59降到1:00

示例:如果您在2020年10月25日今天凌晨1:30拥有Unix cron作业,则您的作业将运行两次

相关问题