用途

查看机器负载以及进程资源占用情况,linux系统性能分析工具

用法

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

常用选项

选项 用途
-a 进程列表根据内存占用大小排序
-b 以batch模式运行
-c 显示完整命令名或者不显示,每次执行跟上一次执行记录的状态相反
-d ss.tt (seconds.tenths) 设置结果刷新间隔,默认是3秒
-h, -v 显示命令版本和用法
-H 显示进程所有线程信息和显示单个进程切换,每次执行跟上一次执行记录的状态相反
-i 显示或者不显示空闲的进程
-m VIRT/USED之前显示切换. Reports USED (sum of process rss and swap total count) instead of VIRT
-M 显示内存大小单位
-n number 设置刷新次数,默认为一直刷新
-p 监控指定的进程列表,最多20个,语法如下:-pN1 -pN2 ... or -pN1, N2 [,...]
-s 安全模式运行
-S Cumulative time mode切换
-u 监控指定的用户进程,语法格式:-u somebody
-U -U somebody,This matches real, effective, saved, and filesystem UIDs.

头字段说明

字段 含义
PID 进程id
PPID 父进程id
RUSER Real User Name
UID The effective user ID
USER The effective user name
GROUP The effective group name
TTY The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you’ll see ’?’ displayed.
PR 任务的优先级
NI Nice value
P Last used CPU (SMP)
%CPU CPU usage
TIME CPU Time
TIME+ CPU Time, hundredths
%MEM Memory usage (RES)
VIRT Virtual Image (kb)
SWAP Swapped size (kb)
RES Resident size (kb)
CODE Code size (kb)
DATA Data+Stack size (kb)
SHR Shared Mem size (kb)
nFLT Page Fault count
nDRT Dirty Pages count
S Process Status
Command Command line or Program name
WCHAN Sleeping in Function
Flags Task Flags

SELECTING and ORDERING Columns

After pressing the interactive commands ’f’ (Fields select) or ´o’ (Order fields) you will be shown a screen containing the current fields string followed by names and descriptions for all fields.

SUMMARY Area Fields

The summary area fields describing CPU statistics are abbreviated.

field1 说明
us user mode
sy system mode
ni low priority user mode (nice)
id idle task
wa I/O waiting
hi servicing IRQs
si servicing soft IRQs
st steal (time given to other DomU instances)

交互命令

The commands shown with an asterisk (’*’) are not available in ’Secure mode’, nor will they be shown on the level-1 help screen.

GLOBAL Commands

命令 含义 说明
or 刷新显示 ##
´?´ or ´h´ 显示命令帮助信息 ##
´=´ Exit Task Limits Removes restrictions on which tasks are shown. This command will reverse any ’i’ (idle tasks) and ’n’ (max tasks) commands that might be active. It also provides for an ’exit’ from PID monitoring. See the ’-p’ command-line option for a discussion of PID monitoring. When operating in alternate-display mode this command has a slightly broader meaning.
´A´ Alternate Display Mode toggle This command will switch between full-screen mode and alternate-display mode. See topic 4. ALTERNATE-DISPLAY Mode and the ’G’ interactive command for insight into ´current’ windows and field groups.
´B´ Bold Disable/Enable toggle This command will influence use of the ’bold’ terminfo capability and alters both the summary area and task area for the ´current’ window. While it is intended primarily for use with dumb terminals, it can be applied anytime.
* ´d´ or ´s´ Change Delay Time interval You will be prompted to enter the delay time, in seconds, between display updates. Fractional seconds are honored, but a negative number is not allowed. Entering 0 causes (nearly) continuous updates, with an unsatisfactory display as the system and tty driver try to keep up with top’s demands. The delay value is inversely proportional to system loading, so set it with care. If at any time you wish to know the current delay time, simply ask for help and view the system summary on the second line.
´G´ Choose Another Window/Field Group You will be prompted to enter a number between 1 and 4 designating the window/field group which should be made the ´current’ window. You will soon grow comfortable with these 4 windows, especially after experimenting with alternate-display mode.
´I´ Irix/Solaris Mode toggle When operating in ’Solaris mode’ (’I’ toggled Off), a task’s cpu usage will be divided by the total number of CPUs. After issuing this command, you’ll be informed of the new state of this toggle.
´u´ select a user You will be prompted for a UID or username. Only processes belonging to the selected user will be displayed. This option matches on the effective UID.
´U´ select a user You will be prompted for a UID or username. Only processes belonging to the selected user will be displayed. This option matches on the real, effective, saved, and filesystem UID.
* ´k´ Kill a task You will be prompted for a PID and then the signal to send. The default signal, as reflected in the prompt, is SIGTERM. However, you can send any signal, via number or name. If you wish to abort the kill process, do one of the following depending on your progress: 1) at the pid prompt, just press 2) at the signal prompt, type 0
´q´ Quit ##
* ´r´ Renice a Task You will be prompted for a PID and then the value to nice it to. Entering a positive value will cause a process to lose priority. Conversely, a negative value will cause a process to be viewed more favorably by the kernel.
´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.
´Z´ Change Color Mapping This key will take you to a separate screen where you can change the colors for the ´current’ window, or for all windows. For details regarding this interactive command see topic 3d. COLOR Mapping.

