ubuntu查看系统资源占用(内存,cpu和进程)

2023-05-11,,

http://blog.csdn.net/vivian187/article/details/51476043

http://bluexp29.blog.163.com/blog/static/33858148201071534450856/

ubuntu查看系统资源占用内存,cpu和进程)

ubuntu查看系统资源占用(内存,cpu和进程)

大文实验室/大文哥

壹捌陆捌零陆捌捌陆捌贰

21504965 AT qq.com

完成时间:2017/12/11 14:32

版本:V1.0

ubuntu查看系统资源占用(内存,cpu和进程)

2010-08-15 03:44:50|  分类: ubuntu |举报|字号 订阅

linux真是太强大了。

查看ubuntu的资源占用的命令为$: top

top命令就可以查看内存,cpu和进程了,很方便

top:

主要参数:

d:指定更新的间隔,以秒计算。

q:没有任何延迟的更新。如果使用者有超级用户,则top命令将会以最高的优先序执行。

c:显示进程完整的路径与名称。

S:累积模式,会将己完成或消失的子行程的CPU时间累积起来。

s:安全模式。

i:不显示任何闲置(Idle)或无用(Zombie)的行程。

n:显示更新的次数,完成后将会退出to

显示参数:

PID(Process ID):进程标示号。

USER:进程所有者的用户名。

PR:进程的优先级别。

NI:进程的优先级别数值。

VIRT:进程占用的虚拟内存值。

RES:进程占用的物理内存值。

SHR:进程使用的共享内存值。

S:进程的状态,其中S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值是负数。

%CPU:该进程占用的CPU使用率。

%MEM:该进程占用的物理内存和总内存的百分比。

TIME+:该进程启动后占用的总的CPU时间。

Command:进程启动的启动命令名称,如果这一行显示不下,进程会有一个完整的命令行。

top命令:

《空格》:立刻刷新。

P:根据CPU使用大小进行排序。

T:根据时间、累计时间排序。

q:退出top命令。

m:切换显示内存信息。

t:切换显示进程和CPU状态信息。

c:切换显示命令名称和完整命令行。

M:根据使用内存大小进行排序。

W:将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ top

top - 14:31:05 up  5:33,  6 users,  load average: 0.06, 0.25, 0.36

Tasks: 297 total,   1 running, 296 sleeping,   0 stopped,   0 zombie

%Cpu(s):  0.5 us,  0.2 sy,  0.0 ni, 97.9 id,  1.5 wa,  0.0 hi,  0.0 si,  0.0 st

KiB Mem:  16373468 total, 13036828 used,  3336640 free,  3294748 buffers

KiB Swap:  4687868 total,    19660 used,  4668208 free.  5340504 cached Mem

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND

1 root      20   0   33956   2784   1368 S   0.0  0.0   0:01.21 init

2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd

3 root      20   0       0      0      0 S   0.0  0.0   0:00.00 ksoftirqd/0

5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H

7 root      20   0       0      0      0 S   0.0  0.0   0:06.82 rcu_sched

8 root      20   0       0      0      0 S   0.0  0.0   0:01.46 rcuos/0

9 root      20   0       0      0      0 S   0.0  0.0   0:01.41 rcuos/1

10 root      20   0       0      0      0 S   0.0  0.0   0:03.13 rcuos/2

11 root      20   0       0      0      0 S   0.0  0.0   0:06.84 rcuos/3

12 root      20   0       0      0      0 S   0.0  0.0   0:07.38 rcuos/4

13 root      20   0       0      0      0 S   0.0  0.0   0:02.07 rcuos/5

14 root      20   0       0      0      0 S   0.0  0.0   0:01.20 rcuos/6

15 root      20   0       0      0      0 S   0.0  0.0   0:01.16 rcuos/7

16 root      20   0       0      0      0 S   0.0  0.0   0:01.07 rcuos/8

17 root      20   0       0      0      0 S   0.0  0.0   0:01.02 rcuos/9

18 root      20   0       0      0      0 S   0.0  0.0   0:01.13 rcuos/10

19 root      20   0       0      0      0 S   0.0  0.0   0:00.94 rcuos/11

20 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh

21 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/0

22 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/1

23 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/2

24 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/3

25 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/4

26 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/5

27 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/6

28 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/7

29 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/8

30 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/9

31 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/10

32 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/11

33 root      rt   0       0      0      0 S   0.0  0.0   0:00.15 migration/0

34 root      rt   0       0      0      0 S   0.0  0.0   0:00.07 watchdog/0

35 root      rt   0       0      0      0 S   0.0  0.0   0:00.06 watchdog/1

