top (提供正在运行的系统的动态实时视图)

rose1 发表于 2020-07-28 16:37
浏览次数:
在手机上阅读

在类似Unix的操作系统上,顶层程序提供正在运行的系统的动态实时视图。它可以显示系统摘要信息,以及当前由内核管理的进程或线程的列表。所显示的系统摘要信息的类型以及针对任务显示的信息的类型,顺序和大小都是用户可配置的。 本文档涵盖top的Linux版本。

查看英文版

目录

1 top 运行系统环境

2 top 语法

top 运行系统环境

Linux

top 语法

top -hv | -bcHisS -d delay -n limit -u|U user | -p pid -w [cols]

选件

Note

The typically mandatory switches ('-') and even whitespace are completely optional.

-h | -v 帮助/版本

显示库版本和用法提示,然后退出。
-b 批处理模式操作

以“批处理”模式从顶部开始,这对于将输出从顶部发送到其他程序或文件很有用。在这种模式下,top将不接受输入并运行,直到使用-n命令行选项设置的迭代限制或终止为止。
-c 命令行/程序名切换

从顶部开始,最后记住的' c '状态相反。因此,如果top在显示命令行,则该字段将显示程序名称,反之亦然。有关其他信息,请参见' c '交互式命令。
-d interval Delay-time,其中interval表示为:ss.tt(secs.tenths)

指定屏幕更新之间的延迟,并覆盖个人配置文件或启动默认值中的相应值。稍后,可以使用“ d ”或“ s ”交互式命令来更改它。

小数秒是可以接受的,但是不允许使用负数。但是,在所有情况下,如果top以“安全模式”运行,则除非root用户,否则禁止进行此类更改(除非使用了' s '命令行选项)。
-H 线程模式操作

指示top显示单个线程。如果没有此命令行选项,则显示每个进程中所有线程的总和。以后,可以使用“ H ”交互式命令来更改它。
-i 空闲过程切换

从上一个记住的“ i ”状态倒转开始。当此切换为“关闭”时,自上次更新以来未使用任何CPU的任务将不会显示。
-n limit 迭代次数

指定top在结束之前应该产生的最大迭代次数或帧数。
-ppid 监控-PID的模式,具体为:-p PID1 -p PID2 ...或-p PID1,PID2,PID3 ...

监控器仅在指定的进程ID处理。此选项最多可以给出20次,或者您可以提供一个逗号分隔列表,最多包含20个PID。允许将两种形式混合在一起。

pid值为零将被视为顶级程序本身的进程ID(一旦运行)。

仅当您要返回正常操作时才使用此命令行选项,无需退出并重新启动top -只需发出以下任何交互式命令即可:' = ',' u '或' U '。

' p ','u '和' U '命令行选项是互斥的。
-s 安全模式操作

即使强制使用root,也要从强制安全模式开始。通过系统配置文件可以更好地控制此模式(请参阅主题6.文件)。
-S 累积时间切换

从上次记忆的“ S ”状态倒转开始。当“累计时间”模式为On时,将列出每个进程及其已死子进程所使用的cpu时间。有关此模式的更多信息,请参见“ S ”交互式命令。
-u|-U user-id-or-name 用户过滤器模式

仅显示具有与给定用户名或用户名匹配的用户ID或用户名的进程。' -u '选项与有效用户匹配,而' -U '选项与任何用户(真实,有效,保存或文件系统)匹配。

“ p ”,“ u ”和“ U ”命令行选项是互斥的。
-w number Output-width-override

在“批处理”模式下,如果不使用参数top,则将使用COLUMNS =和LINES =环境变量(如果已设置)格式化输出。否则,宽度将固定为最大512列。使用参数时,可以减少或增加输出宽度(最大为512),但是行数被认为是无限的。

在正常显示模式下,如果不带参数使用,top将尝试使用COLUMNS =和LINES =环境变量(如果已设置)格式化输出。带有一个参数,输出宽度只能减小,不能增加。无论是使用环境变量还是使用带有-w的参数,如果不在“批处理”模式下,都不能超过实际端子尺寸。

注意:在不使用此命令行选项的情况下,无论是否在“批处理”模式下,输出宽度始终取决于调用顶部的终端。

摘要显示

通过交互命令分别控制以下每个区域。

正常运行时间和平均负载

本节由一行显示以下内容:

  • 程序或窗口名称,取决于显示模式
  • 自上次启动以来的当前时间和时间长度
  • 用户总数
  • 最近1、5和15分钟的系统平均负载

任务和CPU状态

本节至少由两行组成。在SMP环境中,其他行可以反映各个CPU状态百分比。

  • 第1行显示了全部任务或线程,具体取决于线程模式切换的状态。即总被进一步分类为:运行 ; 睡觉 ; 停下来 ; 僵尸
  • 第2行显示了基于自上次刷新以来的时间间隔的CPU状态百分比。在下面显示两个标签的地方,首先显示最新内核版本的那些标签:

    us, user : 运行非独立用户进程的时间
    sy, system : 运行内核进程的时间
    ni, nice : 运行运行良好的用户进程
    wa, IO-wait : 等待I / O完成的时间
    hi : 服务硬件中断所花费的时间
    si : 服务软件中断所花费的时间
    st : 系统管理程序从此vm窃取的时间

内存使用情况

该部分由两行组成,根据物理内存量,它们可以表示以吉字节(KiB),兆字节(MiB)或千兆字节(GiB)表示的值。

  • 第1行反映了物理内存,分类为:total,used,free,buffers
  • 第2行反映了虚拟内存,分类为:total,used,free,cached

字段/列

下面列出了top的可用过程字段(列)。它们以字母顺序显示。您可以自定义其位置以及是否可以使用“ f ”或“ F ”(字段管理)交互式命令显示它们。

可以选择任何字段作为排序字段,您可以控制将它们从高到低还是从低到高进行排序。

CGROUPS-控制组

进程所属的控制组的名称,如果不适用于该进程,则为“ - ”。

控制组提供在安装定义的进程组之间分配资源(cpu,内存,网络带宽等)的功能。它们使您可以对分配,拒绝,确定优先级,管理和监视这些资源进行细粒度的控制。

一个系统上可以同时存在许多不同的“ cgroup”层次结构,并且每个层次结构都附加到一个或多个子系统上。子系统代表单个资源。

注意

