CentOS 7 task management processes and plans

First, the process Introduction

Process is a computer program run on a set of data on the activities of the system is the basic unit of resource allocation and scheduling, is the underlying operating system architecture. In the computer architecture for the early design process, the basic process is the execution of the program entity; in contemporary computer architecture design for the thread, the thread is the process vessel. Program is instruction, organization of data and its description of the process is a solid program. In the Linux operating system, after each program start you can create one or more processes.

Relationship Second, processes and procedures

1, the process
procedure is stored in a hard disk, an optical disk medium such as executable code and data, stored is a static code.
2, the process of
the process of program code runs on the CPU and memory, the code is a dynamic execution. Every process can create one or more processes, among these processes are "parent-child relationship", which is called the parent and child.

Third, view the process information

1, ps command - View static process statistics
ps command is used to display a static snapshot contains complete information on the processes currently running. By different command options, you can selectively view process information.
(1) a: all processes information in the current terminal, including processes of other users.
(2) u: Use user-based format of the output process information.
(3) x: Displays the current user process in all the terminal.
(4) -e: display information about all processes within the system.
(5) -l: Use long (Long) format to display process information.
(6) -f: use full (Full) format to display process information.
Figure we execute "ps aux" command to see the show process information in the form of a simple list.
CentOS 7 task management processes and plans
FIG meaning described above the following fields.
USER: name of the user account to start the process.
PID: The process digital ID number in the system, is unique in the current system.
% CPU: The percentage of CPU usage.
% MEM: The percentage of memory usage.
VSZ: occupancy size of the virtual memory (swap space).
RSS: occupy resident memory size (physical memory).
TTY: indicates that the processes are running on which terminal. "?" Represents the unknown or no terminal.
STAT: Displays the current status of the process, S (interruptible sleep), R (run), Z (dead) <(high priority),
N (lower priority), s (the parent process), + (foreground process) .
START: Start time of the process.
TIME: The process of CPU time.
COMMAND: name of the command to start the process.
Figure we execute "ps -elf" command will be long format display systems process information.
CentOS 7 task management processes and plans
Some of the fields defined above with the short format different from FIG follows.
PPID: the current process of the parent process.
PRI: user mode priority.
NI: kernel mode priority (-29 to 19, the lower the value, the higher the priority).
ADDR: "-" means running.
SZ: memory for the swap partition.
WCHAN: the name of the current process in the kernel.
2, top command - view the dynamic process of ranking information
top command will be displayed in full-screen interactive terminal interface in the current process rankings, time tracking including CPU, memory and other system resources occupancy, refreshed every three seconds by default the basic operating system is similar to the task Manager Windows.
CentOS 7 task management processes and plans
Some of the fields defined above is as follows in FIG.
sy: occupied by the kernel.
ni: priority scheduling occupied.
id: idle CPU.
wa: I / O read and write occupancy.
hi: Hard threads occupied.
si: soft thread consumes.
st: virtualization occupied.
buff / cache: cache.
avail Mem: physical memory footprint.
We can press the C key to view the CPU usage, you can also press the M key to view memory usage, press the Q key to exit Review.
3, pgrep command - query process information
pgrep command, you can specify only part of the name of the query process.
Common options:
the -l: while the output of the corresponding process name.
-U: query a specific user process.
-t: query process specific operation of the terminal.
Figure execution "pgrep -l" log "" command to query process name with "process log" and its PID number.
CentOS 7 task management processes and plans
As shown in the implementation process "pgrep -l -U czt" command to query a specific user.
CentOS 7 task management processes and plans
. 4, pstree command - see the process tree
pstree command to output the Linux operating system, the tree structure of each process, a more visually determine the relationship between the processes (parent and the child).
Common options:
-p: PID can list the corresponding number at the same time when the option is used.
-u: option to list the corresponding username.
-a: option to list the complete command information.
Figure we execute "pstree -aup" command to view the current system of tree processes, including information PID number, user name, complete command and other processes corresponding.
CentOS 7 task management processes and plans

Fourth, the process was started

