Linux Learning Note: process scheduling for Linux systems (Task Scheduler)

Source: Internet
Author: User

Today we learned about the process scheduling of Linux systems, and the process scheduling is to allow the system to automate the list of commands or scripts we have written in the future at some point in time, so that the task can be completed on time even if the user is not near the computer. This will help us to perform the task in a better way, and automatically complete the commands we set when we need to perform the task.

Of course, in order to be able to process scheduling, it is necessary to have a mechanism to identify the time the event occurred and to run the user's expected command, which is implemented in Linux through a specific daemon process. This type of process is:

ATD: The pre-written commands are executed at some point in the future.

Crond: The pre-written commands are repeated at the next qualifying point in time.

We need to see if the daemon is running when we are scheduling the task, so let's look at the following commands to see whether the daemon is running or not:

In the CENTOS6:

]# Service {Atd|crond} status

The result is running or "running", which indicates that it is working correctly

In the CENTOS7:

]# systemctl Status {atd.service|crond.service}

The result is active (running), which indicates that it is working properly

The results of all process scheduling are sent to the user's mailbox in an e-mail message.

Local Email service:
Smtp:simple Mail Transfer Protocol, Simple Mail Transfer Protocol, TCP/25
Pop3:post-office Protocol version 3, Post Office Protocol, third edition, tcp/110
Imap4:internet Mail Access Protocol version 4, Internet Mail Protocol version fourth, tcp/143

The ATD daemon can identify and complete a task plan made by the AT command and Batch command;

AT command:
At, batch, ATQ, Atrm-queue, examine or delete jobs for later execution

At [option] Time
Time:
1.hh:mm [YYYY-MM-DD]
2.noon, midnight, teatime
3.tomorrow
4.now+ #UNIT unit:min, hours, days, weeks, months, years ...

At-defined jobs have the concept of a queue, usually the queue is represented by a single letter, the default is A;
At-q queue_name Time

Options:
-Q QUEUE
-F FILE
-L: View queue, equivalent to ATQ
-D job_id: Clears the specified scheduled job, which is equivalent to ATRM
-C: View the contents of the specified job

Batch command:
The batch command does not need to specify a time when defining a task, it is the system's choice to complete the scheduled task when the system is idle, and the other configuration is the same as at.

Here is the recurring task scheduling schedule: Cron

Cronie software package, providing Crond daemon and other management tools for cron

Cron tasks typically fall into two categories:
System Cron Task:/etc/crontab
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/

# for details see Mans 4 Crontabs

# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * * user-name command to be executed

Attention:
1.
* * * *: Defines the time of day to perform tasks
User-name: User account identity for running this task;
command to be executed: The task command and command line parameters that should be executed;
Note: In order to ensure that the task can be executed accurately, the command is usually filled with absolute path;

2. Separate each field with one or more whitespace characters;

3. The results of the task run are sent directly to the root user by mail;

User Cron Task:/var/spool/cron/username
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/

# for details see Mans 4 Crontabs

# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * command to be executed

Attention:
1.
* * * *: Defines the time of day to perform tasks
command to be executed: The task command and command line parameters that should be executed;
Note: In order to ensure that the task can be executed accurately, the command is usually filled with absolute path;

2. Separate each field with one or more whitespace characters;

3. The results of the task run are sent directly to the user of the publishing task by mail;

Time notation:
1. Specific time: All valid values in the range of valid values for a given point in time;
0 5 3 9 *
2. Wildcard Time: *, meaning "every ..." means, all valid values at a given point in time;
* * * * *
3. Discrete time: At a given point in time, use commas to separate;
0 8,20 * * 1,3,5
4. Continuous time: At a given point in time, use a minus sign to separate;
0 8 * 1-5
5. Step time: At a given point in time, use division sign to separate;
*/2 * * * *
*/7 * * * * This method does not implement scheduled tasks every 7 minutes for intervals;

Attention:
1. The specified step length must be divisible by the value of the time point, otherwise, meaningless;
2. The minimum time unit is minutes, and if you plan to take seconds as a unit of time to perform scheduled tasks, you must rely on other mechanisms.



Linux Learning Note: process scheduling for Linux systems (Task Scheduler)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.