cron如何在内部安排工作? [英] How does cron internally schedule jobs?

查看:109
本文介绍了cron如何在内部安排工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现代" cron守护程序如何在内部 安排其工作?有些crond经常通过at安排运行时间.因此,在写出crontab之后,crond:

How do "modern" cron daemons internally schedule their jobs? Some cronds used to schedule a run every so often via at. So after a crontab is written out, does crond:

  1. 解析crontab以获得所有将来的事件以及间隔的睡眠吗?
  2. 每分钟轮询一个汇总的crontab数据库以确定当前时间是否与计划模式匹配?
  3. 其他?

谢谢

推荐答案

在此问题中听到了一些声.不错的RTFC,其中包含一些离散事件模拟论文和Wikipedia:

A few crickets heard in this question. Good 'ol RTFC with some discrete event simulation papers and Wikipedia:

http://en.wikipedia.org/wiki/Cron#Multi-user_capability

此cron使用的算法为 如下:

The algorithm used by this cron is as follows:

  1. 启动时,在以下目录的主目录中查找名为.crontab的文件 所有帐户持有人.
  2. 对于找到的每个crontab文件,确定将来的下一次 每个命令都将运行.
  3. 将这些命令及其命令放到Franta-Maly事件列表中 对应的时间和他们的五个 字段"的时间说明符.
  4. 进入主循环:
  1. On start-up, look for a file named .crontab in the home directories of all account holders.
  2. For each crontab file found, determine the next time in the future that each command is to be run.
  3. Place those commands on the Franta-Maly event list with their corresponding time and their "five field" time specifier.
  4. Enter main loop:
  1. 检查队列开头的任务条目,计算在 将来将要运行.
  2. 睡眠一段时间.
  3. 在唤醒时并确认正确的时间后,在以下位置执行任务 队列的头(在后台) 拥有用户特权的人 创建了它.
  4. 确定将来的下一次运行此命令并放置 再次将其放回事件列表中
  1. Examine the task entry at the head of the queue, compute how far in the future it is to be run.
  2. Sleep for that period of time.
  3. On awakening and after verifying the correct time, execute the task at the head of the queue (in background) with the privileges of the user who created it.
  4. Determine the next time in the future to run this command and place it back on the event list at that time

这篇关于cron如何在内部安排工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