与大多数列不同,“ CGROUPS”字段不是固定宽度的。当显示时,它将与所有其他可变宽度列一起分配所有剩余的屏幕宽度(最多512个字符)。

  1. 代码 -代码大小(KiB)。专用于可执行代码的物理内存量,也称为“文本驻留集”大小或TRS。
  2. COMMAND-命令名称或命令行。显示用于启动任务的命令行或关联程序的名称。您可以使用“ c ” 在命令行和名称之间切换,“ c ”既是命令行选项,也是交互式命令。当选择显示命令行时,不带命令行的进程(例如内核线程)将仅在括号中显示程序名称(例如:“ [mrecoveryd] ”)。如果太长而无法适合该字段的当前宽度,则任何一种显示形式都可能会被截断。该宽度取决于所选的其他字段,它们的顺序和当前屏幕的宽度。“森林视图”显示模式也可能影响此字段。看' V交互式命令以获取有关该模式的其他信息。

    注意:与大多数列不同,“ COMMAND”字段不是固定宽度的。当显示时,它将与所有其他可变宽度列一起分配所有剩余的屏幕宽度(最多512个字符)。
  3. %CPU -CPU使用率 自上次屏幕更新以来,任务在已用CPU时间中所占的份额,表示为总CPU时间的百分比。在真正的SMP环境中,如果“ Irix模式”为“关”,则top将在“ Solaris模式”下运行,在该模式下,任务的CPU使用率将除以CPU总数。您可以使用“ I ”交互式命令切换“ Irix / Solaris”模式。
  4. 数据 -数据+堆栈大小(KiB)。专用于可执行代码以外的物理内存量,也称为“数据驻留集”大小或DRS。
  5. 标志 -任务标志。此列表示任务的当前调度标志,该标志以十六进制表示,并且抑制了零。这些标志已正式记录在中。
  6. GID-组ID。有效的组ID。
  7. GROUP-组名。有效组名。
  8. %MEM-内存使用率(RES)。任务当前使用的可用物理内存份额。
  9. NI-物有所值。任务的价值。良好的负值表示优先级较高,而良好的正值表示优先级较低。该字段为零表示在确定任务的可调度性时不会调整优先级。
  10. nDRT-脏页数。自上次写入辅助存储器以来已被修改的页面数。必须先将脏页写入辅助存储,然后才能将相应的物理内存位置用于其他虚拟页。
  11. nMaj-主要页面错误计数。任务已发生的主要页面错误数。当进程尝试读取或写入其地址空间中当前不存在的虚拟页面时,将发生页面错误。主要页面错误是在使该页面可用时涉及辅助存储访问。
  12. nMin-次要页面错误计数。任务发生的次要页面错误数。当进程尝试读取或写入其地址空间中当前不存在的虚拟页面时,将发生页面错误。较小的页面错误在使该页面可用时不涉及辅助存储访问。
  13. nTH-线程数。与进程关联的线程数。
  14. P-上次使用的CPU(SMP)。代表上次使用的处理器的数字。在真正的SMP环境中,这可能会频繁更改,因为内核有意使用弱亲和力。同样,运行顶部的行为可能会打破这种弱的亲和力,并导致更多进程更频繁地更换CPU(因为对CPU时间的额外需求)。
  15. PGRP-流程组ID。每个进程都是唯一进程组的成员,该进程组用于分配信号,并由终端对输入和输出的请求进行仲裁。创建(派生)流程后,该流程将成为其父流程组的成员。按照惯例,该值等于流程组的第一个成员(称为流程组负责人)的流程ID(请参阅PID)。
  16. PID-流程ID。任务的唯一进程ID,该ID会定期包装,尽管永远不会从零开始。用内核术语来说,它是由“ task_struct”定义的可调度实体。

    此值还可以用作:进程组ID(请参阅PGRP);会话负责人的会话ID(请参阅SID);线程组负责人的线程组ID(请参阅TGID);以及流程组负责人的TTY流程组ID(请参阅TPGID)。
  17. PPID-父流程ID。任务父级的进程ID(pid)。
  18. PR-优先。任务的调度优先级。如果在此字段中看到“ rt”,则表示任务以“实时”调度优先级运行。

    在linux下,实时优先级在某种程度上具有误导性,因为传统上操作本身是不可抢占的。尽管2.6内核可以被抢占,但并非总是如此。
  19. RES-驻留内存大小(KiB)。任务已使用的未交换物理内存。
  20. RUID-真实用户ID。
  21. RUSER-真实用户名。
  22. S-流程状态。任务的状态可以是以下之一:

    'D' = 不间断睡眠
    'R' = 运行
    'S' = 睡眠
    'T' = 跟踪或停止
    'Z' = 僵尸

    显示为正在运行的任务应更恰当地认为是“准备运行”-他们的task_struct在Linux运行队列中表示。即使没有真正的SMP计算机,您也可能会在此状态下看到许多任务,具体取决于top的延迟间隔和合适的值。
  23. SHR-共享内存大小(KiB)。任务可用的共享内存量,通常不是全部驻留。它反映了可能与其他进程共享的内存。
  24. SID-会话ID。会话是进程组的集合(请参阅PGRP),通常由登录外壳建立。新创建的进程加入了其创建者的会话。按照惯例,该值等于会话的第一个成员的进程ID(请参阅PID),该成员称为会话领导者,通常是登录外壳程序。
  25. SUID-已保存的用户ID。保存的用户ID。
  26. SUPGIDS-补充组ID。登录时建立或从任务的父级继承的任何补充组的ID。它们以逗号分隔列表显示。
    注意:与大多数列不同,“ SUPGIDS”字段不是固定宽度的。当显示时,它将与所有其他可变宽度列一起分配所有剩余的屏幕宽度(最多512个字符)。
  27. SUPGRPS-补充组名。登录时建立的或从任务的父级继承的任何补充组的名称。它们以逗号分隔列表显示。

    注意:与大多数列不同,“ SUPGRPS”字段不是固定宽度的。当显示时,它将与所有其他可变宽度列一起分配所有剩余的屏幕宽度(最多512个字符)。
  28. SUSER-保存的用户名。保存的用户名。
  29. 交换 -交换大小(KiB)。任务地址空间的非驻留部分。
  30. TGID-线程组ID。任务所属的线程组的ID。它是线程组负责人的PID。用内核术语,它表示共享“ mm_struct”的那些任务。
  31. TIME -CPU时间。自任务开始以来已使用的总CPU时间。当“累积模式”为“开”时,将列出每个进程及其死子使用的CPU时间。您用“ S ” 切换“累积模式” ,这既是命令行选项又是交互式命令。有关此模式的更多信息,请参见“ S ”交互式命令。
  32. TIME + -CPU时间(百分之一百)。与“时间”相同,但反映了百分之一秒的粒度。
  33. TPGID -Tty流程组ID。连接的tty的前台进程的进程组ID,如果进程未连接到终端,则为-1。按照惯例,该值等于流程组负责人的流程ID(请参阅PID)(请参阅PGRP)。
  34. TTY-控制TTY。控制终端的名称。TTY通常是从其开始该过程并将其用于输入或输出的设备(串行端口,pty等)。但是,无需将任务与终端关联,在这种情况下,您会看到“ ?显示。
  35. UID-用户ID。任务所有者的有效用户标识。
  36. USER-用户名。任务所有者的有效用户名。
  37. VIRT-虚拟内存大小(KiB)任务使用的虚拟内存总量。它包括所有代码,数据和共享库,以及换出的页面和已映射但未使用的页面。
  38. WCHAN-睡眠中的功能 根据内核链接映射('System.map')的可用性,此字段显示任务当前正在休眠的内核函数的名称或地址。正在运行的任务在此列中显示一个破折号(' - ')。

    通过显示此字段,top自己的工作集可以增加700 Kb以上,具体取决于内核版本。如果发生这种情况,减少开销的唯一方法就是停止并重新启动top。

    注意:与大多数列不同,“ WCHAN”字段不是固定宽度的。当显示时,它将与所有其他可变宽度列一起分配所有剩余的屏幕宽度(最多512个字符)。

管理领域

按下交互式命令“ f ”或“ F ”(字段管理)后,将显示以下屏幕:1)当前窗口名称;2)指定的排序字段;3)所有字段及其当前顺序及其描述。屏幕宽度允许的情况下,标有星号的条目是当前显示的字段。

  • 如屏幕上的指示所示,您可以使用向上和向下箭头键在各个字段之间导航。PgUp,PgDn,Home和End键也可用于快速到达第一个或最后一个可用字段。
  • 右箭头键选择要重新定位的字段,而左箭头键或键将提交该字段的位置。
  • “ d ”键或栏可切换字段的显示状态,从而切换是否存在星号。
  • 在“ 小号 ”键表示一个字段作为排序字段。请参阅主题4c。任务区域命令,正在排序以获取有关选择排序字段的更多信息。
  • “ a ”和“ w ”键可用于循环显示所有可用窗口,“ q ”或键可退出“字段管理”。

“字段管理”屏幕还可以用于以全屏模式或交替显示模式更改当前窗口/字段组。返回顶部显示时,按' q '或时所针对的对象将成为当前对象。请参阅主题5。ALTERNATE-DISPLAY设置和“ g ”交互式命令,以了解当前的窗口和字段组。

注意:如果通过“字段管理”屏幕进行了任何字段更改,则任何已水平滚动的窗口都将被重置。但是,任何垂直滚动位置都不会受到影响。请参阅主题5c。滚动窗口以获取有关垂直和水平滚动的其他信息。

互动命令

下面列出的是类别中命令的简要索引。某些命令会多次出现-它们的含义或范围可能会根据发出它们的上下文而有所不同。

全局命令

全局交互式命令始终在全屏模式和交替显示模式下均可用。但是,在“安全模式”下运行时,其中一些交互式命令不可用。

如果您想提前知道自己的顶部是否固定,请寻求帮助并在第二行查看系统摘要。

 or  刷新显示

