shell之top

项目地址

procps is a set of command line and full-screen utilities that provide
information out of the pseudo-filesystem most commonly located at /proc.
This filesystem provides a simple interface to the kernel data structures.
The programs of procps generally concentrate on the structures that describe
the processess running on the system.
The following programs are found in procps:

free - Report the amount of free and used memory in the system
kill - Send a signal to a process based on PID
pgrep - List processes based on name or other attributes
pkill - Send a signal to a process based on name or other attributes
pmap - Report memory map of a process
ps - Report information of processes
pwdx - Report current directory of a process
skill - Obsolete version of pgrep/pkill
slabtop - Display kernel slab cache information in real time
snice - Renice a process
sysctl - Read or Write kernel parameters at run-time
tload - Graphical representation of system load average
top - Dynamic real-time view of running processes
uptime - Display how long the system has been running
vmstat - Report virtual memory statistics
w - Report logged in users and what they are doing
watch - Execute a program periodically, showing output fullscreen

使用

  • 输出文本格式

添加 -b 选项,如果不加此选项保存到文件可能会乱码。

# 输出重定向到 top.txt文件
top -b >> top.txt
  • top 基本信息

top - 05:08:55 up  5:10,  6 users,  load average: 0.48, 0.47, 0.44
Tasks: 367 total,   1 running, 366 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.1 us,  1.2 sy,  0.0 ni, 94.9 id,  0.0 wa,  0.3 hi,  0.4 si,  0.0 st
KiB Mem : 32692968 total, 27928012 free,  3207520 used,  1557436 buff/cache
KiB Swap: 16346464 total, 16346464 free,        0 used. 29099444 avail Mem

 PID  USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 7062 root      20   0 24.206g  43488  28592 S   5.6  0.1  17:43.45 bash

第1行:top - 05:08:55 up 5:10, 6 users, load average: 0.48, 0.47, 0.44

任务队列信息,和uptime命令输出的结果一致。最后3各数字分别是1分钟、5分钟、15分钟的系统平均负载。load average数据是每隔5秒钟检查一次活跃的进程数,然后按特定算法计算出的数值。如果这个数除以逻辑CPU的数量,结果高于5的时候就表明系统在超负荷运转了。

第2行:Tasks: 367 total, 1 running, 366 sleeping, 0 stopped, 0 zombie

当前系统的任务或进程。如果top命令使用了-p选项指定了PID,则会显示当前筛选出的任务数量而不是全部数量。

第3行:%Cpu(s): 3.1 us, 1.2 sy, 0.0 ni, 94.9 id, 0.0 wa, 0.3 hi, 0.4 si, 0.0 st

CPU:使用百分比。

us: user 用户空间占用cpu的百分比

sy: system 内核空间占用cpu的百分比

ni: niced 改变过优先级的进程占用cpu的百分比

id: 空闲cpu百分比

wa: IO wait IO等待占用cpu的百分比

hi: Hardware IRQ 硬中断 占用cpu的百分比

si: software 软中断 占用cpu的百分比

st: 被hypervisor偷去的时间,当Linux系统是在虚拟机中运行时,等待CPU资源的时间占比

第4行:KiB Mem : 32692968 total, 27928012 free, 3207520 used, 1557436 buff/cache

内存状态。使用中的内存总量(used)指的是现在系统内核控制的内存数,空闲内存总量(free)是内核还未纳入其管控范围的数量。纳入内核管理的内存不见得都在使用中,还包括过去使用过的现在可以被重复利用的内存,内核并不把这些可被重新使用的内存交还到free中去,因此在linux上free内存会越来越少,但不用为此担心。

第5行:KiB Swap: 16346464 total, 16346464 free, 0 used. 29099444 avail Mem

swap交换分区信息。

第6行:空行

第7行:各进程状态监控

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 — 进程名称(命令名/命令行)

参考

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值