6. Process Management in Linux

6. Process Management in Linux

1. Process and thread:
(1) Process: A process is an execution process of a program. It is a dynamic concept. It is the basic unit for allocating and managing resources during the execution of the program. The process refers to the state of the program when it is running. The process is the program A copy of the process has a corresponding life cycle (preparation period, operation period, termination period).
Thread: The process is the smallest unit of resource call, and the thread is the smallest unit of the process.

(2) The status of the process:

R,(TAKS_RUNNING) Executable state (running, ready)
S,(TASK_INTRRUPTABLE) Wake-up sleep
D,(TASK_UNINTRRUPTABLE) Can not wake up sleep
T,(TASK_STOP) Suspended state
Z,(EXIT_ZOMBIE) Dead state

2. Process viewing command:
(1) Graphical process viewing tool
"gnome-system-monitor" Open the task manager as shown in the figure:
Insert picture description here
(2) ps command: (process viewing command)
[1] Three executions of ps command Mode unix bsd GNU (among which, unix and GNU mode commands have "-" before the command, bsd does not, and GNU parameter commands are usually longer)
[2] The role of each parameter of the ps command:
"a" Process related to the terminal (when the user Process generated after logging in to the system)
"x" Process irrelevant to the terminal
"u" View method of user information classification
"f" Process hierarchical relationship
"o" Display specified parameters pid comm nice pri pcpu ppid stat,user,group

			#-e 显示所有进程
			#-f 显示信息的完整格式
			#-H 显示进程的层级结构
			#-o 显示指定参数
			#--sort= 表示排序

Insert picture description hereDisplay the cpu occupancy rate, command, gid of the program and sort by cpu occupancy rate in reverse order (from large to small);

[3] "ps ax" displays the following information:
PID ---------------process id
TTY ---------------terminal used by the process
STAT--------------Process status
TIME--------------Process occupies cpu time
COMMAND---- Process name

"Ps aux" displays the following information:

display significance
USER Process owner
PID Process id
%CPU The amount of cpu used by the process
%MEM The amount of memory used by the process
VSZ The virtual memory size used by the process
RSS The size of the data in the permanent memory of the process
TTY Terminal used by the process
STAT Process status
START Process running time
TIME CPU time occupied by the process

Insert picture description here
(3) pgrep process filtering command:
【1】

command effect
-u uid Display the specified user process (uid)
-U user Display the specified user process (name)
-t tty Display the specified terminal process
-l Show process name
-a Display the full name of the process
-P Child process

Insert picture description hereFilter the complete names of all processes under westos;
[2] View command of pid:
"pidof comm", which means to view the pid of comm command;

(4) Top dynamic process view command
Insert picture description here[1] The parameters of the top command:
"-d" Specify refresh frequency
"-b" Display in batch mode
"-n" Specify the number of
Insert picture description heredisplayed batches to display top process information, refreshed once per second ; Display top process information, display one page;

[2] Instructions inside top

Internal instructions effect
P cpu sort
M Memory sort
T Cpu cumulative use is often sorted
l Turn off/on uptime information
t Turn off/on cpu&task
s Specify refresh rate
k Operation process
u View the specified user process

Exercise: Output the pids of the top 5 processes in memory usage (Sample output: 001 002 003 …)
Insert picture description here

3.进程优先级
(1)系统中程序的优先级范围: 0–139;
内核自控优先级范围:0-99
用户可控优先级:100-139
即数值越低,进程的优先级越高;
(2)nice值的范围:-20-19(分别对应100–139)pri范围:0-39(越高越优先)
(3)更改进程优先级:
”renice -n -5 43331(pid)“ ,表示更改优先级
“nice -n -5 comm”,表示以指定优先级打开进程
(4)stat 字符表示:
S -----sleeping
< -----优先级高
s -----顶级进程
T-------stop
N-------优先级底
R--------running
“+”-------运行在前台

4.进程前后台调用
“ctrl+z”---------把占用shell的进程打入后台挂起
bg---------------把后台挂起的进程运行起来
fg----------------把后台进程调回前台
& ---------------运行进程在后台
jobs-------------查看当前shell中在后台的所有工作
Insert picture description here
5.进程信息号
(1)进程信号;
1 ----------重新家在系统配置文件(source)
2 ----------清空内存中的进程数据
3 ----------清空内存中的鼠标(ctrl+)
9 ----------强行结束进程(不能被阻塞)
15----------正常关闭进程(会被阻塞)
18-----------运行被暂停的进程
19----------暂停进程(不会被阻塞)
20-----------暂停进程(会被阻塞的)

(2)进程信号控制工具:
“kill 进程信号 pid”
“killall 进程信号 进程名字”(结束该名字的所有进程)
“pkill 进程信号 进程条件”(例如:pkill 9 -u westos)

Insert picture description here
6.systemd守护进程
(1)systemctl命令的用法(控制服务)

start			##开启
stop			##关闭
status			##查看状态
reload			##重新加载
restart			##重新启动服务
enable			##设定服务开机启动
enable --now		##设定服务开机启动并当前开启服务
disable			##设定服务开启不其动
list-units		##查看系统所有服务当前状态
list-unit-files		##查看服务开机状态
list-dependencies	##列出服务依赖性
mask			##冻结服务
unmask			##解锁
set-default		##设定系统运行模式
			    #multi-user.target   无图形网络模式
			    #graphical.target    有图形的网络模式

Insert picture description here查看所有服务的开机自启动状态(static表示不能控制的)
Insert picture description here查看系统当前运行模式为:图形网络模式;

(2) 6 operating levels (modes) of the system (0-6)

			0      关机
			1	   单用户模式(类似window安全模式)
			2	   无图形的网络模式
			3
			4
			5	    有图形的网络模式
			6	    重启

runlevel: view the current operating mode
startx: jump to the x mode without changing the operating mode
init x: change the operating mode, switch to the x operating mode

Guess you like

Origin blog.csdn.net/lb1331/article/details/109248306