linux - cron 如何在内部安排作业?

标签 linux unix cron crontab scheduler

“现代”cron 守护进程如何在内部 安排他们的工作?一些 crond 用于通过 at 每隔一段时间安排一次运行。因此,在写出 crontab 后,crond:

  1. 解析所有 future 事件的 crontab 和间隔的 sleep ?
  2. 每分钟轮询一次聚合的 crontab 数据库以确定当前时间是否与计划模式匹配?
  3. 其他?

谢谢,

最佳答案

在这个问题中听到了一些蟋蟀。不错的 RTFC,带有一些离散事件模拟论文和维基百科:

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

The algorithm used by this cron is as follows:

  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. 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

关于linux - cron 如何在内部安排作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3982957/

相关文章:

linux - 如何在 linux 中将多个文件合并到一个目录中,以便每个文件数据都放在一个新列中?

windows - 面向 Linux 的 Visual C++ 开发

linux - 从 crontab 中删除过期的 cron 作业

linux - 有效地测试一个端口是否在 Linux 上打开?

Linux Shell 脚本更改文件模式

shell - 在 Unix 中匹配文件字符串

c - 操作系统(Unix)中的新进程创建

linux - crontab 守护进程发送虚假电子邮件

cron - 为什么包含 php mail() 的第五个参数时 cron 作业无法发送电子邮件?

linux - 循环内的 SED 命令