Skip to Content

Top

"Top" 是 Linux 提供的系統監控程式, 我們可以藉這支工具得知目前系統資源的使用狀態,使用方法很簡單直接在 command line 打入 top 即可,不過要怎麼看得懂他提供的資訊才是最重要的關鍵.

    先看一下第一行這些是代表什麼意思
  • top - 14:47:30 up 10 days,  23:24,    2  user,    load average: 0.00, 0.00, 0.00
  • 目前的電腦時間 : 14:47:30 up 
    電腦已經開機經過了多少時間 : 10 days, 23:24 
    目前登入系統的使用者有幾位 : 2 user 
    系統平均負載 : load average: 0.00, 0.00, 0.00 這裡有三個數字,各代表了前 1,5,10 分鐘的平均負載.

    看看第二行各代表什麼意思.

  • Tasks:  107 total,    1 running,    106 sleeping,   0 stopped,   0 zombie
  • 目前所有的 Processes : Tasks: 107 total, 
    目前正在執行的 Processes : 1 running, 
    目前沒在執行的 Processes : 106 sleeping, 會睡著的原因大多是這個 process 需要等待某些 event 產生中斷,才會再度把他叫醒.
    目前已經停止的 Processes : 0 stopped, 
    目前已經死掉的 Processes : 0 zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.

  • Cpu(s): 0.0% us,   50.0% sy,   0.0% ni,   50.0% id,   0.0% wa,   0.0% hi,   0.0% si
  • 0.0% us : User CPU time: 使用者的 Process 所花 CPU 的百分比.
    50.0% sy : System CPU time: Kernel 的 Process 所花 CPU 的百分比.
    0.0% ni : Nice CPU time: CPU 花在使用者的 process 改變優先順序的百分比.
    50.0% id : idle CPU time: 空閑 CPU 的百分比.
    0.0% wa : iowait CPU 花在等待 I/O 的百分比.
    0.0% hi : Hardware IRQ CPU 處理 hardware interrupts 的百分比.
    0.0% si : Software Interrupts CPU 處理 software interrupts 的百分比.

  • Mem:    1033660k total,   287052k used,   746608k free,  28676k buffers
  • 1033660k total : 系統上所有的記憶體大小.
    287052k used : 目前已經使用的記憶體.可以細分為 1.Application Memory  2.Buffered Memory  3.Cached Memory 不過在這一行下只會看到 buffer 一種, Cached 則是列在 Swap 裡面.雖然列在 Swap 裡但他是實實在在的記憶體所佔的空間.
    746608k free : 目前沒有再用的記憶體.
    28676k buffers : 當成是 buffer 的記憶體大小,主要是當資料還來不及儲存到硬碟中暫儲在記憶體的資料..

  • Swap:   2031608k total,   160k used,   2031448k free,   160084k cached
  • 2031608k total : swap 的大小.
    160k used : 目前 swap 使用區塊大小.
    2031448k free : 目前沒有在使用的區塊大小.
    160084k cached : 資料已經由硬碟中讀取出來,提供給應用程式接下來使用,用以提高存取效能.

  • PID   USER   PR   NI   VIRT   RES   SHR S   %CPU   %MEM   TIME+   COMMAND
  • PID : Process ID 
    USER : Processes 所屬的使用者
    PR : Prioary,Processes 優先順序
    NI : Nice 值,越低(-20)代表優先順序越高,越高(+20)代表優先順序越低.
    VIRT :VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment. 
    RES :RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library. 
    SHR :SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES. 
    這三個值寫的很玄,請參考原始網頁.
    http://gentoo-wiki.com/FAQ_Linux_Memory_Management#The_difference_among_VIRT.2C_RES.2C_and_SHR_in_top_output
    S : status 狀態值下
    D : Uninterruptible sleep 這個 Process 已經進入 Sleeping 而且在等待 I/O 的結果.
    R : Runnable 目前正在執行的 Process
    S : Sleeping 目前沒在執行的 Process 
    T : Stopped 目前已經停止的 Process 
    Z : Zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
    %CPU : 目前這個 Process 的 CPU 使用率.
    %MEM : 目前這個 Process 的 Memory 使用率.
    TIME+ : 目前這個 Process 執行所花的時間.
    COMMAND : Process 的名稱