歡迎您光臨本站 註冊首頁

liunx命令行解析top命令響應

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

liunx命令行解析top命令響應

top命令返回如下:
# top -b -n 2
top - 13:13:02 up  4:17,  1 user,  load average: 0.15, 0.05, 0.01
Tasks: 120 total,   1 running, 119 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.1%us,  0.2%sy,  0.0%ni, 97.6%id,  0.9%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:   3925152k total,  3587764k used,   337388k free,   160976k buffers
Swap: 10207224k total,        0k used, 10207224k free,   478228k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                   
11870 root      20   0 15084 1100  832 R  1.8  0.0   0:00.07 top                                                                                                      
    1 root      20   0 19396 1564 1256 S  0.0  0.0   0:01.07 init                                                                                                      
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                                                  
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                                               
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.45 ksoftirqd/0                                                                                               
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                                               
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                                                                                                
    7 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1                                                                                               
    8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1                                                                                               
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.16 ksoftirqd/1                                                                                               
   10 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/1                                                                                                
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                                                                  
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.03 events/1                                                                                                  
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuset                                                                                                   
   14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                                                   
   15 root      20   0     0    0    0 S  0.0  0.0   0:00.01 netns                                                                                                     
   16 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                                                                
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                                                                        
   18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 sync_supers                                                                                               
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 bdi-default                                                                                               
   20 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0                                                                                             
   21 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/1      
現在想使用命令行獲取內存和cpu的信息,需要的結果如下:
%CPU %MEM
1.8  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
求高手指點,謝謝!
《解決方案》

本帖最後由 royplaygame 於 2013-08-22 13:38 編輯

你可以用如下命令:top -b -n 1 | awk '{print $9,$10}'| sed -n '7,$p'
《解決方案》

回復 2# royplaygame
謝謝

   
《解決方案》

回復 2# royplaygame


   
《解決方案》

回復 2# royplaygame

如果是-n 2該如何處理? 不確定行數的。
   
《解決方案》

378110056 發表於 2013-08-22 13:48 static/image/common/back.gif
回復 2# royplaygame

如果是-n 2該如何處理? 不確定行數的。

你的 -n 2是連著做了兩次top, 你可以 -n 1做兩次,就好了

[火星人 ] liunx命令行解析top命令響應已經有503次圍觀

http://coctec.com/docs/service/show-post-213.html