Centos process control and scheduling of 7

This blog will detail the relevant command Liunx system and related processes, can be divided into the following areas:


table of Contents:

  • View the process
  • Process control
  • A one-time task settings
  • Periodic task set

Preface:

Before the official start of blog text, where the first of the process to make a simple overview. What processes are?
Process is really just a piece of code, but we often hear of the program with different yes.
Program code that is stored in the media, save a static code;
and the process is code that runs on the CPU and memory, are dynamic preservation code.

First, view the process

View the process we usually use two commands: PS command and the TOP command, then I detailed explanation for these two commands are:

1, PS command

PS command to list those currently running processes in the system, but different from us behind the TOP command, PS command to show a snapshot of the process is similar, it is static; and dynamic part of the TOP command.
Common command-option combination:

[root@localhost ~]# ps aux

Among them, the meaning behind ps of each option are as follows:

A current list of all processes on the system ----
U ---- mainly used in user mode format output
X ---- all processes at the user terminal

Interface schematic Screenshot:
Centos process control and scheduling of 7
Header "ps aux" the show also has its own list of different meanings, from left to right are:

USER-- behalf of the process under which the user
PID-- process corresponding to the process ID of the representative
CPU utilization% CPU-- behalf of the process of
memory usage% MEM-- behalf of the process of
VSZ-- virtual memory footprint
RSS-- actual physical memory occupation
TTY-- terminal (? the reason here is that usually by local login?)
STAT-- the current process in which the state (different characters represent different states: S represents an interruptible sleep process; s represents the parent process; <indicates high priority processes; process R represents running; L representative of multiple linear process; represents N low priority; the Z representative of zombies; D representative of non-interrupted sleep process; + represents a foreground process)
the START - represents the process start time
TIME-- on behalf of the process CPU time
COMMAND-- process itself name

About viewing a static process table, there is another way to view

[root@localhost ~]# ps -elf

Among them, the meaning behind ps of each option are as follows:

-e ---- Displays the current system all processes
-l ---- is displayed in long format
-f ---- be displayed in full format

A schematic screenshot interface:
Centos process control and scheduling of 7
and "ps aux" as the command header also has different meanings (described herein above through the header will not waste the saliva repeat):

PPID-- the parent process the PID of the
C - CPU utilization
PRI-- user mode process priority (values are higher priority)
Ni - kernel mode process priority (priority value smaller higher)
ADDR-- process status ( "-" means running)
SZ-- the process consumes capacity of a virtual swap partition (swap) of
WCHAN-- the process name in the kernel
TIME-- run time

2, TOP command

And before the same command PS, TOP is used to display the process table, but the PS display is static process table, and then display the TOP is a dynamic process table (refresh rate: refresh once every 3s).
Specific Screenshots:
Centos process control and scheduling of 7

Second, the control process

Just enough to understand the process, the most important thing able to control the process, the following several command is the most used daily process control commands:

(1) pgrep command - query process PID information based on specific criteria

Common command-option combination:

[root@localhost ~]# pgrep -l "log"

Which, "log" keyword for the process. DETAILED Screenshots follows:
Centos process control and scheduling of 7

[root@localhost ~]# pgrep -l -U root -t pts/0 

Wherein, "- U" back to the user, - back "t" is the terminal number:
Centos process control and scheduling of 7

(2) pstree command - List processes information in a tree structure

Common command-option combination:

[root@localhost ~]# pstree -aup

among them,

-a-- indicate Show full information
-u-- shows a display user
-p-- indicate the PID number display

Specific Screenshots follows:
Centos process control and scheduling of 7
In addition, there is a combination of only list only a user's process tree:

[root@localhost ~]# pstree -ap root

"-Ap" behind the associated user name
specific interface screenshot below:
Centos process control and scheduling of 7

(3) kill, killall, pkill command - to terminate the process

Although these three commands are used to terminate the process, but there is still a big difference between the three.

The kill command - usually followed by the PID number, meaning "kill" to specify a process;
killall command - usually behind the keyword with the process, meaning "kill" all processes containing keywords;
pkill command - behind usually with "-U / -t" plus the username / terminal, meaning "kill" all processes in the specified user / terminal.

But all three can use the "-9", the running process "forced" to terminate.
DETAILED Screenshots following three:
Centos process control and scheduling of 7
Centos process control and scheduling of 7
Centos process control and scheduling of 7

Scheduling (4) process

控制进程不光是掌控进程的“生死”,而是为了让进程能够更好的为我们工作,所以调度必不可少。
通常情况,所有键入的指令都会在前台运行,在运行大容量的复制、移动等操作时,前台运行会大大增加等待时间,所以我们可以在平常的指令后加“&”符号将其移入后台执行,并用jobs命令查看,例:

[root@localhost ~]# dd if=/dev/zero of=/mnt/aaa.txt bs=1G count=10 &
[root@localhost ~]# jobs -l

具体示意截图:
Centos process control and scheduling of 7
同样我们也可以用bg命令加序号(上面3987PID的前面就是序号)的方式将后台的进程调回前台执行,并使用“ctrl z”的快捷键将前台进程挂起,并以停止的方式调回后台。

`[root@localhost ~]# fg 1
^Z

具体示意截图:
Centos process control and scheduling of 7

三、at命令——一次性任务

常用选项组合:

[root@localhost ~]# at 17:00 2019-08-26

其中

“17:00”——表示一次性计划执行时间
“2019-08-26”——表示一次性计划执行日期

具体操作案例:
Centos process control and scheduling of 7
完成一次性计划任务后,可以使用atq命令进行查看、使用atrm命令进行对应的删除

[root@localhost ~]# atq
[root@localhost ~]# atrm 对应序列

具体操作截图:
Centos process control and scheduling of 7

四、Crontab命令——周期性任务

at命令被用于创建一次性计划任务,那么相对应的可多次执行的计划任务也同样存在。
Crontab命令
常用的选项:

-u——哪个用户进行执行
-e——对计划任务进行编辑
-l——查看所有的计划任务
-r——删除对应用户下所有周期性任务

选项后的格式为:(分时日月周)
分钟、小时、日期、月份、星期 命令
具体使用见截图:
Centos process control and scheduling of 7
其中各个时间数值的特殊表示方法:

"*": Indicates an arbitrary time within the range of
"": indicates the plurality of discrete intervals of time point
"-": represents a continuous time
"/": frequency specified time interval

Specific application example screenshot:
Centos process control and scheduling of 7

The above is a commonly used system in Liunx various instructions regarding aspects of the process, thank you for reading! ! Let us next blog goodbye.

Guess you like

Origin blog.51cto.com/14484404/2432717