Special File Types   «Prev  Next»
Lesson 9Periodic processes
ObjectiveDescribe the main ways to automate a periodic process.

Unix Periodic Processes

Some UNIX processes, such as those associated with the kernel[1], run at all times. However, you will want some applications to run only at specific times. For example, you may want to schedule a backup of your system at only those times when the backup will not adversely affect network performance. Other common tasks include automatically deleting files, using tar[2] on old log files, and scheduling periodic maintenance. Any process that you want to schedule is called a periodic process. One of the standard UNIX daemons[3] that allows you to automate periodic processes is cron.
  • What is cron?
    The cron daemon allows you to perform two functions:
    1. Automate the running of processes and applications
    2. Schedule a certain time for this process to run on a system

    If you configure cron correctly, it will run at boot time, then continue running until you issue a kill command or shut the system down.

Other ways to automate

You can use the at command in much the same way as cron. The at command, however, runs a program at one specified time.
The batch command executes commands entered from standard input. This command functions much like the at command, but does not bog down the system.

Use Unix at command like cron

You can use the at command in much the same way as cron. What is the difference? Whereas you use cron to run a program over time repeatedly, you can use the at command to run a command at one specified time. The syntax for at is
at options time date

Options for the at command include:
  1. -f, which allows at to execute commands inside a text file
  2. -m, which sends an email to the person who scheduled the at command upon completion of the task

You should use a specific time format. For example, if you want to schedule a series of commands contained in the file trail.sh to run at 6:30 p.m., you would enter
at -f trial.sh 0630pm

To obtain a listing of scheduled events, use the atq command. This command also has several options:
  1. -c will sort the list according to when the list was generated by the at command.
  2. -n will display a numbered list of at events.
If you want to remove scheduled at entries, use the atrm command and provide the proper number for the at entry. If you do not know the number, you can first issue the atq command. You will then receive a message such as
1 1999-06-14 18:30 a

This message informs you that you have one command prepared to execute. To remove it, enter
atrm 1

If you have multiple commands in line to execute, enter the number of the command you want to delete from the list. For example, atrm 1 deletes the first command,
atrm 7
deletes the seventh command, and so forth.


Unix batch Command

The batch command executes commands entered from standard input. This command functions much like the at command. However, one key difference exists: at can execute several commands at once, running them in the background. This operation can consume valuable system resources and bog down the server. The batch command runs one process, waits for it to end, then runs another. This empowers the operating system to run batch jobs and tasks at its own discretion, rather than being forced to run them at a specific time. The command syntax for batch is as follows:
batch task list CTRL+D

Although you can issue commands to view crontab and at entries, you must rely on email to receive output for the batch command.

Batch Processes

Batch processes are not associated with any terminal. Rather, they are submitted to a queue, from which jobs are executed sequentially. Unix offers a very primitive batch command, but vendors whose customers require queuing have generally implemented something more substantial. Some of the best known are the (NQS) Network Queuing System[4], developed by NASA and used on many high-performance computers including Crays, as well as several network-based process-scheduling systems from various vendors. These facilities usually support heterogeneous as well as homogeneous networks, and they attempt to distribute the aggregate CPU load evenly among the workstations in the network, a process known as load balancing or load leveling.

Continuing with cron The next lesson will continue our exploration of cron. You will learn how to configure a cron job and get some practice, too.
[1]kernel: The kernel is the core of the UNIX operating system. The kernel remains hidden from typical users.
[2]: tar:The tar utility is an archiving program that allows you to back up directories or files quickly. It is used in many smaller backups and less sophisticated archiving procedures.
[3]daemon: A daemon is a process that is not associated with any terminal and which is dedicated to handling a particular task.
[4](NQS) Network Queuing System: The Network Queueing System(NQS) was created by the need for a UNIX batch and device queueing facility capable of supporting requests in a networked environment of UNIX machines. Furthermore, NQS was developed as part of an effort aimed at tying together a diverse assortment of UNIX based machines into a useful computational complex for the National Aeronautics and Space Administration (NASA).

SEMrush Software 9 SEMrush Banner 9