Small partners expect to learn some special knowledge of process and task management plans, based on the principle for the IT services industry, small series which lead us to harvest wave.
First, view the process
Second, the control process
Three, at a one-time task settings
Four, crontab periodic task set
First, view the process
1. The relationship between programs and processes
- In the hard disk, an optical disk medium such as executable code and data
- Static code saved
2. Process
- Program code running in CPU and memory
- Dynamic code execution
- Parent and the child: Every process can create one or more processes (a process contains multiple threads)
specific relationship is as follows (red vertical stripe black box is the thread):
3.ps command - View static process statistics
- a: view all processes of the current system
- u: Specifies the user
- x: The user process at all terminals
- -e: show all processes within the information system
- -l: long format process information
- -f: use the full format process information
E.g:
- Command "ps aux": in the form of a simple list of shows process information;
- Command "ps -elf": long format display systems process information, output also includes information PPID column.
4.top command - view the dynamic process of ranking information
- Dynamic information is refreshed once 3s
- Display Tasks, cpu occupancy, memory usage (Mem), swap space (Swap) and other summary information
5.pgrep command - query process information
- Pgrep command
query process PID information based on specific criteria, as follows:
6.pstree command - see the process tree
can output a Linux system tree structure of each process
- -a: Show full information
- -u: list of usernames
- -p: PID number corresponding to the list
Second, the control process
1. The process was started
- Manual start
- Scheduled to start
(1) manual start
- Reception Start: user input commands directly execute the program
- Start backstage: Add the "&" symbol at the end of the command line
(2) scheduling start
- Use the at command to set a one-time task plan
- Use the crontab command to set periodic scheduled tasks
2.改变进程的运行方式(进程的前后台调度)
(1)Ctrl + Z组合键
将当前进程挂起,即调入后台并停止执行
(2)jobs命令
查看处于后台的任务列表
(3)fg命令
将后台进程恢复到前台运行,可指定任务序号
3.终止进程执行
Ctrl + C组成键
中断正在执行的命令
(1)使用kill命令终止进程
- Kill、killall命令
- Kill用于终止指定PID号的进程
- Killall用于终止指定名称的所有进程
- -9选项用于强制终止
(2)使用pkill命令终止进程
pkill命令
根据特定条件终止相应的进程
常用命令选项
- -U :根据进程所属的用户名终止相应进程
- -t :根据进程所在的终端终止相应进程
三、at 一次性任务设置
1.at命令
- 只在指定的时间点执行一次,前提是对应的系统服务atd必须已经运行。
-
一次性计划任务样式:
- 案例:设置在当天的21:30时刻关闭当前系统
四、crontab 周期性任务设置
1.crontab的配置文件和目录
按照预先设置的时间周期(分钟、小时、天.......)重复执行用户指定的命令操作
属于周期性计划任务
主要设置文件
- 全局配置文件,位于文件:/etc/crontab
- 系统默认的设置,位于目录:/etc/cron.*/
- 用户定义的设置,位于文件:/var/spool/cron/用户名
2.使用crontab命令管理用户的计划任务
crontab 选项 [-u 用户名]
常用选项如下:
- -e:编辑计划任务列表
- -u: specifies the management plan task belongs to which user, for the current user default (own)
- -l: displays a list of scheduled tasks
-
-r: delete the list of scheduled tasks
(1) Timing edit formatSpecial representation (2) the value of the time
(3) Application Example
Summary
1. See process command (PS, Top, the pgrep, the pstree)
2 Control Process
initiate the process
scheduling process (ctrl + Z key combination, jobs, bg, fg)
to terminate the process (the kill, killall, the pkill)
3.at Command Set Scheduled tasks
4.crontab scheduled tasks configuration field