在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 文件的样本。这个文件有点复杂,没仔细看过。
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
分享到:
相关推荐
按内存占用排序和按CPU占用排序的Linux TOP命令.docx
本文定位:想通过python调用top命令获取cpu使用率但暂时没有思路的情况。 如果单纯为了获得cpu的利用率,通过top命令重定向可以轻松实现,命令如下: 复制代码 代码如下: top -bi > cpuHistory.log 或 复制代码 代码...
显示系统当前的进程和其他状况; top是一个动态显示过程,即可以通过用户按键来不断...该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
Linux TOP命令默认是CPU占用排序,按M可以切换到按内存占用排序。这是系统维护和电脑内存维护。可以切换的。不同的用法,达到不同的效果。
linux c程序获取cpu使用率及内存使用情况
文中介绍了几个常用的linux下的命令及方法
Linux下CPU利用率-参考top命令.htm
Linux top 命令详解 Linux top 命令详解 Linux top 命令详解
linux下c/c++ 实现cpu使用率查询,内存使用率查询,当个程序使用查询 主要应用/proc/stat /proc/meminfo /proc/pid/stat /proc/pid/status 等文件中的内容进行计算
linux top命令源码 top命令相当windows的任务管理器,查看资源使用状况。
1、创建存放脚本文件目录 mkdir -p /etc/press chmod 777 /etc/press 2、启动定时任务进程 echo 'systemctl start crond.service...部署成功后查看当前使用率:top -n 1|grep Cpu|awk '{print "当前CPU使用率:"$2"%"}'
top命令经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令,但比较奇怪的是能用好它的人却很少,下面通过WEB服务器的top监控截图,讲述top视图中的各种数据的含义,还包括视图中各进程...
获取CPU使用率,主频和内存大小,使用率等系统实时,硬件参数。Linux上面运行。
C/C++实现linux和Windows查看系统、进程、服务的内存和CPU使用情况的源代码,生成的是静态链接库,Windows和Linux下经测试都可用,查看系统、指定名称的服务、指定名称的进程占用CPU和内存,查看方式不是通过程序中...
top命令和ps命令的基本作用是...该命令可以按CPU使用、内存使用、执行时 间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定。在后面的介绍中将把命令参数和交互命令分开讲述。
go读取Linux下cpu占用率、cpu温度、内存占用率及磁盘占用率
linux进程内存占用排序命令.pdflinux进程内存占用排序命令.pdf
linux下top命令参数解释 linux下top命令参数解释
在linux下有很多命令,可以查看机器的硬件信息。 这里介绍一个查看内存的条数等信息的方法。 相看硬件信息,仅适合ubuntu系列发行版: lshw Linux 下查看内存条数: dmidecode |grep -A16 “Memory Device$” 有关...
Linux系统下启动FTP命令、启动oracle命令、启动Webogic命令、oracle备份命令,这个是我天天得用的东西!自己亲自整理的!