cpu和内存的查看命令:top
一、问题引入
在使用Linux过程中,会经常查询系统 CPU
和 内存
的使用率。但Linux不像Windows可以直接打开任务管理器UI,直接图形化显示。而Linux必须借助内部命令查询系统cpu和内存的使用率。
由于这是一个经常性的查询动作,有必要记录和记忆一下过程。
二、解决过程
查询到Linux中利用top命令可以显示系统信息。直接在Linux中看看该命令的帮助文档
[root@localhost ~]# man top
NAME
top - display Linux processes
SYNOPSIS
top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]
The traditional switches `-' and whitespace are optional.
DESCRIPTION
The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list
of processes or threads currently being managed by the Linux kernel. The types of system summary information shown and the types,
order and size of information displayed for processes are all user configurable and that configuration can be made persistent across
restarts.
The program provides a limited interactive interface for process manipulation as well as a much more extensive interface for per‐
sonal configuration -- encompassing every aspect of its operation. And while top is referred to throughout this document, you are
free to name the program anything you wish. That new name, possibly an alias, will then be reflected on top's display and used when
reading and writing a configuration file.
执行命令:top
信息分析:
- 第一行
top - 15:55:22 up 16 days, 6:26, 2 users, load average: 0.09, 0.14, 0.14
系统时间 运行16天6小时26分钟 2个用户在线 cpu负载平均值(1分钟,5分钟,15分钟)
- 第二行
Tasks: 183 total, 1 running, 181 sleeping, 0 stopped, 1 zombie
进程总数183 1个运行 181 个睡眠 0 个停止 1个僵持
- 第三行
%Cpu(s): 1.8 us, 0.2 sy, 0.0 ni, 98.0 id, 0.0 wa, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
用户占用 内核占用 空闲
- 第四行
KiB Mem: 7925008 total, 5777012 free, 1430508 used, 717488 buff/cache
物理内存总数 空闲内存 已使用内存 内核缓存
- 第五行
KiB Swap: 8126460 total, 8126460 free, 0 used. 6125488 acail Mem
交换内存总数 空闲内存 已使用内存 缓冲区内存
在top命令后,按下 1
, 可以显示各个cpu的利用率
2024-08-30 新增
跟踪指定进程的变化,执行命令:top -p pid
,即可观察指定pid的cpu和内存占用变化。
三、反思总结
操作系统信息及其管理方面的命令应该进行记忆,并经常性的去使用该命令以达到熟能生巧。