在Linux下怎樣讓top命令啓動以後就按內存使用排序(或CPU使用排序)?

top 命令的參數中沒有方法能夠直接作到。windows

 

man top 寫道app

NAME
       top - display Linux tasks

SYNOPSIS
       top -hv | -bcHisS -d delay -n iterations -p pid [, pid ...]

       The traditional switches ’-’ and whitespace are optional.

       -b : Batch mode operation
       -c : Command line/Program name toggle
       -d : Delay time interval as:  -d ss.tt (seconds.tenths)
       -h : Help
       -H : Threads toggle
       -i : Idle Processes toggle
       -n : Number of iterations limit as:  -n number
       -u : Monitor by user as:  -u somebody
       -U : Monitor by user as:  -U somebody
       -p : Monitor PIDs as:  -pN1 -pN2 ...  or  -pN1, N2 [,...]
       -s : Secure mode operation
       -S : Cumulative time mode toggle
       -v : Version
       -M : Detect memory units
less

 

可是能夠在文本全屏界面顯示出來以後使用交互式命令來進行,好比 按大寫M能夠使進程顯示按內存使用排序,按大寫P按CPU使用排序。ui

按大寫W能夠將當前的設置保存到配置文件中,通常就是 ~/.toprc,這樣就能夠在下次啓動top命令是按照設定的排序方式來顯示了。this

man top 寫道spa

         W :Write_the_Configuration_File
              This  will save all of your options and toggles plus the current
              display mode and delay  time.   By  issuing  this  command  just
              before  quitting  top, you will be able restart later in exactly
              that same state.

         1 :Toggle_Single/Separate_Cpu_States  --  On/Off
              This command affects how the ’t’ command’s Cpu States portion is
              shown.  Although this toggle  exists  primarily  to  serve  mas-
              sively-parallel SMP machines, it is not restricted to solely SMP
              environments.

       SORTING of task window
         For  compatibility,  this  top  supports  most of the former top sort
         keys.  Since this is primarily a service to former top  users,  these
         commands do not appear on any help screen.
            command   sorted field                  supported
              A         start time (non-display)      No
              M         %MEM                          Yes
              N         PID                           Yes
              P         %CPU                          Yes
              T         TIME+                         Yes
rest

 

下面是一個 ~/.toprc 文件的樣本。這個文件有點複雜,沒仔細看過。orm

Text代碼  收藏代碼排序

  1. RCfile for "top with windows"           # shameless braggin'  進程

  2. Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0  

  3. Def     fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX  

  4.         winflags=62777, sortindx=13, maxtasks=0  

  5.         summclr=1, msgsclr=1, headclr=3, taskclr=1  

  6. Job     fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX  

  7.         winflags=62777, sortindx=0, maxtasks=0  

  8.         summclr=6, msgsclr=6, headclr=7, taskclr=6  

  9. Mem     fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX  

  10.         winflags=62777, sortindx=13, maxtasks=0  

  11.         summclr=5, msgsclr=5, headclr=4, taskclr=5  

  12. Usr     fieldscur=ABDECGfhijlopqrstuvyzMKNWX  

  13.         winflags=62777, sortindx=4, maxtasks=0  

  14.         summclr=3, msgsclr=3, headclr=2, taskclr=3  

相關文章
相關標籤/搜索