进程管理
进程查看、调度
一、进程查看
1、进程
进程 process
计算机执行任务的最小单位
2、进程查看
[root@localhost ~]# ps aux
a: all, u: user x: 所有终端
COMMAND: 进程名称
USER: 启动进程的用户,与权限有关
PID: 进程ID
PID=1
centos 7: systemd
centos 6: init
%CPU:进程所占用的CPU百分比
%MEM:进程所占用的内存百分比
RSS: 常驻内存集, 进程所占用的物理内存大小
VSZ: 虚拟内存集, 进程所占用的所有内存大小(物理内存、共享内存、swap)
进程间通信:IPC
1) 利用共享内存
2) 消息队列服务器
zeroMQ, RabbitMQ, Redis
STAT:进程状态
R 正在被CPU执行的进程
T 停止
Z 僵尸进程
# kill 进程ID //杀死进程
# kill -19 进程ID //挂起进程
# kill -18 进程ID //恢复进程运行
D 不可中断的睡眠
S 可中断的睡眠
< 高优先级的进程
CPU优先调度执行、分配相对较长的执行时间
N 低优先级的进程
+ 在前台运行的进程
l 多线程的进程
[root@localhost ~]# ps -elf
PPID 父进程ID
查看CPU的型号
[root@localhost ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
查看进程树
[root@localhost ~]# pstree
systemd─┬─ModemManager───2*[{ModemManager}]
├─NetworkManager───2*[{NetworkManager}]
├─accounts-daemon───2*[{accounts-daemon}]
├─agetty
├─alsactl
├─atd
├─auditd─┬─audispd─┬─sedispatch
│ │ └─{audispd}
│ └─{auditd}
├─avahi-daemon───avahi-daemon
查看进程ID
[root@localhost ~]# pidof vim
二、查看服务器运行状态
1、动态查看进程
# top
M: 按内存占比显示进程
P: 按CPU占比显示进程
1: 显示每个CPU的使用率
top - 16:53:15 up 17 min, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 93 total, 2 running, 91 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016156 total, 825456 free, 83660 used, 107040 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 797692 avail Mem
load average: 0.00, 0.00, 0.00
CPU平均1、5、15分钟的负载
%Cpu(s) CPU的使用率
us 用户进程所占的CPU
sy 内核空间进程所占的CPU
id CPU的空闲率
wa 等待磁盘I/O的进程所占的CPU
Buffer 缓冲区
写数据时,CPU会将数据保存到buffer,再由buffer同步到硬盘
Cache 缓存区
读数据,硬盘数据先读入到cache, CPU从cache中读取处理
2、CPU
1、查看CPU的型号
# lscpu
2、查看CPU负载
[root@localhost ~]# uptime
16:45:13 up 28 min, 2 users, load average: 0.00, 0.01, 0.02
# top
3、查看CPU使用率
[root@localhost ~]# mpstat 1 5
Linux 3.10.0-693.el7.x86_64 (localhost) 12/30/2020 _x86_64_ (4 CPU)
04:47:55 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
04:47:56 PM all 0.00 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00 99.75
04:47:57 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
04:47:58 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
04:47:59 PM all 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 99.75
3、内存
1、查看内存容量使用情况
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 976 146 647 7 182 643
Swap: 2047 0 2047
[root@localhost ~]#
2、查看内存IO
[root@localhost ~]# vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 662228 2116 184472 0 0 15 1 18 18 0 0 100 0 0
0 0 0 662228 2116 184472 0 0 0 0 40 29 0 0 100 0 0
0 0 0 662228 2116 184472 0 0 0 0 31 30 0 0 100 0 0
4、硬盘
1、查看硬盘容量使用情况
[root@localhost ~]# df -hT
2、查看硬盘IO
[root@localhost ~]# iostat 1 5
5、网卡
1、查看网卡IO
[root@node01 ~]# sar -n DEV 1 2
Linux 3.10.0-693.el7.x86_64 (node01) 2019年08月14日 _x86_64_ (2 CPU)
09时03分39秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
09时03分40秒 eth0 2.00 1.00 0.12 0.10 0.00 0.00 0.00
09时03分40秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
rxpck/s 每秒接收的数据包的数量
txpck/s 每秒发送的数据包的数量
rxkB/s 每秒接收的数据量,以kB为单位
txkB/s 每秒发送的数据量,以kB为单位
2、查看网卡的速率
[root@localhost ~]# ethtool ens33
Settings for ens33:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s

浙公网安备 33010602011771号