SUMMARY Area Commands

The summary area interactive commands are always available in both full-screen mode and alternate-display mode. They affect the beginning lines of your display and will determine the position of messages and prompts.

命令 含义 说明
´l´ Toggle Load Average/Uptime -- On/Off This is also the line containing the program name (possibly an alias) when operating in full-screen mode or the ´current’ window name when operating in alternate-display mode.
´m´ Toggle Memory/Swap Usage -- On/Off This command affects two summary area lines.
´t´ Toggle Task/Cpu States -- On/Off This command affects from 2 to many summary area lines, depending on the state of the ’1’ toggle and whether or not top is running under true SMP.
´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 massively-parallel SMP machines, it is not restricted to solely SMP environments.

TASK Area Commands

The task area interactive commands are always available in full-screen mode.

The task area interactive commands are never available in alternate-display mode if the ´current’ window’s task display has been toggled Off (see topic 4. ALTERNATE-DISPLAY Mode).

命令 含义 说明
´b´ Bold/Reverse toggle This command will impact how the ’x’ and ’y’ toggles are displayed. Further, it will only be available when at least one of those toggles is On.
´x´ Column Highlight toggle Changes highlighting for the current sort field. You probably don’t need a constant visual reminder of the sort field and top hopes that you always run with ’column highlight’ Off, due to the cost in path-length. If you forget which field is being sorted this command can serve as a quick visual reminder.
´y´ Row Highlight toggle Changes highlighting for "running" tasks. For additional insight into this task state, see topic 2a. DESCRIPTIONS of Fields, Process Status. Use of this provision provides important insight into your system’s health. The only costs will be a few additional tty escape sequences.
´z´ Color/Monochrome toggle Switches the ´current’ window between your last used color scheme and the older form of black-on-white or white-on-black. This command will alter both the summary area and task area but does not affect the state of the ’x’, ’y’ or ’b’ toggles.
´c´ Command Line/Program Name toggle This command will be honored whether or not the ’Command’ column is currently visible. Later, should that field come into view, the change you applied will be seen.
´f´ and ´o´ Fields select or Order fields These keys display separate screens where you can change which fields are displayed and their order. For additional information on these interactive commands see topic 2b. SELECTING and ORDERING Columns.
´H´ Threads toggle When this toggle is On, all individual threads will be displayed. Otherwise, top displays a summation of all threads in a process.
´S´ Cumulative Time Mode toggle When ’Cumulative mode’ is On, each process is listed with the cpu time that it and its dead children have used. When Off, programs that fork into many separate tasks will appear less demanding. For programs like ’init’ or a shell this is appropriate but for others, like compilers, perhaps not. Experiment with two task windows sharing the same sort field but with different ’S’ states and see which representation you prefer. After issuing this command, you’ll be informed of the new state of this toggle. If you wish to know in advance whether or not ’Cumulative mode’ is in effect, simply ask for help and view the window summary on the second line.
´u´ Show Specific User Only You will be prompted to enter the name of the user to display. Thereafter, in that task window only matching User ID’s will be shown, or possibly no tasks will be shown. Later, if you wish to monitor all tasks again, reissue this command but just press at the prompt, without providing a name.
´i´ Idle Processes toggle Displays all tasks or just active tasks. When this toggle is Off, idled or zombied processes will not be displayed. If this command is applied to the last task display when in alternate-display mode, then it will not affect the window’s size, as all prior task displays will have already been painted.
´n´ or ´#´ Set Maximum Tasks You will be prompted to enter the number of tasks to display. The lessor of your number and available screen rows will be used.
´<´ Move Sort Field Left Moves the sort column to the left unless the current sort field is the first field being displayed.
´>´ Move Sort Field Right Moves the sort column to the right unless the current sort field is the last field being displayed.
´F´ or ´O´ Select Sort Field These keys display a separate screen where you can change which field is used as the sort column. If a field is selected which was not previously being displayed, it will be forced On when you return to the top display. However, depending upon your screen width and the order of your fields, this sort field may not be displayable.
´R´ Reverse/Normal Sort Field toggle Using this interactive command you can alternate between high-to-low and low-to-high sorts.

参考资料

【1】man top

