现在需要统计CPU使用率前10的进程,根据top版本的不同,使用的command不同,结果的显示格式也不同。
32949016k total — 物理内存总量(32GB)
14411180k used — 使用中的内存总量(14GB)
18537836k free — 空闲内存总量(18GB)
169884k buffers — 缓存的内存量 (169M)
swap交换分区信息,具体信息说明如下:
32764556k total — 交换区总量(32GB)
0k used — 使用的交换区总量(0K)
32764556k free — 空闲交换区总量(32GB)
3612636k cached — 缓冲的交换区总量(3.6GB)
top -n 1
[?25l[0m[H[J[s[999C[999B[6n[uTasks: 349 total, 4 running, 344 sleeping, 0 stopped, 0 zombie另外一个的版本如下:
top -n 1
User 4%, System 7%, IOW 0%, IRQ 0%
User 5 + Nice 0 + Sys 8 + Idle 91 + IOW 0 + IRQ 0 + SIRQ 0 = 104
PID USER PR NI CPU% S #THR VSS RSS PCY Name
4623 root 20 0 8% R 1 9916K 2728K fg top
2 root 20 0 0% S 1 0K 0K fg kthreadd
3 root 20 0 0% S 1 0K 0K fg ksoftirqd/0
4 root 20 0 0% S 1 0K 0K fg kworker/0:0
5 root 0 -20 0% S 1 0K 0K fg kworker/0:0H
6 root 20 0 0% S 1 0K 0K fg kworker/u16:
7 root 20 0 0% S 1 0K 0K fg rcu_preempt
8 root 20 0 0% S 1 0K 0K fg rcu_sched
9 root 20 0 0% S 1 0K 0K fg rcu_bh
10 root RT 0 0% S 1 0K 0K fg migration/0
11 root RT 0 0% S 1 0K 0K fg watchdog/0
12 root RT 0 0% S 1 0K 0K fg watchdog/1
13 root RT 0 0% S 1 0K 0K fg migration/1
14 root 20 0 0% S 1 0K 0K fg ksoftirqd/1
15 root 20 0 0% S 1 0K 0K fg kworker/1:0
16 root 0 -20 0% S 1 0K 0K fg kworker/1:0H
17 root RT 0 0% S 1 0K 0K fg watchdog/2
18 root RT 0 0% S 1 0K 0K fg migration/2
19 root 20 0 0% S 1 0K 0K fg ksoftirqd/2
20 root 20 0 0% S 1 0K 0K fg kworker/2:0
21 root 0 -20 0% S 1 0K 0K fg kworker/2:0H
22 root RT 0 0% S 1 0K 0K fg watchdog/3
23 root RT 0 0% S 1 0K 0K fg migration/3
24 root 20 0 0% S 1 0K 0K fg ksoftirqd/3
25 root 20 0 0% S 1 0K 0K fg kworker/3:0
26 root 0 -20 0% S 1 0K 0K fg kworker/3:0H
27 root RT 0 0% S 1 0K 0K fg watchdog/4
28 root RT 0 0% S 1 0K 0K fg migration/4
使用top统计一段时间的进程信息的源码如下:
https://github.com/feifeiyuan/features/tree/master/C/%E4%BD%BF%E7%94%A8top%E7%BB%9F%E8%AE%A1%E4%B8%80%E6%AE%B5%E6%97%B6%E9%97%B4%E7%9A%84%E8%BF%9B%E7%A8%8B%E4%BF%A1%E6%81%AF