Linux? , is it not difficult to understand the process information? top, ps

1 Take a look at the details of the top command parameters

The Linux top command is used to display the dynamic details of the process in real time.

The first line, [top - ] task queue information

系统时间:07:27:05
运行时间(系统已开机多长时间):up 1:57 min
当前登录用户数:3 user
cpu 平均负载:load average: 0.00, 0.00, 0.00
//三个数值分别为,1分钟,5分钟,15分钟的负载情况

The second line, [Tasks] task (process)

总进程数:150 total, 
正在运行的进程数:1 running, 
睡眠的进程数:149 sleeping, 
停止的进程数: 0 stopped, 
僵尸进程数: 0 zombie

The third line, [Cpu(s)] status information

0.0%us【user space】— 用户空间占用CPU的百分比。
0.3%sy【sysctl】— 系统内核占用CPU的百分比。
0.0%ni【】— 改变过优先级的进程占用CPU的百分比
99.7%id【idolt】— 空闲CPU百分比
0.0%wa【wait】— IO等待占用CPU的百分比
0.0%hi【Hardware IRQ】— 硬中断占用CPU的百分比
0.0%si【Software Interrupts】— 软中断占用CPU的百分比

Fourth line, [Mem] memory status

//total:总内存大小,used:已使用的内存,free:空闲的内存,buffers:缓存的内存大小
1003020k total,   234464k used,   777824k free,    24084k buffers

The fifth line, [Swap] virtual memory swap partition information

//total:交换区总量;used:使用的交换区总量;free:空闲交换区总量;cached:缓存的交换区总量
2031612k total,      536k used,  2031076k free,   505864k cached

Sixth line, blank line

Below the seventh line: status monitoring of each process (task)

PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S —进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位1/100秒
COMMAND — 进程名称(命令名/命令行)

2 Some common interactive commands and use cases of top

top 命令,然后按数字 "1" 可监控每个逻辑CPU的状况
q # 退出程序
m # 切换显示内存信息
M # 根据驻留内存大小进行排序
t # 切换显示进程和CPU状态信息
P # 根据CPU使用百分比大小进行排序
top -d 3 # 表示更新周期为3秒
top -p 11 # 显示进程号为11的进程信息,CPU、内存占用率等

3 What is the difference between buffer and cache in top command?

Stack Exchange discussion on this post
what-do-the-buff-cache-and-avail-mem-fields-in-top-mean

Extract key information

buffers
Memory used by kernel buffers (Buffers in /proc/meminfo)

cache
Memory used by the page cache and slabs  (Cached and SReclaimable in /proc/meminfo)
buff/cache

buff/cache
Sum of buffers and cache

4 ps command common cases and parameter description

The Linux ps (process status) command is used to display the status of the current process, similar to the Windows Task Manager.

ps -aux |grep {process to find}

示例:ps -aux|grep zookeeper
# 最常用的方法是 ps -aux,结合 grep 去查找特定的进程。
#-a 代表 all。
#-u 以用户为主的格式来显示程序状况。
#-x 显示所有程序,不以终端机来区分。

ps -ef |grep {process to find}

示例:ps -ef | grep zookeeper
# -e 和 -a 的意思是一样的,即显示有关其他用户进程的信息,包括那些没有控制终端的进程。
# -f 显示用户id,进程id,父进程id,最近CPU使用情况,进程开始时间等等。

Other common cases of ps command

# 显示 root 用户进程信息
ps -u root

# 结合 less 命令和管道来使用
ps -aux |less

# 根据 CPU 使用来升序排序
ps -aux --sort -pcpu | less

# 根据内存使用来升序排序
ps -aux --sort -pmem | less

# 结合 head,只显示前十个
ps -aux --sort -pcpu,+pmem | head -n 10

5 Summary

Is it not difficult for Linux to understand process status information? Top and ps are enough for general use!

 

Guess you like

Origin blog.csdn.net/weixin_55305220/article/details/123588594