Linux system management process [RHEL8]

1. The process of understanding

Process (Process)

  • Program is a static file
  • Process is a copy of the running program
  • The existence of life cycle (preparation, operation period, the termination period) process
    Process Status
status definition
R(TASK_RUNNING) Executable state (RUNNING, READY)
S(TASK_INTERRUPTIBLE) You can wake to sleep
D (TASK_UNINTERRUPTIBLE) Can not wake up from sleep state
T(TASK_STOPPED) Suspended state
z( EXIT_ZOMBIE) Dead state

2. Process Viewer

pstree
see the process tree -> process is displayed with a tree structure
Here Insert Picture Description

Process and thread
thread is the smallest unit of a running process, the process is the smallest unit of resource allocation of
each process resource is also independent of
all the resources a process is shared by all threads [such as cleaning the house this process sweeping, mopping thread]
systemd -> daemon, under the leadership of its equivalent process, when the system is turned on will automatically open

ps
displays the current command execution process status [each containing two different formats UNIX, BSD]

a Display terminal associated with the process (BSD)
x Display all independent of the terminal processes (BSD)
in User-classified to show the process status information (BSD)
f Hierarchy display process information
O Specify viewing options, pid, comm, nice priority, pri, pcpu, stat, ppid
-e Show all processes (uinx)
-f Show full format information (unix)
-H Information about the structure of the display process hierarchy
-O Specify viewing options, pid, comm, nice,% cpu,% mem, nice
  • Display terminal associated with the process (BSD)
    Here Insert Picture Description
  • Display terminal has nothing to do with the process (BSD)
    Here Insert Picture Description
  • Show all processes
    Here Insert Picture Description
  • Display hierarchy of all processes
    Here Insert Picture Description
  • Displays information about all processes BSD-style
    Here Insert Picture Description
  • Show all processes (uinx)
    Here Insert Picture Description
  • Show full format information (unix)
    Here Insert Picture Description
  • Related information display process hierarchy structure
    Here Insert Picture Description
    in detailHere Insert Picture Description
  • 指定查看选项,pid,comm,nice优先级,pri,pcpu,stat,ppid【BSD风格】
    Here Insert Picture Description
  • 指定查看选项,pid,comm,nice,%cpu,%mem,nice【UNIX风格】
    Here Insert Picture Description
  • ps命令对当前的程序或者某些资源进行排序
    1.根据cpu进行排序
    正序:
    Here Insert Picture DescriptionHere Insert Picture Description
    倒序:
    Here Insert Picture Description倒序显示前6行:
    Here Insert Picture Descriptionps命令显示信息
字段 解释
USER 用户名称
PID 进程id
%CPU cpu用量百分比
%MEM 内存用量百分比
VSZ 占用虚拟内存大小
RSS 常驻内存集大小
TTY 字符终端
STAT 进程状态
START 运行时间
TIME 占用cpu时间
COMMAND 进程名称

pgrep
显示指定信息进程–>注意此环境之下必须要启动所查询的用户进程

命令 解释
-u uid 显示指定用户进程
-U name 显示指定用户进程
-t tty 显示指定终端进程
-l 显示进程名称
-a 显示完整格式进程名
-P pid 显示指定进程的子进程
  • 显示指定用户进程
    1.查看用户 uid
    Here Insert Picture Description
    2.进行筛选
    Here Insert Picture Description
  • 显示进程名称&显示指定用户进程
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200205224350977.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzUxOTk1MQ==,size_16,color_FFFFFF,t_70
  • 显示指定终端进程
    1.查看指定进程的终端
    Here Insert Picture Description
    2.命令查看
    Here Insert Picture Description
  • 显示完整格式进程名
    Here Insert Picture Description
  • 显示指定进程的子进程
    1.创建子进程
    Here Insert Picture Description2.查询
    Here Insert Picture Description
    pgrep
    根据进程名称获取pid
    1.运行一个watch进程
    Here Insert Picture Description2.查看该命令操作所对应的进程id
    Here Insert Picture Descriptiontop
    实时的对于进程信息进行扫描并且显示出来
    1.top内部参数
P cpu百分比排序
M 内存百分比
T 累计占用cpu时间
l 开启/关掉uptime信息
t 开启/关闭task&cpu信息
s 调整刷新频率
k 终止进程
u 查看指定用户进程
  • 查看指定用户进程
    Here Insert Picture DescriptionHere Insert Picture Description
    2.top命令参数
-d 指定刷新间隔
-b 以批次方式显示
-n 显示批次数量
  • 指定刷新间隔
    Here Insert Picture Description
  • 以批次方式显示
    Here Insert Picture Description
  • 显示批次数量
    Here Insert Picture Description
    3.top显示进程信息详解
top 系统当期时间
up 系统运行时常
user 登录当前系统的用户数量
load average 平均负载1分钟 5分钟 15 分钟的队列长度(uptime)
task 任务
%cpu cpu占用百分比
us 用户空间
sy 内核空间
ni nice调整时间
id 空闲时间
wa 等待io
hi 处理硬件中断
si 处理软件中断
st 被虚拟化程序占用的百分比
mem 物理内存
swap 交换分区占用

3.进程优先级

按照资源占用划分进程类