这些命令将唤醒顶部,并且在收到任何输入后,将重新绘制整个显示。它们还会强制更新任何热插拔的cpu或物理内存更改。

如果您有较大的延迟间隔并希望查看当前状态,请使用这些键之一。
? or h 帮助

有两个可用的帮助级别。第一个将提醒所有基本的交互式命令。如果顶部固定,则该屏幕将被缩写。

Typing 'h' or '?' on that help screen will take you to help for those interactive commands applicable to alternate-display mode.
= Exit-Task-Limits

删除对显示任务的限制。此命令将反转任何可能处于活动状态的“ i ”(空闲任务)和“ n ”(最大任务)命令。它还提供了来自pid监视和用户筛选的“退出”。有关PID监视和有关用户过滤的“ U ”或“ u ”交互式命令的讨论,请参见“ -p ”命令行选项。
此外,使用此命令将重置已滚动的任何窗口。
A 交替显示模式切换

此命令将在全屏模式和交替显示模式之间切换。
B 粗体禁用/启用切换

此命令将影响对“粗体” terminfo功能的使用,并更改当前窗口的摘要区域和任务区域。尽管它主要用于哑终端,但可以随时使用。



注意:当此开关为开且top在单色模式下运行时,整个显示将显示为普通文本。因此,除非“ x ”或“ y ”切换使用反向来强调,否则将无法通过视觉确认它们是否均匀。

d or s * Change-Delay-Time-interval

将提示您输入显示更新之间的延迟时间(以秒为单位)。

小数秒是可以接受的,但是不允许使用负数。输入0会导致(几乎)连续更新,并且由于系统和tty驱动程序试图满足最高需求而显示不令人满意。延迟值与系统负载成反比,因此请谨慎设置。

如果您想随时了解当前延迟时间,请寻求帮助并在第二行查看系统摘要。
g 选择另一个窗口/字段组

将提示您输入1到4之间的数字,指定应该成为当前窗口的字段组。您将很快对这4个窗口感到满意,尤其是在尝试了交替显示模式之后。
H 线程模式切换启用

此切换时,将在所有可见任务窗口中为所有进程显示单个线程。否则,top显示每个进程中所有线程的总和。
I Irix / Solaris模式切换

在“ Solaris模式”下操作(“ I ”切换为“关闭”),任务的CPU使用率将除以CPU总数。发出此命令后,系统将告知您此切换开关的新状态。
k * Kill-a-task

将提示您输入PID,然后发送信号。提示中反映的默认信号是SIGTERM。但是,您可以通过数字或名称发送任何信号。



如果要中止kill过程,请根据您的进度执行以下操作之一:

1) 在pid提示符下,只需按

2) 在信号提示符下,键入0
q 退出
r * Renice-a-Task

将提示您输入PID,然后将其值设置为nice。输入正值将导致进程失去优先级。相反,负值将导致内核更有利地查看进程。
W 配置文件写入

此键保存所有选项,并进行切换以及当前的显示模式和延迟时间。通过在退出top之前发出此命令,您将可以稍后以完全相同的状态重新启动。
Z 更改颜色映射

此键将您带到一个单独的屏幕,您可以在其中更改当前窗口或所有窗口的颜色。有关此交互式命令的详细信息,请参见主题4d。颜色映射。

*标有星号(*)的命令在“安全模式”下不可用,也不会在1级帮助屏幕上显示。

摘要区域命令

摘要区域交互式命令在全屏模式和交替显示模式下始终可用。它们会影响显示的开始行,并将确定消息和提示的位置。

这些命令始终仅影响当前窗口/字段组。请参阅主题5。ALTERNATE-DISPLAY设置和“ g ”交互式命令,以了解当前的窗口和字段组。

l 加载平均/正常运行时间切换

此命令也是在全屏模式下运行时包含程序名称(可能是别名)的行,在交替显示模式下运行时也是当前窗口名称的行。
t 任务/ CPU状态切换

此命令影响2到许多摘要区域行,具体取决于“ 1 ”切换的状态以及top是否在真实SMP下运行。

摘要区域的此部分还受“ H ”交互式命令切换的影响,如显示“任务”或“线程”的总标签中所反映。
1 Single / Separate-Cpu-States切换

此命令影响' t '命令的Cpu状态部分的显示方式。尽管此切换主要是为大规模并行SMP机器提供服务,但它不仅限于SMP环境。

当您在摘要区域中看到“%Cpu(s):”时,“ 1 ”切换打开,并且所有cpu信息都收集在一行中。否则,每个cpu分别显示为:'%Cpu0,%Cpu1,...',直至可用的屏幕高度。
m Memory / Swap-Usage切换

此命令影响处理物理和虚拟内存的两条摘要区域行。

注意:如果对于任何窗口,整个摘要区域都已切换为“关闭”,则只剩下消息行。这样,您将最大化可用的任务行,但是(临时)在全屏模式下牺牲了程序名称,而在交替显示模式下牺牲了当前窗口名称。

任务区命令

任务区交互式命令始终在全屏模式下可用。

如果当前窗口的任务显示已切换为“关闭”,则任务区交互命令在交替显示模式下将永远不可用(请参阅主题5. ALTERNATE-DISPLAY设置)。

任务窗口外观

以下命令也将受到全局“ B ”(粗体启用)切换状态的影响。

b 粗体/反向切换

此命令将影响' x '和' y '切换的显示方式。此外,仅当这些切换开关中的至少一个打开时,它才可用。
x 列高亮切换

更改当前排序字段的突出显示。如果您忘记了要对哪个字段进行排序,则在显示排序字段的情况下,此命令可以用作快速的视觉提醒。排序字段可能不可见,因为:

1) 屏幕宽度不足

2) 交互式命令“ f ”将其关闭
y 行高亮切换
更改“正在运行”任务的突出显示。使用此规定可提供有关系统运行状况的重要见解。唯一的花费将是一些额外的tty转义序列。
z “颜色/单色”切换

在当前使用的配色方案和较旧的黑白相间或黑白相间的形式之间切换当前窗口。此命令将同时更改摘要区域和任务区域,但不会影响“ x ”,“ y ”或“ b ”切换开关的状态。

任务窗口的内容

c 命令行/程序名切换

无论当前“命令”列是否可见,都将使用此命令。稍后,如果看到该字段,将看到您应用的更改。
f or F 字段管理

这些键显示一个单独的屏幕,您可以在其中更改显示哪些字段,它们的顺序以及指定排序字段。
S 累积时间模式切换

当“累积模式”为“开”时,将列出每个进程及其死子使用的CPU时间。

禁用时,分叉到许多单独任务中的程序的要求会降低。对于“ init”或shell这样的程序,这是合适的,但对于其他程序,例如编译器,则可能不合适。实验两个共享相同排序字段但具有不同“ S ”状态的任务窗口,然后查看您喜欢哪种表示形式。

发出此命令后,将通知您此切换开关的新状态。如果您想提前知道“累积模式”是否有效,请寻求帮助并在第二行查看窗口摘要。
u or U 仅显示特定用户信息

将提示您输入要显示的用户ID或用户名。' -u '选项与有效用户匹配,而' -U '选项与任何用户(真实,有效,保存或文件系统)匹配。

此后,在该任务窗口中将仅显示匹配的用户,或者可能不会显示任何进程。可以使用不同的任务窗口来筛选不同的用户。

以后,如果要在当前窗口中再次监视所有任务,请重新发出此命令,但在提示时按键。
V Forest-View-Mode切换

在此模式下,进程将根据其父级进行重新排序,并且COMMAND列的布局类似于树的布局。在林视图模式下,仍然可以在程序名称和命令行之间切换(请参阅“ c ”交互式命令),或者在进程和线程之间进行切换(请参见“ H ”交互式命令)。

注意:键入影响排序顺序的任何键都将在当前窗口中退出林视图模式。请参阅主题4c。任务区域命令,正在排序以获取有关这些键的信息。

任务窗口大小

i 空闲进程切换

显示所有任务或仅活动任务。当此切换为“关闭”时,自上次更新以来未使用任何CPU的任务将不会显示。但是,由于%CPU和TIME +字段的粒度,可能仍显示某些进程似乎没有使用CPU。

