现在需要统计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 zombieMem: 1845192k total, 1812816k used, 32376k free, 1700k buffers
Swap: 819196k total, 33736k used, 785460k free, 817484k cached
800%cpu 63%user 0%nice 105%sys 632%idle 0%iow 0%irq 0%sirq 0%host
[7m PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS [0m
3145 u0_a89 16 -4 1.8G 211M 101M S 50.0 11.7 714:24.63 com.imangi.temp+
11384 root 20 0 10M 3.5M 2.7M R 36.8 0.1 0:00.16 top -n 1
365 system -2 -8 101M 21M 16M S 18.4 1.1 229:26.95 surfaceflinger
324 system -3 -8 57M 15M 12M R 10.5 0.8 149:29.16 android.hardwar+
836 system 18 -2 4.3G 197M 149M S 7.8 10.9 130:51.64 system_server
176 root 20 0 0 0 0 S 5.2 0.0 56:29.95 [gsp-core[0]]
10128 root 20 0 0 0 0 S 2.6 0.0 0:11.01 [kworker/u16:3]
643 system RT 0 15M 4.4M 3.7M S 2.6 0.2 30:10.13 android.hardwar+
625 audioserver 20 0 47M 12M 10M S 2.6 0.6 43:16.77 audioserver
314 audioserver 20 0 31M 11M 9.1M S 2.6 0.6 38:25.66 android.hardwar+
185 root RT 0 0 0 0 S 2.6 0.0 5:50.24 [sbuf-6-5]
133 root 20 0 0 0 0 R 2.6 0.0 41:40.97 [sprd-adf-dev]
11381 root 20 0 8.7M 2.9M 2.4M S 0.0 0.1 0:00.02 sh -
11363 root 20 0 10M 3.2M 2.7M S 0.0 0.1 0:00.02 sleep 60
11362 root 20 0 2.0M 4.0K 0 S 0.0 0.0 0:00.00 busybox awk -v +
11361 root 20 0 8.7M 544K 0 S 0.0 0.0 0:00.00 sh /system/bin/+
11355 root 20 0 8.7M 2.9M 2.4M S 0.0 0.1 0:00.04 sh /system/bin/+
11354 root 20 0 8.7M 2.6M 2.2M S 0.0 0.1 0:00.01 sh -c /system/b+
11243 root 20 0 0 0 0 S 0.0 0.0 0:00.08 [kworker/3:0]
另外一个的版本如下:
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