在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  

相关文章
相关标签/搜索