如果在交替显示模式下将此命令应用于最后一个任务显示,则它不会影响窗口的大小,因为所有先前的任务显示均已绘制。
n or # 设置最大任务数

将提示您输入要显示的任务数。您的号码出租人和可用的屏幕行将被使用。

在交替显示模式下使用时,此命令可让您精确控制每个当前可见任务显示(最后一个除外)的大小。它不会影响最后一个窗口的大小,因为所有先前的任务显示都已经被绘制。

注意:如果要在交替显示模式下增加最后一个可见任务显示的大小,请减小其上方的任务显示的大小。

任务窗口排序

为了兼容性,此top支持大多数以前的top sort键。由于这主要是为以前的高级用户提供的服务,因此这些命令不会出现在任何帮助屏幕上。

命令 排序字段 支持的
A start time (non-display) No
M %MEM Yes
N PID Yes
P %CPU Yes
T TIME+ Yes

在使用以下任何一种排序规定之前,top建议您使用' x '交互式命令临时打开列突出显示。这将有助于确保实际的排序环境符合您的意图。

仅当当前排序字段可见时,才会使用以下交互式命令。排序字段可能不可见,因为:

1) 屏幕宽度不足
2)' f '交互式命令将其关闭

< Move-Sort-Field-Left

将排序列向左移动,除非当前排序字段是要显示的第一个字段。
> Move-Sort-Field-Right

除非当前排序字段是最后显示的字段,否则将排序列向右移动。

无论当前的排序字段是否可见,以下交互式命令都将始终被接受。

f or F 字段管理

这些键显示一个单独的屏幕,您可以在其中更改将哪个字段用作排序列以及其他功能。当在顶部突出显示处于关闭状态的情况下运行顶部时,此命令是验证当前排序字段的便捷方法。
R 反向/正常排序字段切换

使用此交互式命令,您可以在高到低和低到高排序之间进行切换。
注意

字段排序使用内部值,而不是列显示中的内部值。因此,TTY和WCHAN字段将违反严格的ASCII整理顺序。

替代显示规定:Microsoft Windows

字段组/ Windows

在全屏模式下,整个屏幕代表一个窗口。仍然可以更改单个窗口以显示4个不同字段组中的1个(请参见“ g ”交互式命令,以下重复)。4个字段组中的每一个都有一个独特的可单独配置的摘要区域和其自己的可配置任务区域。

在交替显示模式下,这四个基础字段组现在可以同时显示,或者可以根据您的命令分别关闭。

摘要区域将始终存在,即使它只是消息行。在任何给定时间只能显示一个摘要区域。但是,根据您的命令,当前可能会在屏幕上显示零到四个单独的任务显示。

当前窗口

当前窗口是与摘要区域关联的窗口以及与任务相关的命令始终指向的窗口。由于在备用显示模式下,您可以将任务显示切换为“关闭”,因此某些命令可能仅适用于当前窗口。

当您将第一个摘要区域行切换为“关闭”时,还会出现进一步的复杂情况。由于缺少窗口名称(“ l ”切换线),您将不容易知道当前窗口是哪个窗口。

Windows命令

- (dash) or _ (underscore) 显示/隐藏窗口切换

“ - ”键可打开和关闭当前窗口的任务显示。启用时,该任务区域将显示您使用' f '交互式命令建立的最少列标题。它还将反映您应用的其他任何任务区域选项/切换,产生零个或多个任务。所有任务显示

“ _ ”键都相同。换句话说,它会在当前可见的任务显示和您已切换为关闭的任何任务显示之间切换。如果当前所有四个任务显示均可见,则此交互式命令将使摘要区域保留为唯一显示元素。
= or + * 均衡(重新平衡)窗口

' = '键强制显示当前窗口的任务显示。它还会反转任何可能处于活动状态的' i '(空闲任务),' n '(最大任务)和' u '/' U '(用户过滤器)命令。另外,如果窗口已滚动,则将使用此命令将其重置。

' + '键对所有窗口都相同。四个任务显示将重新出现,并保持平衡。他们还将保留您以前应用的所有自定义设置,但“ i ”(空闲任务),“ n ”(最大任务),“ u ” /” 除外'(用户过滤器)和滚动交互式命令。
A * 交替显示模式切换

此命令将在全屏模式和交替显示模式之间切换。

首次发出此命令时,将显示所有四个任务显示。此后,当您切换模式时,您只会看到已选择使其可见的任务显示。
a, w * Next-Window-Forward / Backward

此命令更改当前窗口,从而更改命令所指向的窗口。这些键以循环方式起作用,因此您可以使用任一键到达任何所需的当前窗口。

假设窗口名称是可见的(您尚未切换“ l ”关闭),每当当前窗口名称失去其强调/颜色时,就提醒您任务显示为“关闭”并且许多命令将受到限制。
g * 选择另一个窗口/字段组

将提示您输入1到4之间的数字,指定应该成为当前窗口的字段组。

在全屏模式下,此命令对于更改当前窗口是必需的。在交替显示模式下,它不是' a '和' w '命令的较不方便的替代方法。
G 更改窗口/字段组名称

将提示您输入一个新名称以应用于当前窗口。它不要求窗口名称可见(“ l ”切换为“开”)。

*带有星号(*)的交互式命令的使用超出了交替显示模式。

' = ',' A ',' g '始终可用。

' a ',' w '在颜色映射和字段管理中的作用相同。

滚动窗口

通常,任务窗口是系统总任务/线程的局部视图,仅显示一些可用的字段/列。使用这些滚动键,您可以垂直或水平移动该视图以显示任何所需的任务或列。

Up, PgUp 滚动任务

将视图向上移到第一个任务行,直到第一个任务显示在当前窗口的顶部。当PgUp滚动整个窗口时,向上箭头键移动一行。
Down, PgDn 滚动任务

将视图向下移到最后一个任务行,直到最后一个任务是当前窗口顶部显示的唯一任务。当PgDn滚动整个窗口时,向下箭头键将移动一行。
Left, Right 滚动列一次

将可显示字段的视图水平移动一列。

注意:提醒一下,某些字段/列不是固定宽度的,而是在可见时分配了所有剩余的屏幕宽度。向右或向左滚动时,该功能最初可能会产生一些意外的结果。
Home 跳转到原位置

将显示重新定位到非滚动坐标。
End 跳转到结束位置

重新定位显示,以便最右边的列反映最后一个可显示字段,而底部任务行代表最后一个任务。

注意:从该位置,仍然可以使用箭头键向下和向右滚动,直到将单个列和单个任务作为唯一显示元素。
C Show-scroll-coordinates切换

切换每当不使用消息行时显示的参考消息。

“ 滚动坐标:y = n / n(任务),x = n / n(字段) ”

显示为n / n的坐标是相对于当前窗口的左上角。

y = n / n(任务)

前n个代表最上面的可见任务,并由滚动键控制。第二个n自动更新以反映总任务。

x = n / n(字段)

第一个n表示最左边显示的列,并由滚动键控制。第二个n是可显示字段的总数,并使用' f '交互式命令建立。

如果当前窗口的任务显示已关闭,则以上交互式命令始终在全屏模式下可用,而在交替显示模式下则不可用。

在窗口中搜索

您可以使用这些交互式命令来查找包含特定值的任务行。

L 查找字符串

将提示您输入区分大小写的字符串,该字符串从当前窗口坐标开始。搜索字符串内容没有限制。

搜索不限于单个字段或列中的值。搜索字符串中允许显示任务行中显示的所有值。您可以包括空格,数字,符号,甚至包括森林景观艺术品。

在没有输入的情况下键入键将有效地禁用“&”键,直到输入新的搜索字符串为止。
& 定位下一个

假设已建立搜索字符串,top将尝试查找下一个匹配项。

找到匹配项后,当前窗口将垂直重新放置,因此包含该字符串的任务行位于第一位。滚动坐标消息可以提供这种垂直重新定位的确认(请参见“ C ”交互式命令)。但是,水平滚动永远不会通过搜索更改。

匹配字符串的可用性将受到以下因素的影响。

a. 从可用的总数中可以显示哪些字段

b. 垂直或水平滚动窗口

c. 命令行/命令行切换器的状态

