Linux system management processes

First, what is the process

Program is a static file on disk, the process is a copy of the running program, the process is dynamic, when the program is loaded onto the disk, the program has become a process. The process is the presence of the life cycle, there is preparation, and to terminate run-on

Status Second, the process

status definition
R(Running) Executable state (Running, Ready)
S(Interruptible) Be awake
D(Uninterruptible) Not awake
T(Stopped) Suspended state
Z(Zombie) Dead state

Third, the process of viewing

1, view the process tree

Command pstree, the process is a program that runs the form in the system, by state information view the process, we can understand the system resources occupied by the process of running state of the system is analyzed, adjusted, so that the system remains in a stable operational state
Here Insert Picture Description

2, display the current status of the command execution process

Command ps(Process Status) can list and process information related to this landing system

  • BSD style
a Display terminal associated with the process
x Display all associated with a terminal process
in In order to classify the user to display the process status information
f Hierarchy display process information
O Designated viewing options

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

  • unix style
-e Show all processes
-f Show full format information
-H Information about the structure of the display process hierarchy
-The Specifies an option

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

  • ps command displays information
Field Explanation
USER user name
PUD Process id
%CPU cpu Amount Percent
%MEM Memory Amount Percent
VSZ The virtual memory size
RSS Memory resident set size
TTY Character terminal
STAT Process State
START operation hours
TIME Occupancy cpu time
COMMAND Process Name
3, displays the specified process information

Commandpgrep

u (uid) Displays the specified user process
-U(name) Displays the specified user process
-t(tty) Displays the terminal process
-l Displayed process name
-a Show full format process name
-P(pid) Display child processes specified process

Cut student users view user id and
Here Insert Picture Descriptionview the process id
Here Insert Picture Description
Here Insert Picture Description
display terminal pts / 1 Terminal Process
Here Insert Picture Descriptiondisplay the full format process name
Here Insert Picture Descriptiondisplay child processes
Here Insert Picture Description

4, according to obtain the pid process name

Commandpidof
Here Insert Picture Description

5, dynamic display memory process information

Commandtop

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

top命令
Here Insert Picture Description关闭uptime信息
Here Insert Picture Description关闭task&cpu时间状态1
Here Insert Picture Description关闭task&cpu时间状态2
Here Insert Picture Description关闭task&cpu时间状态3
Here Insert Picture Description调整刷新频率
Here Insert Picture Description
查看student用户进程信息
Here Insert Picture Description
Here Insert Picture Description终止firellwd进程
Here Insert Picture Description

  • 命令参数
-d 指定刷新间隔
-b 以批次方式显示
-n 显示批次数量
  • top显示进程信息详解
    top 系统当期时间
    up 系统运行时常
    user 登录当前系统的用户数量
    load average 平均负载1分钟 5分钟 15分钟的队列长度
    task 任务
    %cpu cpu占用百分比
    mem 物理内存
    swap 交换分区
    其中%cpu中不同参数的含义如下
us 用户空间
sy 内核空间
ni nice调整时间
id 空闲时间
wa 等待io
hi 处理硬件中断
si 处理软件中断
st 被虚拟化程序占用的百分比

四、进程优先级

  • 优先级范围
    在Linux中优先级由固定的数字表示(0-139),其中1-99为实时优先级,数字越大优先级越高,是系统自用的,不用手动处理,100-139为静态优先级,数字越小优先级越高

  • NICE值
    用数字-20-19对应静态优先级,普通用户只能够调低优先级而超级用户可以任意调整
    ps ax -o nice,pid,comm可以查看系统中进程的优先级
    nice -n 优先级数字 程序以及renice -n 优先级 程序pid可以调整进程的优先级

五、进程的前后台调用

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

Here Insert Picture Description
将gedit调回前台,状态变为running
Here Insert Picture Description
不能通过bg指令将vim激活,它会立即回到stopped状态
Here Insert Picture Description

六、信号

  • 可控信号类型
    命令为man 7 signal
可控信号 含义
1 刷新
2 中断键盘输入
3 退出键盘
9 强制结束
15 正常关闭
18 激活进程
19 强制暂停
20 正常暂停

信号指令为

kill 信号 pid
pkill 信号 进程名称

七、系统守护进程

守护进程是linux后台执行的服务进程,是独立于控制终端,周期性地执行某种任务或等待处理某些发生事件,不会随着终端关闭而停止,直到接受停止信息才会结束

  • 守护进程的类型
守护进程类型 使用系统及特点
Sysv init 沿用到rehl6 链式开启
upstart 在rehl6中应用并行启动
systemd rhel7后使用独立完成启动
  • systemctl 用法
指令 用途
systemctl list-unit-files --type=service 查看服务开机运行情况
systemctl list-units --type=service 查看服务当前运行情况
systemctl list-dependencies 查看服务依赖性
systemctl status service 查看服务状态
systemctl start service 开启服务
systemctl stop service 关闭服务
systemctl restart service 重新启动服务
systemctl enable service 设定服务开机启动
systemctl disable service Power shut down service set
systemctl enable --now service Set service start-up and open the service
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

Check the operation of the service startup
Here Insert Picture Descriptionto view the service is currently running situation
Here Insert Picture Descriptionsee sshd service dependency
Here Insert Picture Descriptionview sshd status display is running and the boot does not start
Here Insert Picture Descriptionstopping sshd
Here Insert Picture Descriptionlater when sshd service is closed, the connection between the real and virtual machines break
Here Insert Picture Descriptionopen and view this service sshd when the service state
Here Insert Picture Descriptionafter opening the sshd service real machine and the virtual machine can ssh
Here Insert Picture DescriptionView sshd service status at this time and the process ID of
Here Insert Picture Descriptionthe service after the restart process will change the number of services
Here Insert Picture Descriptionwill not change with the refresh process ID after reload service configuration
Here Insert Picture Descriptionsettings ssh service Power shut down
Here Insert Picture Descriptionthe sshd service is shut down and view the status
Here Insert Picture Descriptionset to open services and open the boot sshd service
Here Insert Picture Descriptionis set to run system-level graphical network model is no
Here Insert Picture DescriptionHere Insert Picture Descriptioncommand init 5can manually turn the graphics mode temporarily
Here Insert Picture Descriptionset the system to run level graphics mode network
Here Insert Picture Description

Published 28 original articles · won praise 0 · Views 776

Guess you like

Origin blog.csdn.net/weixin_43834060/article/details/104037998