1、手工启动
前台启动:进程在前台运行时,用户必须等到该进程执行结束并退出以后才能继续输入其他命令,大多数命令操作在前台启动运行。
后台启动:启动后台进程需要使用“&”符号,将“&”符号放在要执行命令的最后面,进程启动后会直接放入后台运行,而不占用前台的命令操作界面,方便用户进行其他操作。
如图我们需要复制系统镜像里的目录内容但不影响正常使用,可以执行“cp -r /mnt/Packages/ /opt/ &”命令将该进程放入后台运行。
CentOS 7 task management processes and plans
如果想看后台进程可以执行“jobs -l”命令即可。
CentOS 7 task management processes and plans
2、改变进程的运行方式
(1)挂起进程,即调入后台并停止运行——Ctrl+Z组合键。
如图当我们正在复制目录,然后按下Ctrl+Z组合键就会停止该进程并调入后台。
CentOS 7 task management processes and plans
(2)将后台进程恢复到前台运行,可指定任务号——fg命令。如图执行“fg 1”命令恢复进程值前台运行。
CentOS 7 task management processes and plans
3、终止进程执行
(1)终止指定PID号的进程——kill命令
如图执行“kill -9 42758”命令强行终止任务,可以看到进程任务被杀死。
CentOS 7 task management processes and plans
(2)终止指定名称的所有进程——killall命令
如图我们执行“killall -9 -vim”命令即可终止所有vim的进程。
CentOS 7 task management processes and plans
(3)根据特定条件终止相应的进程——pkill命令
常用选项:
-U:根据进程所属的用户名终止相应进程。
-t:根据进程所在的终端终止相应进程。
如图我们执行“pkill -9 -U czt”俩终止该用户的所有进程,可以看到该用户直接就被踢出到登录界面了。
CentOS 7 task management processes and plans
CentOS 7 task management processes and plans
CentOS 7 task management processes and plans
4、调度启动
(1)一次性计划任务——at命令。
CentOS 7 task management processes and plans
设置一次性计划任务时,在 at 命令行中依次指定计划执行任务的时间、日期作为参数(若只指定时间则表示当天的该时间,若只指定日期则表示该日期的当前时间),确认后将进入带“at>”提示符的任务编辑界面,每行设置一条执行命令,可以依次设置多条语句,最后按 Ctrl+D 组合键提交任务。所设置的命令操作将在计划的时间点被依次执行。
如图先知执行“date”命令获取系统时间,然后执行“at”命令执行的时间、日期等参数并提交任务,在执行“atq”命令查看任务列表。
CentOS 7 task management processes and plans
下面我们执行查看命令去去相应目录下查看任务结果即可。
CentOS 7 task management processes and plans
(2)周期性任务设置——crontab命令
配置文件:/etc/crontab
我们执行“cat /etc/crontab”命令来查看一下配置文件,该文件中包括设置 Shell环境、可执行路径等变量的操作,以及每小时、每天、每周、每月需要执行的任务目录。
CentOS 7 task management processes and plans
分钟:取值为从0到59之间的任意整数
小时:取值为从0到23之间的任意整数
日期:取值为从1到31之间的任意整数
月份:取值为从1到12之间的任意整数
星期:取值为从0到7之间的任意整数,0或7代表星期日
命令:要执行的命令或程序脚本
crontab命令常用选项:
1)-e:编辑计划任务列表。
2) -u: specifies the management plan task belongs to which user, the default for the current user, usually only the root user has permission to use this option (for editing, deleting scheduled tasks to other users).
3) -l: displays a list of scheduled tasks.
4) -r: delete the list of scheduled tasks.
Figure we execute "crontab -e" command to enter the editing task list, press the "I" key to enter the edit mode, enter "49 13 * / usr / bin / cp -r / Home / CZT / opt" and then save and exit. (Similar to the operation and use of the vi editor)
CentOS 7 task management processes and plans
We then execute "crontab -l" to view a list of scheduled tasks.
CentOS 7 task management processes and plans
Here we go under the View Task Results / opt directory.
CentOS 7 task management processes and plans
If we want to delete all scheduled tasks directly execute "crontab -r" can be.
CentOS 7 task management processes and plans

Guess you like

Origin blog.51cto.com/14449521/2432434