d. 所选排序列的稳定性,例如PID很好,但%CPU不好。

如果搜索失败,则恢复当前窗口的起始(未滚动)位置,水平滚动,显示命令行或选择更稳定的排序字段仍可能会产生成功的“&”搜索。

如果当前窗口的任务显示已关闭,则以上交互式命令始终在全屏模式下可用,而在交替显示模式下则不可用。

注意:每次键入搜索键时,top都会强制打开空闲任务并关闭用户筛选,以确保遇到每个任务。有关如何过滤显示的任务的其他信息,请参见“ i ”和“ u / U”交互式命令。

档案

系统配置文件

该文件的存在将影响向普通用户显示哪个版本的“帮助”屏幕。更重要的是,它将限制top运行时允许普通用户执行的操作。他们将无法发出以下命令。

k 杀死一个任务
r 重做一项任务
d or s 更改延迟/睡眠间隔

系统配置文件不是按顶部创建的。相反,您可以手动创建此文件并将其放在/ etc目录中。它的名称必须是'toprc',并且不能有前导' 。'(句号)。它必须只有两行。

这是/ etc / toprc内容的示例:

s#第1行:“安全”模式开关5.0#第2行:“延迟”间隔(以秒为单位)

个人配置文件

该文件被写为' $ HOME /。您的名字4-top '+' rc '。使用“ W ”交互式命令来创建或更新它。这是一般布局:

全局#第1行:程序名称/别名符号全局#第2行:id,altscr,irixps,delay,curwin每个ea#第a行:winname,fieldscur窗口#第b行:winflags,sortindx,maxtasks窗口#第c行:summclr ,msgsclr,headclr,taskclr

如果$ HOME变量不存在,则top将根据权限尝试将个人配置文件写入当前目录。

技巧和窍门

当您提高计划进度时,这些“技巧”中的许多技巧都是最有效的。因此,如果您具有权限,请计划以一个不错的值-10启动它。

内核魔术

对于这些技巧,top需要全屏模式。

  • 通过提示和帮助,用户界面有意暗示延迟间隔限制为十分之一秒。但是,您可以自由设置任何所需的延迟。如果您希望按他的计划安排最好地查看Linux,请尝试延迟.09秒或更短的时间。

    对于此实验,请在X Windows下打开一个xterm并将其最大化。然后执行以下操作:

    1. 通过以下方式提供调度增强和微小的延迟:nice -n -10 top -d.09
    2. 保持对排序列的突出显示为关闭,以最小化路径长度
    3. 打开对反行突出显示以进行强调
    4. 尝试各种排序列(TIME / MEM可以正常工作),以及正常或反向排序以查看最活跃的进程
    您将看到一个非常繁忙的Linux,它正在为您做所有的事情,但是没有可用的程序来说明这一点。
  • 在使用“黑底白字”颜色的xterm下,在顶部的“颜色映射”屏幕上,将任务颜色设置为黑色,并确保将任务突出显示设置为粗体,而不是反向。然后将延迟间隔设置为.3秒左右。

    在查看最活跃的进程之后,您将看到只是当前正在运行的任务的鬼影。

  • 删除现有的rcfile,或创建一个新的符号链接。启动此新版本,然后键入“ T ”(密钥,请参阅主题4c。任务区命令,排序),然后键入“ W ”和“ q ”。最后,使用-d0(零延迟)重新启动程序。

    您的显示将以前顶速度的三倍刷新,这是300%的速度优势。随着顶部攀升到TIME阶梯,在猜测顶部是否会达到顶部时,请耐心等待。

弹窗

对于这些技巧,top需要交替显示模式。

  • 在显示3或4个任务的情况下,选择除上一个任务以外的任何窗口,然后使用“ i ”命令切换开关关闭空闲进程。取决于您在何处应用“ i ”,有时会弹出几个任务显示,有时就像手风琴一样,因为top会尽力分配空间。
  • 对每个窗口的摘要行进行不同的设置:一个没有内存(' m ');另一个没有状态(“ t ”);也许一无所有,只是消息行。然后按住' a '或' w '并观察弹跳窗口的变化-跳跃窗口。
  • 显示所有4个窗口,并依次使用' i '命令切换将空闲进程设置为“关闭”。您刚刚进入了“极端反弹”区域。

大鸟窗

此技巧还需要交替显示模式。

  • 显示所有4个窗口,并确保1:Def是当前窗口。然后,使用' n '交互式命令不断增加窗口大小,直到所有其他任务显示都“弹出嵌套”为止。当它们全部移位后,使用' _ '命令切换在所有可见/不可见窗口之间切换。这是一次真正的令人兴奋的体验。
top -hv | -bcHisS -d delay -n limit -u|U user | -p pid -w [cols]

Options

Note

The typically mandatory switches ('-') and even whitespace are completely optional.

-h | -v Help/Version

Show library version and the usage prompt, then quit.
-b Batch-mode operation

Starts top in 'Batch' mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option, or until killed.
-c Command-line/Program-name toggle

Starts top with the last remembered 'c' state reversed. Thus, if top was displaying command lines, now that field will show program names, and visa versa. See the 'c' interactive command for additional information.
-d interval Delay-time, where interval is represented as: ss.tt (secs.tenths)

Specifies the delay between screen updates, and overrides the corresponding value in one's personal configuration file or the startup default. Later this can be changed with the 'd' or 's' interactive commands.

Fractional seconds are honored, but a negative number is not allowed. In all cases, however, such changes are prohibited if top is running in 'Secure mode', except for root (unless the 's' command-line option was used).
-H Threads-mode operation

Instructs top to display individual threads. Without this command-line option a summation of all threads in each process is shown. Later this can be changed with the 'H' interactive command.
-i Idle-process toggle

Starts top with the last remembered 'i' state reversed. When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed.
-n limit Number of iterations

Specifies the maximum number of iterations, or frames, top should produce before ending.
-ppid Monitor-PIDs mode, specified as: -ppid1 -ppid2 ... or -ppid1,pid2,pid3 ...

Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both forms is permitted.

A pid value of zero will be treated as the process id of the top program itself (once it is running).

This command-line option only and should you want to return to normal operation, it is not necessary to quit and restart top -- just issue any of these interactive commands: '=', 'u' or 'U'.

The 'p', 'u' and 'U' command-line options are mutually exclusive.
-s Secure-mode operation

Starts top with secure mode forced, even for root. This mode is far better controlled through the system configuration file (see topic 6. FILES).
-S Cumulative-time toggle

Starts top with the last remembered 'S' state reversed. When 'Cumulative time' mode is On, each process is listed with the cpu time that it and its dead children have used. See the 'S' interactive command for additional information regarding this mode.
-u|-U user-id-or-name User-filter-mode

Display only processes with a user id or user name matching that given. The '-u' option matches the effective user whereas the '-U' option matches on any user (real, effective, saved, or filesystem).

The 'p', 'u' and 'U' command-line options are mutually exclusive.
-w number Output-width-override

In 'Batch' mode, when used without an argument top will format output using the COLUMNS= and LINES= environment variables, if set. Otherwise, width will be fixed at the maximum 512 columns. With an argument, output width can be decreased or increased (up to 512) but the number of rows is considered unlimited.

In normal display mode, when used without an argument top will attempt to format output using the COLUMNS= and LINES= environment variables, if set. With an argument, output width can only be decreased, not increased. Whether using environment variables or an argument with -w, when not in 'Batch' mode actual terminal dimensions can never be exceeded.

Note: Without the use of this command-line option, output width is always based on the terminal at which top was invoked whether or not in 'Batch' mode.

Summary Display

Each of the following areas are individually controlled through interactive commands.

Uptime and Load Averages

This section consists of a single line displaying the following:

  • program or window name, depending on display mode
  • current time and length of time since last boot
  • total number of users
  • system load avg over the last 1, 5 and 15 minutes

Task and CPU States