资源使用量 进程类型
cpu使用密集(计算量大) CPU-Bound
I/O使用密集 I/O-Bound

对于cpu使用密集的程序CPU分量会多,那么对于i/o可能会受阻。为了避免这样的情况发生,可以对cpu使用密集多分配,那么也要提高i/o使用密集程序的优先级。

优先级范围

  • 对Linux而言优先级被划分成固定个数(0-139)
  • 1-99为实时有优先级,数字越大优先级越高,不用手动处理系统自用【不能人为进行干预】
  • 100-139为静态优先级,数字越小优先级越高
    NICE值
  • NICE值:-20~19对用静态优先级【对应的是上面优先级范围的100-139】
  • 普通用户只可以调低优先级,超级用户任意调整
  • 关于优先级的命令
    1.ps ax –o nice,pid,comm
    2.nice –n 优先级 程序
    指定优先级进行开启
    Here Insert Picture Description
    3.reince–n 优先级 程序pid
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200206133124649.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzUxOTk1MQ==,size_16,color_FFFFFF,t_70

4.进程前后台调用

进程前后台调用相关命令

指令 含义
jobs 查看后台任务
ctrl+z 将前台运行进程打入后台
bg 激活后台进程
fg 调回进程
& 运行在后台

1.占用终端的进程
Here Insert Picture Description2.将前台运行进程打入后台
ps查看发现已经被暂停,不能使用
Here Insert Picture Description3.查看后台任务
Here Insert Picture Description4.激活后台进程
Here Insert Picture DescriptionHere Insert Picture Description
然而,该操作不能将vim进程运行起来,因为该进程必需要占用终端提供操作界面,才能运行起来
Here Insert Picture Description5.调回进程
Here Insert Picture Description
6.运行在后台
Here Insert Picture Description

5.信号

可控信号类型
man 7 signal

可控信号 含义
1 刷新【让进程再次读取配置】
2 中断键盘输入
3 退出键盘
9 强制结束
15 正常关闭
18 激活进程
19 强制暂停
20 正常暂停
  • 中断键盘输入
    Here Insert Picture Description

  • 退出键盘 ctrl+/
    在看电影时,鼠标就会被隐藏起来

  • 强制暂停
    Here Insert Picture Description

  • 激活进程
    Here Insert Picture Description

  • 正常暂停【被系统阻塞掉,没有效果】
    系统认为这样做不对,hhh
    Here Insert Picture Description

  • 强制结束
    Here Insert Picture DescriptionHere Insert Picture Description
    Here Insert Picture Description信号指令
    kill 信号 pid
    pkill 信号 进程名称

    Here Insert Picture DescriptionHere Insert Picture Description

6.系统守护进程

设置实验环境
1.nm-connection-editor
Here Insert Picture Description2.检查是否设置正确
Here Insert Picture Description3.ssh建立连接
Here Insert Picture Description守护进程的定义

  • 守护进程就是通常讲Daemon进程
  • 是linux后台执行的服务进程
  • 是独立于控制终端、周期性地执行某种任务或等待处理某些发生事件
  • 不会随终端关闭而停止,直到接受停止信息才会结束
    守护进程类型
守护进程类型 使用系统及特点
Sysv init 经典的守护进程类型延用到rhel6
upstart 做到并行启动rhel6中应用
systemd 独立完成启动,rhel7中使用

systemctl用法之一

指令 用途
systemctl list-unit-files 查看服务开机运行情况
systemctl list-units 查看服务当前运行情况
systemctl list dependencies 查看服务依赖性
systemctl status service 查看服务状态
systemctl start service 开启服务
systemctl stop service 关闭服务
systemctl reload service 重新加载服务配置
  • systemctl list-unit-files 查看服务开机运行情况
    Here Insert Picture Description
  • systemctl list dependencies 查看服务依赖性
    Here Insert Picture Description
  • systemctl status service 查看服务状态Here Insert Picture Description
  • systemctl stop service 关闭服务
    Here Insert Picture Description
  • systemctl start service open service
    Here Insert Picture Description
  • systemctl reload service reload service configuration
    Here Insert Picture Descriptionid will not change
    Here Insert Picture Descriptionsystemctl usage of the two
instruction use
systemctl restart service Restart Service
systemctl enable service Set to open service start
systemctl enable –now service Set service start-up and open the service
systemctl disable service Power shut down service set
systemctl set-default multi-user.target Set the system run level is no graphics mode network
systemctl set-default graphical.target Set the system to run level graphics mode network
  • systemctl enable service is set to start service open
    Here Insert Picture Description
  • systemctl disable service set to close boot services
    Here Insert Picture Description
  • systemctl enable -now service set service start-up and open the service
    Here Insert Picture DescriptionHere Insert Picture Description
  • systemctl set-default multi-user.target operating system level setting network mode unpatterned
    Here Insert Picture Descriptionopen without a graphical interface
    Here Insert Picture Description
  • systemctl set-default graphical.target system operation level setting pattern network mode
    Here Insert Picture DescriptionGUI
    Here Insert Picture Description
Published 15 original articles · won praise 4 · Views 385

Guess you like

Origin blog.csdn.net/weixin_43519951/article/details/104184387