N天学习一个Linux命令之top的更多相关文章

  1. 2018/03/11 每日一个Linux命令 之 top

    每日一个Linux命令 之 top   今天在公司测试服务器上跑了一个我写的功能[本地测试过的],但是不知道怎么跑了个无限死循环出来,一个文件的体积在不停的变大,如果不管的话这能行? 上去一看,PHP ...

  2. N天学习一个Linux命令之帮助命令:man

    前言 工作中每天都在使用常用的命令和非常用的命令,忘记了用法或者参数,都会bing一下,然后如此循环.一直没有真正的系统的深入的去了解命令的用法,我决定打破它.以前看到有人,每天学习一个linux命令 ...

  3. 每天一个linux命令之top

    每天一个linux命令之top 转  https://www.linuxprobe.com/chapter-02.html 在图2-6中,top命令执行结果的前5行为系统整体的统计信息,其所代表的含义 ...

  4. N天学习一个Linux命令之free

    用途 查看系统内存(物理/虚拟/缓存/共享)使用情况 用法 free [-b | -k | -m | -g | -h] [-o] [-s delay ] [-c count ] [-a] [-t] [ ...

  5. N天学习一个linux命令之ping

    用途 检测主机是否可到达,也就是说,目标主机是否可以联网,还可以用于检测网速.通过发送ICMP ECHO_REQUEST数据包检测. 用法 ping [options] destination 常用选 ...

  6. N天学习一个linux命令之kill

    用途 用于终止进程 用法 kill [-s signal|-p] [--] pid... kill -l [signal] 说明 1.默认发送信号15(请求终止进程,程序可以捕获,操作系统会杀死没有对 ...

  7. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  8. N天学习一个linux命令之scp

    用途 通过ssh通道,不同主机之间复制文件 用法 scp [options] [user@host:]file1 [user2@host2:]file2 常用参数 -1使用 ssh 1协议 -2使用s ...

  9. 每天学习一个Linux命令-目录

    在工作中总会零零散散使用到各种Linux命令,从今天开始详细的学习一下linux常用命令,坚持每天一个命令,学习的主要参考资料为: 1.竹子-博客(https://www.cnblogs.com/pe ...

随机推荐

  1. Django day30 自定义配置settings文件,分页器,版本控制

    一:自定义配置settings文件 1.有两套配置文件,默认配置,用户的配置 2.如果某个字段,用户配置了,就用用户的,如果没配置,就用默认的 二:分页器 1.三种分页: # 普通分页 from re ...

  2. Akka源码分析-Cluster-ActorSystem

    前面几篇博客,我们依次介绍了local和remote的一些内容,其实再分析cluster就会简单很多,后面关于cluster的源码分析,能够省略的地方,就不再贴源码而是一句话带过了,如果有不理解的地方 ...

  3. Vue中nextTick()解析

    最近,在开发的时候遇到一个问题,让我对vue中nextTick()的用法加深了了解- 下面是在组件中引用的一个拖拽的组件: <vue-draggable-resizable class=&quo ...

  4. [转]linux之at指令详解

    转自:http://www.2cto.com/os/201409/336183.html 指令:at定时任务,指定一个时间执行一个任务,只能执行一次. 语法:# at [参数] [时间]at> ...

  5. SVN系列学习(三)-TortoiseSVN的基本操作

    1.添加(Add) 在ZJHZXS_01中,新建一个记事本,在记事本中写上一下内容,然后保存,再打开,再保存 这个时候,在选中文件夹ZJHZXS_01,并右击[SVN Commit] 提交成功,加了一 ...

  6. Mysql(三):多表查询和存储程序

    今天内容: ● 多表查询(内连接 外连接 子查询) ● 存储程序(存储过程 函数) 多表查询 ​ 同时从多张数据表中查取到需要的数据即是多表查询. 多表查询时,参与查询的表中每条数据进行组合,这种效果 ...

  7. NSNotificationCenter 的使用详解

    通常我们在 iOS 中发生什么事件时该做什么是由 Delegate 实现的,例如 View 加载完后会触发 viewDidLoad.Apple 还为我们提供了另一种通知响应方式,那就是 NSNotif ...

  8. 【转】Java 集合系列05之 LinkedList详细介绍(源码解析)和使用示例

    概要  前面,我们已经学习了ArrayList,并了解了fail-fast机制.这一章我们接着学习List的实现类——LinkedList.和学习ArrayList一样,接下来呢,我们先对Linked ...

  9. JS——轮播图高级版

    需求: 1.页面需要小图标和箭头 2.定时器不断的滑动图片 3.在点击箭头时,图标和图片随即做出响应 核心思想: 1.往左移动到第一张的情况:在第二张移动到第一张时,这个动画效果完成之后,立刻将ul的 ...

  10. JS——模拟百度搜索

    注意事项: 1.for循环移除子节点时,其长度是变化的 2.在文档流中,input.img.p等标签与其他标签有3px的距离,利用左浮动,可以消除3px距离 3.背景图片定位时,第一个值是x轴方向的值 ...