This section consists of a minimum of two lines. In an SMP environment, additional lines can reflect individual CPU state percentages.

  • Line 1 shows total tasks or threads, depending on the state of the Threads-mode toggle. That total is further classified as: runningsleepingstoppedzombie
  • Line 2 shows CPU state percentages based on the interval since the last refresh. Where two labels are shown below, those for more recent kernel versions are shown first:

    us, user : time running un-niced user processes
    sy, system : time running kernel processes
    ni, nice : time running niced user processes
    wa, IO-wait : time waiting for I/O completion
    hi : time spent servicing hardware interrupts
    si : time spent servicing software interrupts
    st : time stolen from this vm by the hypervisor

Memory Usage

This portion consists of two lines which may express values in kibibytes (KiB), mebibytes (MiB) or gibibytes (GiB) depending on the amount of physical memory.

  • Line 1 reflects physical memory, classified as: totalusedfreebuffers
  • Line 2 reflects virtual memory, classified as: totalusedfreecached

Fields / Columns

Listed below are top's available process fields (columns). They are shown in alphabetical order. You may customize their position and whether or not they are displayable with the 'f' or 'F' (Fields Management) interactive commands.

Any field is selectable as the sort field, and you control whether they are sorted high-to-low or low-to-high.

CGROUPS -- Control Groups

The names of the control group(s) to which a process belongs, or '-' if not applicable for that process.

Control Groups provide for allocating resources (cpu, memory, network bandwidth, etc.) among installation-defined groups of processes. They enable fine-grained control over allocating, denying, prioritizing, managing and monitoring those resources.

Many different hierarchies of "cgroups" can exist simultaneously on a system and each hierarchy is attached to one or more subsystems. A subsystem represents a single resource.

Note

The 'CGROUPS' field, unlike most columns, is not fixed-width. When displayed, it plus any other variable width columns will be allocated all remaining screen width (up to the maximum 512 characters).

  1. CODE -- Code Size (KiB). The amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS.
  2. COMMAND -- Command Name or Command Line. Display the command line used to start a task or the name of the associated program. You toggle between command line and name with 'c', which is both a command-line option and an interactive command. When you've chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in brackets (for example: "[ mrecoveryd ]"). Either form of display is subject to potential truncation if it's too long to fit in this field's current width. That width depends upon other fields selected, their order and the current screen width. This field may also be impacted by the 'forest view' display mode. See the 'V' interactive command for additional information regarding that mode.

    Note: The 'COMMAND' field, unlike most columns, is not fixed-width. When displayed, it plus any other variable width columns will be allocated all remaining screen width (up to the maximum 512 characters).
  3. %CPU -- CPU Usage. The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.
  4. DATA -- Data + Stack Size (KiB). The amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS.
  5. Flags -- Task Flags. This column represents the task's current scheduling flags that are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in .
  6. GID -- Group Id. The effective group ID.
  7. GROUP -- Group Name. The effective group name.
  8. %MEM -- Memory Usage (RES). A task's currently used share of available physical memory.
  9. NI -- Nice Value. The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field means priority will not be adjusted in determining a task's dispatchability.
  10. nDRT -- Dirty Pages Count. The number of pages that have been modified since they were last written to auxiliary storage. Dirty pages must be written to auxiliary storage before the corresponding physical memory location can be used for some other virtual page.
  11. nMaj -- Major Page Fault Count. The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when auxiliary storage access is involved in making that page available.
  12. nMin -- Minor Page Fault count. The number of minor page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A minor page fault does not involve auxiliary storage access in making that page available.
  13. nTH -- Number of Threads. The number of threads associated with a process.
  14. P -- Last used CPU (SMP). A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).
  15. PGRP -- Process Group Id. Every process is member of a unique process group that is used for distribution of signals and by terminals to arbitrate requests for their input and output. When a process is created (forked), it becomes a member of the process group of its parent. By convention, this value equals the process ID (see PID) of the first member of a process group, called the process group leader.
  16. PID -- Process Id. The task's unique process ID, which periodically wraps, though never restarting at zero. In kernel terms, it is a dispatchable entity defined by a 'task_struct'.

    This value may also be used as: a process group ID (see PGRP); a session ID for the session leader (see SID); a thread group ID for the thread group leader (see TGID); and a TTY process group ID for the process group leader (see TPGID).
  17. PPID -- Parent Process Id. The process ID (pid) of a task's parent.
  18. PR -- Priority. The scheduling priority of the task. If you see 'rt' in this field, it means the task is running under 'real time' scheduling priority.

    Under linux, real time priority is somewhat misleading since traditionally the operating itself was not preemptable. And while the 2.6 kernel can be made mostly preemptable, it is not always so.
  19. RES -- Resident Memory Size (KiB). The non-swapped physical memory a task has used.
  20. RUID -- Real User Id.
  21. RUSER -- Real User Name.
  22. S -- Process Status. The status of the task which can be one of:

    'D' = uninterruptible sleep
    'R' = running
    'S' = sleeping
    'T' = traced or stopped
    'Z' = zombie

    Tasks shown as running should be more properly thought of as 'ready to run' -- their task_struct is represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top's delay interval and nice value.
  23. SHR -- Shared Memory Size (KiB). The amount of shared memory available to a task, that is typically not all resident. It reflects memory that could be potentially shared with other processes.
  24. SID -- Session Id. A session is a collection of process groups (see PGRP), usually established by the login shell. A newly forked process joins the session of its creator. By convention, this value equals the process ID (see PID) of the first member of the session, called the session leader, which is usually the login shell.
  25. SUID -- Saved User Id. The saved user ID.
  26. SUPGIDS -- Supplementary Group IDs. The IDs of any supplementary group(s) established at login or inherited from a task's parent. They are displayed in a comma delimited list.

    Note: The 'SUPGIDS' field, unlike most columns, is not fixed-width. When displayed, it plus any other variable width columns will be allocated all remaining screen width (up to the maximum 512 characters).
  27. SUPGRPS -- Supplementary Group Names. The names of any supplementary group(s) established at login or inherited from a task's parent. They are displayed in a comma delimited list.

    Note: The 'SUPGRPS' field, unlike most columns, is not fixed-width. When displayed, it plus any other variable width columns will be allocated all remaining screen width (up to the maximum 512 characters).
  28. SUSER -- Saved User Name. The saved user name.
  29. SWAP -- Swapped Size (KiB). The non-resident portion of a task's address space.
  30. TGID -- Thread Group Id. The ID of the thread group to which a task belongs. It is the PID of the thread group leader. In kernel terms, it represents those tasks that share an 'mm_struct'.
  31. TIME -- CPU Time. Total CPU time the task has used since it started. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children have used. You toggle 'Cumulative mode' with 'S', which is both a command-line option and an interactive command. See the 'S' interactive command for additional information regarding this mode.
  32. TIME+ -- CPU Time (hundredths). The same as 'TIME', but reflecting more granularity through hundredths of a second.
  33. TPGID -- Tty Process Group Id. The process group ID of the foreground process for the connected tty, or -1 if a process is not connected to a terminal. By convention, this value equals the process ID (see PID) of the process group leader (see PGRP).
  34. TTY -- Controlling Tty. The name of the controlling terminal. The TTY 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.
  35. UID -- User Id. The effective user ID of the task's owner.
  36. USER -- User Name. The effective user name of the task's owner.
  37. VIRT -- Virtual Memory Size (KiB). The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
  38. WCHAN -- Sleeping in Function. Depending on the availability of the kernel link map ('System.map'), this field shows the name or the address of the kernel function in which the task is currently sleeping. Running tasks displays a dash ('-') in this column.

    By displaying this field, top's own working set could be increased by over 700 Kb, depending on the kernel version. Should that occur, your only means of reducing that overhead will be to stop and restart top.

    Note: The 'WCHAN' field, unlike most columns, is not fixed-width. When displayed, it plus any other variable width columns will be allocated all remaining screen width (up to the maximum 512 characters).

Managing Fields

After pressing the interactive command 'f' or 'F' (Fields Management) you will be presented with a screen showing: 1) the current window name; 2) the designated sort field; 3) all fields in their current order along with descriptions. Entries marked with an asterisk are the currently displayed fields, screen width permitting.

  • As the on-screen instructions indicate, you navigate among the fields with the Up and Down arrow keys. The PgUp, PgDn, Home and End keys can also be used to quickly reach the first or last available field.
  • The Right arrow key selects a field for repositioning and the Left arrow key or thekey commits that field's placement.
  • The 'd' key or thebar toggles a field's display status, and thus the presence or absence of the asterisk.
  • The 's' key designates a field as the sort field. See topic 4c. TASK AREA Commands, SORTING for additional information regarding your selection of a sort field.
  • The 'a' and 'w' keys can be used to cycle through all available windows and the 'q' orkeys exit Fields Management.

