linux如何按照内存排序,在Linux下怎样让top命令启动之后就按内存使用排序(或CPU使用排序)?...

top 命令的参数中没有方法可以直接做到。

man top 写道

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

但是可以在文本全屏界面显示出来之后使用交互式命令来进行,比如 按大写M可以使进程显示按内存使用排序,按大写P按CPU使用排序。

按大写W可以将当前的设置保存到配置文件中,一般就是 ~/.toprc,这样就可以在下次启动top命令是按照设定的排序方式来显示了。

man top 写道

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

下面是一个 ~/.toprc 文件的样本。这个文件有点复杂,没仔细看过。

Text代码  de11e9cbccf3dea65dde0f1d87717aba.png

RCfile for "top with windows"           # shameless braggin'

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

Def     fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX

winflags=62777, sortindx=13, maxtasks=0

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

Job     fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX

winflags=62777, sortindx=0, maxtasks=0

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

Mem     fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX

winflags=62777, sortindx=13, maxtasks=0

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

Usr     fieldscur=ABDECGfhijlopqrstuvyzMKNWX

winflags=62777, sortindx=4, maxtasks=0

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值