These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Cron-Introduction

Classnotes | UNIX01 | RecentChanges | Preferences

at is a simple program which, when ran, initiates a scheduler for events. Cron, on the other hand, is a daemon which is started during the init process and is always running. It reads schedules of events for system-wide events and individual user events and performs them at recurring intervals. Whereas at is ideal for quick, one-time events, cron is much more suited for things which must happen on a regular basis.

Overview of the cron daemon

The cron daemon is where all timed events are initiated. It is executed upon system initialization and remains active while the system is operating in multi-user mode. Cron wakes up every minute and examines all the stored configuration files, called crontabs, to check each them for commands that may be scheduled to be executed at the current time. Some systems have limits to the number of tasks that can be scheduled during the one minute time period. Most notably, because of the low number, is SGI's IRIX 5.3 which has a limit of 25 jobs.

Besides starting commands each minute, some cron daemons also check to see if its spool directory's last modified time has been updated. If it has, cron will check the modification time on all crontabs and reread the ones that have been modified. Other cron daemons examine new crontab files when first initialized and when the commands crontab or at are executed. This reduces the overhead of checking for new or changed files at regularly scheduled intervals.

Cron searches the crontab spool directory for crontab files. These files are named after user accounts. For instance, if the system administrator is logged into the root accounts creates a crontab file, it will be named root and will be placed in the crontab spool directory. If Bill Wilson, whose username is bill, creates a crontab file it is named bill in the crontab spool directory. When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).

The configuration files used to control the operation of cron are called crontab files or cron tables. These files contain information about the time, date and command to execute. Different versions of UNIX store cron and support files in different locations and may use a slightly different format. Since we are focusing on Linux in this class, the following will be very Linux-centric. As always, consult the man pages for your UNIX if unsure.

NOTE: There are actually many different cron daemons to choose from, and there are vocal supporters for each. In fact, cron daemon discussions usually result in "flame wars" when seasoned UNIX administrators debate the merits of their favorite cron implimentation. In this class, we will almost exclusively be focusing on Vixie Cron and Anacron, because they are the most common default choices in distrubutions.


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 9, 2003 2:29 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.