The Fields Management screen can also be used to change the current window/field group in either full-screen mode or alternate-display mode. Whatever was targeted when 'q' orwas pressed will be made current as you return to the top display. See topic 5. ALTERNATE-DISPLAY Provisions and the 'g' interactive command for insight into current windows and field groups.

Note: Any window that has been scrolled horizontally will be reset if any field changes are made via the Fields Management screen. Any vertical scrolled position, however, will not be affected. See topic 5c. SCROLLING a Window for additional information regarding vertical and horizontal scrolling.

Interactive Commands

Listed below is a brief index of commands within categories. Some commands appear more than once -- their meaning or scope may vary depending on the context in which they are issued.

Global Commands

The global interactive commands are always available in both full-screen mode and alternate-display mode. However, some of these interactive commands are not available when running in 'Secure mode'.

If you want to know in advance whether or not your top has been secured, ask for help and view the system summary on the second line.

 or  Refresh-Display

These commands awaken top and following receipt of any input the entire display will be repainted. They also force an update of any hotplugged cpu or physical memory changes.

Use either of these keys if you have a large delay interval and wish to see current status.
? or h Help

There are two help levels available. The first will provide a reminder of all the basic interactive commands. If top is secured, that screen will be abbreviated.

Typing 'h' or '?' on that help screen will take you to help for those interactive commands applicable to alternate-display mode.
= 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 and user filtering. See the '-p' command-line option for a discussion of PID monitoring and the 'U' or 'u' interactive commands regarding user filtering.

Additionally, any window that has been scrolled will be reset with this command.
A Alternate-Display-Mode toggle

This command will switch between full-screen mode and alternate-display mode.
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.

Note: When this toggle is On and top is operating in monochrome mode, the entire display will appear as normal text. Thus, unless the 'x' or 'y' toggles are using reverse for emphasis, there will be no visual confirmation that they are even on.

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 want to know the current delay time, 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 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.
H Threads-mode toggle

When this toggle is On, individual threads will be displayed for all processes in all visible task windows. Otherwise, top displays a summation of all threads in each process.
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 told the new state of this toggle.
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 want 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. 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 key saves 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 takes 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 4d. COLOR Mapping.

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

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.

These commands always impact just the current window/field group. See topic 5. ALTERNATE-DISPLAY Provisions and the 'g' interactive command for insight into current windows and field groups.

l Load-Average/Uptime toggle

This command 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.
t Task/Cpu-States toggle

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.

This portion of the summary area is also influenced by the 'H' interactive command toggle, as reflected in the total label which shows either 'Tasks' or 'Threads'.
1 Single/Separate-Cpu-States toggle

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.

When you see '%Cpu(s):' in the summary area, the '1' toggle is On and all cpu information is gathered in a single line. Otherwise, each cpu is displayed separately as: '%Cpu0, %Cpu1, ...' up to available screen height.
m Memory/Swap-Usage toggle

This command affects the two summary area lines dealing with physical and virtual memory.

Note: If the entire summary area has been toggled Off for any window, you would be left with just the message line. In that way, you will have maximized available task rows but (temporarily) sacrificed the program name in full-screen mode or the current window name when in alternate-display mode.

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 5. ALTERNATE-DISPLAY Provisions).

Appearance Of Task Window

The following commands will also be influenced by the state of the global 'B' (bold enable) toggle.

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. If you forget which field is being sorted this command can serve as a quick visual reminder, providing the sort field is being displayed. The sort field might not be visible because:

1) there is insufficient Screen Width

2) the 'f' interactive command turned it Off
y Row-Highlight toggle

Changes highlighting for "running" tasks. 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.

Content Of Task Window

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 or F Fields-Management

These keys display a separate screen where you can change which fields are displayed, their order and also designate the sort field.
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 want to know in advance whether or not 'Cumulative mode' is in effect, ask for help and view the window summary on the second line.
u or U Show-Specific-User-Only

You will be prompted for the uid or name of the user to display. The '-u' option matches on effective user whereas the '-U' option matches on any user (real, effective, saved, or filesystem).

Thereafter, in that task window only matching users will be shown, or possibly no processes will be shown. Different task windows can be used to filter different users.

Later, if you want to monitor all tasks again in the current window, re-issue this command but just pressat the prompt.
V Forest-View-Mode toggle

In this mode, processes are reordered according to their parents and the layout of the COMMAND column resembles that of a tree. In forest view mode it is still possible to toggle between program name and command line (see the 'c' interactive command) or between processes and threads (see the 'H' interactive command).

Note: Typing any key affecting the sort order will exit forest view mode in the current window. See topic 4c. TASK AREA Commands, SORTING for information on those keys.

Size Of Task Window

i Idle-Process toggle

Displays all tasks or just active tasks. When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed. However, due to the granularity of the %CPU and TIME+ fields, some processes may still be displayed that appear to have used no CPU.

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.

When used in alternate-display mode, this is the command that gives you precise control over the size of each currently visible task display, except for the very last. It will not affect the last window's size, as all prior task displays will have already been painted.

Note: If you want to increase the size of the last visible task display when in alternate-display mode, decrease the size of the task display(s) above it.

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

Before using any of the following sort provisions, top suggests that you temporarily turn on column highlighting using the 'x' interactive command. That will help ensure that the actual sort environment matches your intent.

The following interactive commands will only be honored when the current sort field is visible. The sort field might not be visible because:

1) there is insufficient Screen Width
2) the 'f' interactive command turned it Off

< 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.

The following interactive commands will always be honored whether or not the current sort field is visible.

f or F Fields-Management

These keys display a separate screen where you can change which field is used as the sort column, among other functions. This command can be a convenient way to verify the current sort field, when running top with column highlighting turned Off.
R Reverse/Normal-Sort-Field toggle

Using this interactive command you can alternate between high-to-low and low-to-high sorts.
Note

Field sorting uses internal values, not those in column display. Thus, the TTY and WCHAN fields will violate strict ASCII collating sequence.

Alternate-Display Provisions: Microsoft Windows

Field Groups/Windows

In full-screen mode there is a single window represented by the entire screen. That single window can still be changed to display 1 of 4 different field groups (see the 'g' interactive command, repeated below). Each of the 4 field groups has a unique separately configurable summary area and its own configurable task area.

In alternate-display mode, those 4 underlying field groups can now be made visible simultaneously, or can be turned Off individually at your command.

The summary area will always exist, even if it's only the message line. At any given time only one summary area can be displayed. However, depending on your commands, there could be from zero to four separate task displays currently showing on the screen.

Current Window

The current window is the window associated with the summary area and the window to which task related commands are always directed. Since in alternate-display mode you can toggle the task display Off, some commands might be restricted for the current window.

A further complication arises when you have toggled the first summary area line Off. With the loss of the window name (the 'l' toggled line), you'll not easily know what window is the current window.

Commands for Windows

- (dash) or _ (underscore) Show/Hide-Window(s) toggles

The '-' key turns the current window's task display On and Off. When On, that task area will show a minimum of the columns header you've established with the 'f' interactive command. It will also reflect any other task area options/toggles you've applied yielding zero or more tasks.

The '_' key does the same for all task displays. In other words, it switches between the currently visible task display(s) and any task display(s) you had toggled Off. If all 4 task displays are currently visible, this interactive command will leave the summary area as the only display element.
= or + Equalize-(re-balance)-Window(s)

The '=' key forces the current window's task display to be visible. It also reverses any 'i' (idle tasks), 'n' (max tasks) and 'u'/'U' (user filter) commands that might be active. Also, if the window had been scrolled, it will be reset with this command.

The '+' key does the same for all windows. The four task displays will reappear, evenly balanced. They will also have retained any customizations you had previously applied, except for the 'i' (idle tasks), 'n' (max tasks), 'u'/'U' (user filter) and scrolling interactive commands.
A Alternate-Display-Mode toggle