36 root      rt   0       0      0      0 S   0.0  0.0   0:00.13 migration/1

37 root      20   0       0      0      0 S   0.0  0.0   0:00.00 ksoftirqd/1

38 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kworker/1:0

rootroot@cm-System-Product-Name:~$

free

1.作用

free命令用来显示内存的使用情况,使用权限是所有用户。

2.格式

free [-b-k-m] [-o] [-s delay] [-t] [-V]

3.主要参数

-b -k -m:分别以字节(KB、MB)为单位显示内存使用情况。

-s delay:显示每隔多少秒数来显示一次内存使用情况。

-t:显示内存总和列。

-o:不显示缓冲区调节列。

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ free

total       used       free     shared    buffers     cached

Mem:      16373468   13036984    3336484       5892    3294748    5340504

-/+ buffers/cache:    4401732   11971736

Swap:      4687868      19660    4668208

rootroot@cm-System-Product-Name:~$

uptime

18:59:15 up 25 min, 2 users, load average: 1.23, 1.32, 1.21

现在的时间

系统开机运转到现在经过的时间

连线的使用者数量

最近一分钟,五分钟和十五分钟的系统负载

参数: -V 显示版本资讯。

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ uptime

14:31:27 up  5:33,  6 users,  load average: 0.04, 0.24, 0.36

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ uptime -V

uptime from procps-ng 3.3.9

rootroot@cm-System-Product-Name:~$

vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----

r b swpd free buff cache si so bi bo in cs us sy id wa

0 1 24980 10792 8296 47316 5 19 205 52 1161 698 26 3 1 70

1 观察磁盘活动情况

磁盘活动情况主要从以下几个指标了解:

bi:表示从磁盘每秒读取的块数(blocks/s)。数字越大,表示读磁盘的活动越多。

bo:表示每秒写到磁盘的块数(blocks/s)。数字越大,表示写磁盘的活动越多。

wa:cpu等待磁盘I/O(未决的磁盘IO)的时间比例。数字越大,表示文件系统活动阻碍cpu的情况越严重,因为cpu在等待慢速的磁盘系统提供数据。wa为0是最理想的。如果wa经常大于10,可能文件系统就需要进行性能调整了。

2 观察cpu活动情况

vmstat比top更能反映出cpu的使用情况:

us:用户程序使用cpu的时间比例。这个数字越大,表示用户进程越繁忙。

sy:系统调用使用cpu的时间比例。注意,NFS由于是在内核里面运行的,所以NFS活动所占用的cpu时间反映在sy里面。这个数字经常很大的 话,就需要注意是否某个内核进程,比如NFS任务比较繁重。如果us和sy同时都比较大的话,就需要考虑将某些用户程序分离到另外的服务器上面,以免互相 影响。

id:cpu空闲的时间比例。

wa:cpu等待未决的磁盘IO的时间比例。

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

0  0  19660 3336856 3294784 5340496    0    0   104    59   39   53  1  0 98  1  0

rootroot@cm-System-Product-Name:~$

iostat

用于统计CPU的使用情况及tty设备、硬盘和CD-ROM的I/0量

参数:

-c 只显示CPU行

-d 显示磁盘行

-k 以千字节为单位显示磁盘输出

-t 在输出中包括时间戳

-x 在输出中包括扩展的磁盘指标

avg-cpu: %user %nice %sys %iowait %idle

20.25 0.18 2.61 76.39 0.57

%iowait 等待本地I/O时CPU空闲时间的百分比

%idle 未等待本地I/O时CPU空闲时间的百分比

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn

hda 9.86 284.34 84.48 685407 2036

每秒传输数(tps)、每秒512字节块读取数(Blk_read/s)、每秒512字节块写入数(Blk_wrtn/s)和512字节块读取(Blk_read)和写入(Blk_wrtn)的总数量。

rootroot@cm-System-Product-Name:~$

rootroot@cm-System-Product-Name:~$ iostat

Linux 3.13.0-24-generic (cm-System-Product-Name) 2017年12月11日 _x86_64_ (12 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

0.51    0.00    0.16    1.46    0.00   97.86

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn

sda              67.28       284.51        17.32    5702836     347188

sdb              53.33       213.94         0.00    4288301         24

sdc             124.22       575.54       566.31   11536245   11351240

sdd              11.89       172.06       119.55    3448823    2396361

rootroot@cm-System-Product-Name:~$

ubuntu查看系统资源占用(内存,cpu和进程)的相关教程结束。

《ubuntu查看系统资源占用(内存,cpu和进程).doc》

下载本文的Word格式文档,以方便收藏与打印。