Linux Scheduled Task process management

Source: Internet
Author: User
Tags cpu usage

Crond is a command that Linux uses to execute programs on a regular basis. This task dispatch command is started by default when the operating system is installed. The Crond command periodically checks to see if there is any work to be done and the work will be performed automatically if there is work to be done. You can start and close this service in the following ways:

/sbin/service Crond Start//Startup service

/sbin/service Crond stop//Shut down service

/sbin/service crond Restart//Restart service

/sbin/service Crond Reload//Reload Configuration

1.linux task scheduling is mainly divided into the following two categories:

* System execution: The work to be performed by the system periodically, such as backing up system data, cleaning up the cache

* Personal work: A user's regular work, such as checking the mail server for new letters every 10 minutes, can be set by each user.

2.crontab Command options:

The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:

Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command

CRONTAB-L//list details of a user cron service

Crontab-r//Delete a cron service with no users

CRONTAB-E//Edit a user's cron service

For example, root to view your cron settings: Crontab-u root-l

Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r

When editing the Cron service, the edited content has some formatting and conventions, input: Crontab-u root-e

Enter VI edit mode, the content of the edit must conform to the following format:/1 * ls >>/tmp/ls.txt

3.cron file Syntax

Hour of the week order

0-59 0-23 1-31 1-12 0-6 Command (value range, 0 for Sunday One a row corresponds to a task)

4. Remember the meanings of several special symbols:

"*" represents a number in the range of values,

"/" stands for "every",

"-" represents a number to a number,

"," separate a few discrete numbers

5. To cite a few examples

5 ls//Specify the LS command to execute the first 5 minutes per hour

5 * ls//specify 5:30 to execute LS command per day

7 8 ls//Specify 7:30 minutes of 8th per month to execute the LS command

5 8 6 * ls//specified every June 8 5:30 to execute the LS command

6 0 ls//specify 6:30 per Sunday to execute the LS command [Note: 0 means Sunday, 1 means Week 1, and so on, can also be expressed in English, Sun said Sunday, Mon for Monday and so on. ]

3 10,20 ls//3:30 per month 10th and 20th execute LS command [note: "," used to connect multiple discontinuous periods]

8-11 * ls//25 minutes per day at 8-11 o ' (Note: "-" used to connect consecutive periods of time)

/15 * ls//execute the LS command every 15 minutes [i.e. No. 0 15 30 45 60 minutes per hour Execute LS command]

6 /10 * ls//per month, the LS command is executed every 10 days 6:30 [that is, 1, 11, 21, 31st, 6:30 executes the LS command once. ]

7 * Root run-parts/etc/cron.daily//daily 7:50 executes all executables in the/etc/cron.daily directory as root [note: The Run-parts parameter indicates that Executes all executables in the following directory. ]

6. There are two ways to add a dispatch task:

A. In the command line input: CRONTAB-E and then add the corresponding task, Wq save the disk to exit.

B. Directly edit the/etc/crontab file, or Vi/etc/crontab, to add the appropriate task.
Two processes process Management

The target of Linux process scheduling
1. Efficiency: High efficiency means that more tasks are done at the same time. The scheduler will be executed frequently, so the scheduler should be as efficient as possible;

2. Enhance the interactive performance: under the system equivalent load, but also to ensure that the system response time;

3. Ensuring fairness and avoiding hunger and thirst;

4.SMP Dispatch: The scheduler must support the multi-processing system;

5. Soft real-time scheduling: The system must effectively call the real-time process, but does not guarantee that it will meet its requirements;

Multi-tasking:
Multi-process running at the same time
Preemptive multi-tasking

Process classification:
CPU Bound:cpu Intensive
I/O Bound:io intensive

Process priority:
140:0-139
1-99: Real-time priority, the higher the number, the greater the priority
100-139: The smaller the number, the higher the priority;

PS View the current system execution of the list of threads, in an instantaneous state, not continuous state, continuous state need to use the top name to see more common parameters please use man ps to view
Ps

Show All Process details
PS aux

-U displays a list of processes for a user
Ps-f-U www-data

-C Search process by name or command
Ps-c apache2

--sort based on process CPU usage descending, view top 5 processes-pcpu means descending pcpu ascending
PS aux--sort=-pcpu | Head-5

-F Displays hierarchical relationships of processes with a tree structure, in case of parent-child processes
Ps-f--forest-c apache2

# #显示一个父进程的所有子进程
Ps-o pid,uname,comm-c apache2
PS--ppid 2359

Show all threads of a process-l parameter
Ps-p 3150-l

Displays the execution time of the process-O parameter
PS-E-O Pid,comm,etime

The watch command can be used to capture the PS display process in real time
Watch-n 1 ' ps-e-o pid,uname,cmd,pmem,pcpu--sort=-pmem,-pcpu | Head-15 '

Jobs view the results of the execution of a process run in the background, + represents a current job, the minus table is a job after the current job, the JOBS-L option shows that the pid,jobs status of all tasks can be running, stopped, Terminated, but if the task is terminated (kill), the shell removes the process identity of the task from the list known to the current shell environment, that is, the jobs command displays the task information that is running in the background or suspended in the current shell environment
Jobs

View process numbers for background operations
Jobs-p

View the process number that is now terminated or exited
Jobs-n

Kill command terminates a foreground process can use CTRL + C to kill through top or PS get process ID number kill [-S signal |-P] [-a] process number ...
Sends the specified signal to the corresponding process. Not specifying a model will send Sigterm (15) to terminate the specified process. Process to close process number 12
Kill 12

is equivalent to pressing the CTRL + C key while running the PID 123 process in the foreground
Kill-2 123

If the program can not be terminated with the "-kill" parameter, it sends a signal of Sigkill (9), which will force the end process
Kill-9 123

List all signal names
HUP 1 terminal disconnection
INT 2 Interrupt (with Ctrl + C)
Quit 3 exit (with Ctrl + \)
Term 15 termination
Kill 9 Forced termination
CONT 18 Continuation (contrary to stop, FG/BG command)
Stop 19 paused (with Ctrl + Z)
Kill-l

Gets the value of the specified signal
Kill-l KILL

Kills all processes of the specified user
Kill-u Peidalinux
Kill-9 $ (ps-ef | grep peidalinux)

The command in the background is moved to the foreground to continue running the process 123 to the foreground execution
FG 123

A command that pauses in the background changes to continue execution
BG 123

This command can continue to run the process after you exit the account/close the terminal. Nohup is not hanging. The output is redirected to the Myout.file file
Nohup command > Myout.file 2>&1 &

Linux Scheduled Task process management

Related Article

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.