This command will switch between full-screen mode and alternate-display mode.

The first time you issue this command, all four task displays will be shown. Thereafter when you switch modes, you will see only the task display(s) you've chosen to make visible.
aw Next-Window-Forward/Backward

This command changes the current window, which in turn changes the window to which commands are directed. These keys act in a circular fashion so you can reach any desired current window using either key.

Assuming the window name is visible (you have not toggled 'l' Off), whenever the current window name loses its emphasis/color, that's a reminder the task display is Off and many commands will be restricted.
g Choose-Another-Window/Field-Group

You will be prompted to enter a number between 1 and 4 designating the field group which should be made the current window.

In full-screen mode, this command is necessary to alter the current window. In alternate-display mode, it is a less convenient alternative to the 'a' and 'w' commands.
G Change-Window/Field-Group-Name

You will be prompted for a new name to be applied to the current window. It does not require that the window name be visible (the 'l' toggle to be On).

* The interactive commands shown with an asterisk (*) have use beyond alternate-display mode.

'=', 'A', 'g' are always available.'

'a', 'w' act the same with color mapping and fields management.

Scrolling a Window

Typically a task window is a partial view into a systems's total tasks/threads which shows only some of the available fields/columns. With these scrolling keys, you can move that view vertically or horizontally to reveal any desired task or column.

UpPgUp Scroll-Tasks

Move the view up toward the first task row, until the first task is displayed at the top of the current window. The Up arrow key moves a single line while PgUp scrolls the entire window.
DownPgDn Scroll-Tasks

Move the view down toward the last task row, until the last task is the only task displayed at the top of the current window. The Down arrow key moves a single line while PgDn scrolls the entire window.
Left, Right Scroll-Columns

Move the view of displayable fields horizontally one column at a time.

Note: As a reminder, some fields/columns are not fixed-width but allocated all remaining screen width when visible. When scrolling right or left, that feature may produce some unexpected results initially.
Home Jump-to-Home-Position

Reposition the display to the un-scrolled coordinates.
End Jump-to-End-Position

Reposition the display so that the rightmost column reflects the last displayable field and the bottom task row represents the last task.

Note: From this position it is still possible to scroll down and right using the arrow keys until a single column and a single task is left as the only display element.
C Show-scroll-coordinates toggle

Toggle an informational message that is displayed whenever the message line is not otherwise being used.

"scroll coordinates: y = n/n (tasks), x = n/n (fields)"

The coordinates shown as n/n are relative to the upper left corner of the current window.

y = n/n (tasks)

The first n represents the topmost visible task and is controlled by scrolling keys. The second n is updated automatically to reflect total tasks.

x = n/n (fields)

The first n represents the leftmost displayed column and is controlled by scrolling keys. The second n is the total number of displayable fields and is established with the 'f' interactive command.

The above interactive commands are always available in full-screen mode but never available in alternate-display mode if the current window's task display has been toggled Off.

Searching in a Window

You can use these interactive commands to locate a task row containing a particular value.

L Locate-a-string

You will be prompted for the case-sensitive string to locate starting from the current window coordinates. There are no restrictions on search string content.

Searches are not limited to values from a single field or column. All of the values displayed in a task row are allowed in a search string. You may include spaces, numbers, symbols and even forest view artwork.

Keyingwith no input will effectively disable the '&' key until a new search string is entered.
& Locate-next

Assuming a search string has been established, top will attempt to locate the next occurrence.

When a match is found, the current window is repositioned vertically so the task row containing that string is first. The scroll coordinates message can provide confirmation of such vertical repositioning (see the 'C' interactive command). Horizontal scrolling, however, is never altered via searching.

The availability of a matching string will be influenced by the following factors.

a. Which fields are displayable from the total available

b. Scrolling a window vertically or horizontally

c. The state of the command/command-line toggle

d. The stability of the chosen sort column, for example PID is good but %CPU bad.

If a search fails, restoring the current window home (unscrolled) position, scrolling horizontally, displaying command-lines or choosing a more stable sort field could yet produce a successful '&' search.

The above interactive commands are always available in full-screen mode but never available in alternate-display mode if the current window's task display has been toggled Off.

Note: Whenever a search key is typed, top forces idle tasks On and user filtering Off to ensure that every task is encountered. See the 'i' and 'u/U' interactive commands for additional information on how displayed tasks might be filtered.

Files

System Configuration File

The presence of this file will influence which version of the 'help' screen is shown to an ordinary user. More importantly, it will limit what ordinary users are allowed to do when top is running. They will not be able to issue the following commands.

k Kill a task
r Renice a task
d or s Change delay/sleep interval

The system configuration file is not created by top. Rather, you create this file manually and place it in the /etc directory. Its name must be 'toprc' and must have no leading '.' (period). It must have only two lines.

Here is an example of the contents of /etc/toprc:

s # line 1: 'secure' mode switch 5.0 # line 2: 'delay' interval in seconds

Personal Configuration File

This file is written as '$HOME/.your-name-4-top' + 'rc'. Use the 'W' interactive command to create it or update it. Here is the general layout:

global # line 1: the program name/alias notation global # line 2: id,altscr,irixps,delay,curwin per ea # line a: winname,fieldscur window # line b: winflags,sortindx,maxtasks window # line c: summclr,msgsclr,headclr,taskclr

If the $HOME variable is not present, top will try to write the personal configuration file to the current directory, subject to permissions.

Tips And Tricks

Many of these 'tricks' work best when you give top a scheduling boost. So plan on starting it with a nice value of -10, assuming you've got the authority.

Kernel Magic

For these tricks, top needs full-screen mode.

  • The user interface, through prompts and help, intentionally implies that the delay interval is limited to tenths of a second. However, you're free to set any desired delay. If you want to see Linux at his scheduling best, try a delay of .09 seconds or less.

    For this experiment, under X Windows open an xterm and maximize it. Then do the following:

    1. provide a scheduling boost and tiny delay via:nice -n -10 top -d.09
    2. keep sorted column highlighting Off so as to minimize path length
    3. turn On reverse row highlighting for emphasis
    4. try various sort columns (TIME/MEM work well), and normal or reverse sorts to bring the most active processes into view

    What you'll see is a very busy Linux doing what it's always done for you, but there was no program available to illustrate this.

  • Under an xterm using 'white-on-black' colors, on top's Color Mapping screen set the task color to black and be sure that task highlighting is set to bold, not reverse. Then set the delay interval to around .3 seconds.

    After bringing the most active processes into view, what you'll see are the ghostly images of just the currently running tasks.

  • Delete the existing rcfile, or create a new symlink. Start this new version then type 'T' (a secret key, see topic 4c. Task Area Commands, SORTING) followed by 'W' and 'q'. Finally, restart the program with -d0 (zero delay).

    Your display will be refreshed at three times the rate of the former top, a 300% speed advantage. As top climbs the TIME ladder, be as patient as you can while speculating on whether or not top will ever reach the top.

Bouncing Windows

For these tricks, top needs alternate-display mode.

  • With 3 or 4 task displays visible, pick any window other than the last and turn idle processes Off using the 'i' command toggle. Depending on where you applied 'i', sometimes several task displays are bouncing and sometimes it's like an accordion, as top tries his best to allocate space.
  • Set each window's summary lines differently: one with no memory ('m'); another with no states ('t'); maybe one with nothing at all, just the message line. Then hold down 'a' or 'w' and watch a variation on bouncing windows -- hopping windows.
  • Display all 4 windows and for each, in turn, set idle processes to Off using the 'i' command toggle. You've just entered the "extreme bounce" zone.

The Big Bird Window

This trick also requires alternate-display mode.

  • Display all 4 windows and make sure that 1:Def is the current window. Then, keep increasing window size with the 'n' interactive command until all the other task displays are "pushed out of the nest". When they've all been displaced, toggle between all visible/invisible windows using the '_' command toggle. It's a truly mind-bending experience.

查看英文版

查看中文版

其他命令行

tabs | tac | talk | tail | tcopy | tty | tar | tbl | tcpdump | tcsh | time | tee | timex | telinit | telnet | test | touch | tput | tr | troff | traceroute |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条