用途

查看机器负载以及进程资源占用情况,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. PID204特种部队

    特种部队   题目描述 Description 某特种部队接到一个任务,需要潜入一个仓库.该部队士兵分为两路,第一路士兵已经在正面牵制住了敌人,第二路士兵正在悄悄地从后方秘密潜入敌人的仓库.当他们到达 ...

  2. ACM_绝对值排序

    Why Males And Females Apart? Time Limit: 2000/1000ms (Java/Others) Problem Description: In so many o ...

  3. setjmp和longjmp函数

    关于setjmp函数和longjmp函数有话要说,是UNIX高级环境变成看到了10.10信号那章用到了,研究一下,这里作为补充. setjmp(jmp_buf env_buf) 函数可以将当前的运行环 ...

  4. 313 Super Ugly Number 超级丑数

    编写一段程序来寻找第 n 个超级丑数.超级丑数是指其所有质因数都在长度为k的质数列表primes中的正整数.例如,[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] ...

  5. Croppic插件使用介绍-asp.net

    具体的参数使用和基本使用方式请看:http://www.uedsc.com/croppic-api.html 需要说明的几点: 1.支持两种上传方式: (1)先将原图上传至服务器,然后再次将切图信息传 ...

  6. xcode常用的快捷键

    按键 描述 command+[ 左移代码块 command+] 右移代码块 Tab键 接受代码自动完成提示 Esc键 显示代码提示菜单 command+方向left键 移动光标到本行行首 comman ...

  7. PHP中单例模式与工厂模式

    单例模式概念 单例模式是指整个应用中类只有一个对象实例的设计模式. 单例模式的特点 一个类在整个应用中只有一个实例 类必须自行创建这个实例 必须自行向整个系统提供这个实例 php中使用单例模式的原因 ...

  8. x264

    x264 x264  h264  1. x264调用主要过程 x264_param_default():设置参数集结构体x264_param_t的缺省值. x264_picture_alloc():为 ...

  9. ORA-02068,ORA-03135错误解决方法

    今天查看了下ERP DB服务器 alter_<SID>.log日志,发现有个错误 Sat Sep 14 14:49:42 CST 2013 Error 2068 trapped in 2P ...

  10. oracle 用户的操作

    语法: CREATE USER user   IDENTIFIED { BY password              | EXTERNALLY [ AS 'certificate_DN' ]    ...