Linux process management notes full version

The meaning of the process

A process (process) is a static file, a copy of a program, which has a life cycle, preparation period-running period-termination period.

Process status

status definition
R(TASK_RUNNING) Executable state (RUNNING, READING)
S(TASK_INTERRUPTIBLE) Can wake up to sleep
D(TASK_UNINTEERUPTIBLE) Can not wake up sleep state
T(TASK_STOPPED) Suspended state
Z(EXIT_ZOMBIE) Dead state

ps command style

Divided into three types: BSD, unix, GUN
BSD style

	a(显示与终端相关的进程)
	x(显示与终端无关的进程)
	u(以用户未归类信息显示进程状态信息)
	f(层级结构显示进程信息)
	o(显示指定参数的进程信息)

unix style:

	-e(显示所有进程)
	-f(显示完整格式信息)
	-H(层级结构显示进程相关信息)
	-o(查看指定选项信息)

ps command display information

Field Explanation
USER user name
PID Process id
%CPU CPU usage
%MEM Memory usage
VSZ Occupied virtual memory size
RSS Resident memory size
TTY Character terminal
STAT Process status
START operation hours
TIME CPU time
COMMAND Process name

Insert picture description here
ps sorting display information
Display the last 6 lines of the positive order command: ps axo pid,comm,%cpu --sort=%cpu | tail -n 6
Insert picture description here
Display the first 6 lines of the reverse order:ps axo pid,comm,%cpu --sort=-%cpu | head -n 7
clea

Process filtering command pgrep

	pgrep  显示指定进程信息
		   - u  id号           显示指定用户进程
		   - U name            显示指定用户进程
		   - t tty             显示指定终端进程
		   - l                 显示进程名称
		   - a                 显示完整格式进程名
		   - P pid             显示指定进程的子进程
	pidof   进程名              查看进程id

Insert picture description here
Insert picture description here

Usage of top command

  - top 
  -		外部参数
  -			-d                           显示刷新时间
  -			-b                           以批次显示
  -	        -n                           显示批次数量

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

	- top内部参数
	- 		P                       cpu百分比排序
	- 		M                       内存百分比排序
	- 		T                       累计占用cpu时间
	- 		l                       开启或者关闭uptime信息
	- 		t                       开启或关闭task&cpu信息
	- 		s                       调整刷新频率
	- 		k                       终止进程
	- 		u                       查看指定用户进程 

Process priority and NICE value

   - 优先级范围:
   - 	对于Linux来说,优先级被划分为固定个数(0-139)
   -    0-99为实时优先级,数字越大优先级越高,系统自己调用。
   -    100-139,为静态优先级,数字越小,优先级越高。
   - NICE值
   - 	 -20-19对应静态优先级
   - 	关于优先级命令
   - 			nice -n 优先级 程序名     (手动设置程序优先级)
   - 			renice -n 优先级 程序pid   (修改优先级)

Insert picture description here
Insert picture description here

S Process status
I There is a locked space in the memory (the system is not reclaimed during sleep)
N Low priority
< High priority
+ In the foreground (running)
s Top-level process
T stop
S Sleep
R Running

Front and back calls of the process

jobs View background tasks
ctrl+z Break the program into the background and pause the task
bg Activate daemon
fg Call back to the program
& The program runs in the background

Insert picture description here

Daemon systemd and systemctl management commands

The daemon, which shares the program control program for the kernel, usually pid is 1
systemctl management system service

	- systemctl  
	- 		参数:start                 ##开启服务
	- 	          stop                 ##停止服务
	- 			  reload               ##重新加载服务
	- 			  restart              ##重启服务
	-             list-units           ##查看所有服务当前状态
	- 			  list-unit-files      ##查看服务开机状态
	- 			  list-dependencies    ##查看服务依赖性
	- 			  enable               ##开机自启动服务
	- 			  enable --now         ##开机自启动并且现在就开启服务
	- 			  disable 	           ##开机不自启动服务
	- 			  status               ##查看服务状态
	- 			  mask                 ##冻结服务
	-             unmask               ##解冻
	- 			  set-default          ##设定系统运行模式
	- 							       ##multi-user.target         无图形界面
	- 								   ##graphical.target          有图形界面
	- 			  get-default          ##查看系统运行模式
	- 								   ##0关机  1单用户root模式  2-4无图形界面模式  5图形界面模式 6 重启

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Process signals and signal commands

Controllable signal type man 7 signal

Controllable signal meaning
1 Refresh (let the process re-read the configuration, equivalent to systemctl reload)
2 Clear the process data in the memory
3 ctrl+/Pause the use of the mouse
9 Forced end
15 Normal shutdown
18 Activation process
19 Forcibly pause the process
20 Normal pause

Signal command:

	信号指令:
				kill   信号   pid
				killall 信号 进程名
				pkill   信号 进程名字

Login audit in the system

	 - w                 显示正在登陆系统的账号
	 - 					 -i    显示登陆来源
	 - 					 /var/run/utmp
	 - last              登陆成功现在已经退出的
	 - 					 /var/log/wtmp
	 - lastb             试图登录但未成功
	 - 					 /var/log/btmp

Guess you like

Origin blog.csdn.net/qwerty1372431588/article/details/109190741