zoukankan      html  css  js  c++  java
  • N天学习一个Linux命令之top

    用途

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

  • 相关阅读:
    课表
    hz评测机的迷惑操作
    联赛模拟测试16
    第四阶段总结
    震惊!OI居然还考天体运动
    简单题 题解
    P2340 [USACO03FALL]Cow Exhibition G题解
    题目分享I 三代目
    题目分享H 三代目
    题目分享G 三代目
  • 原文地址:https://www.cnblogs.com/wadeyu/p/9335094.html
Copyright © 2011-2022 走看看