(4)top详解 (每周一个linux命令系列)
(4)top详解 (每周一个linux命令系列)
linux命令 top详解
引言:今天的命令是用来看cpu信息的top
top
我们先看man top
top - display Linux processes
翻译:显示linux进程信息
具体的描述如下:
The top program provides a dynamic real-time view of a running sys‐tem. It can display system summary information as well as a list ofprocesses or threads currently being managed by the Linux kernel.The types of system summary information shown and the types, orderand size of information displayed for processes are all user config‐urable and that configuration can be made persistent across restarts.The program provides a limited interactive interface for processmanipulation as well as a much more extensive interface for personalconfiguration -- encompassing every aspect of its operation. Andwhile top is referred to throughout this document, you are free toname the program anything you wish. That new name, possibly analias, will then be reflected on top's display and used when readingand writing a configuration file.
翻译如下:
top命令提供一个运行中系统的动态实时视图,它可以显示系统摘要信息以及由linux内核管理的的进程或线程的列表。系统概要信息的类型被显示出来,类型、顺序为进程显示的信息大小都是用户配置的。可以通过重新启动使配置持久化。
该程序为进程操作提供有限的交互式界面。并为个人配置提供了更广泛的接口 - 涵盖了其操作的各个方面。 虽然本文档中提到了top,但你可以随意命名该程序。 该新名称(可能是别名)将反映在top的显示界面上,并在读取和写入配置文件时使用。
我们再来看一下命令执行结果
top - 17:00:43 up 12 days, 1:13, 3 users, load average: 6.27, 3.04, 2.31
Tasks: 444 total, 3 running, 441 sleeping, 0 stopped, 0 zombie
%Cpu(s): 19.0 us, 4.7 sy, 0.0 ni, 75.1 id, 1.1 wa, 0.0 hi, 0.2 si, 0.0
KiB Mem : 16131568 total, 926512 free, 8862288 used, 6342768 buff/cache
KiB Swap: 8191996 total, 8191900 free, 96 used. 5994096 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5297 nobody 20 0 283588 20388 5372 R 9.3 0.1 9:25.75 php-fpm
23312 nobody 20 0 372584 21660 6272 S 9.3 0.1 14:31.92 php-fpm
23325 nobody 20 0 353288 13676 4916 R 9.3 0.1 14:55.50 php-fpm ......
可以看到,top命令同时返回了一些uptime命令中返回的系统信息,这里不再赘述。
第二行是系统作业数量(Tasks)
- total 进程总数 - running 正在运行的进程数 - sleeping 休眠的进程数 - stopped 停止的进程数 - zombie 僵尸进程数 (没有被子进程先于父进程结束却没有被回收,不占用内存等资源,但在进程表中有记录)
第三行是cpu使用情况(%Cpu(s))
- us, user: 运行未调整优先级的用户进程的CPU百分比- sy,system: 运行内核进程的CPU百分比- ni,niced: 运行已调整优先级的用户进程的CPU百分比- id 空闲cpu百分比- wa,IO wait: 用于等待IO完成的CPU时间- hi 硬件中断(Hardware IRQ)占用CPU的百分比- si 软件中断(Software Interrupts)占用CPU的百分比- st,Steal time 如果当前处于一个hypervisor下的vm,被vm偷走(Steal)的时间,虚拟 CPU 等待实际 CPU 的时间的百分比。
接下来的命令有点像是我们之前发的free
Mem: - total 物理内存总量 - used 使用中的物理内存总量 - free 空闲内存总量 - buffers 用作内核缓存的内存量 Swap: - total 交换区总量 - used 使用中的交换区总量 - free 空闲交换区总量 - cached 缓冲的交换区总量。
在说交互和列含义之前,先大概说一下,top命令的交互并不是通过以前 ‘ 命令 <选项> ’的形式 而是在出现top视图后,按键盘上的键进行操作。
交互和选项
选项
top [-] [d] [p] [q] [c] [S] [s] [i] [n] [u]
使用说明
-d delay 指定每两次屏幕信息刷新之间的时间间隔。交互命令s交互命令来改变之。
-p 通过指定监控进程ID来仅仅监控某个进程的状态。
-q 该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。
-c 显示整个命令行而不只是显示命令名
-S 指定累计模式 和交互命令中的S同
-s 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。
-i 使top不显示任何闲置或者僵死进程。
-n <次数>:循环显示的次数。
-u <用户名>:指定用户名;
交互命令
h或?:显示帮助画面,给出一些简短的命令总结说明;
k:终止一个进程 按键后会提示:PID to signal/kill [default pid = xxx] 让你输入pid;
i:忽略闲置和僵死进程,这是一个开关式命令;
q:退出程序;
r:重新安排一个进程的优先级别 也会有提示:PID to renice [default pid = xxx] 输入pid后提示:Renice PID 28851 to value;输入正数降低优先级,负数增加优先级S:切换到累计模式;
s:改变两次刷新之间的延迟时间(单位为s),如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是3s;
f/F:从当前显示中添加或者删除列属性,进入后有操作说明;
o/O:改变显示项目的顺序;
l:切换显示平均负载和启动时间信息;
m:切换显示内存信息;
t:切换显示进程和CPU状态信息;
c:切换显示命令名称和完整命令;
M:根据驻留内存大小进行排序;
P:根据CPU使用百分比大小进行排序;
T:根据时间/累计时间进行排序;
w:将当前设置写入~/.toprc文件中。
我们不可能尽善尽美的说明每一项,其他的用到的概率也不大。具体的意思也需要大家自己去尝试。我们下面说一下视图中每一列代表的含义(常用的带*)
列含义
* PID = Process Id 进程唯一标识符
* USER = Effective User Name 用户名
* PR = Priority 优先级 越低越好 rt是运行状态
* NI = Nice Value 调整的优先级
* VIRT = Virtual Image (KiB) 进程使用的虚拟内存。VIRT=SWAP+RES
* RES = Resident Size (KiB) 任务使用的非交换物理内存大小b。RES=CODE+DATA
* SHR = Shared Memory (KiB) SHR是进程使用的共享内存。共享内存大小,单位kb
* S = Process Status 进程状态 取值如下:D - 不可中断的睡眠态。R – 运行态S – 睡眠态T – 被跟踪或已停止Z – 僵尸态* %CPU = CPU Usage 任务所使用的CPU时间百分比。
* %MEM = Memory Usage (RES) 任务所使用的CPU时间百分比
* TIME+ = CPU Time, hundredths 全部CPU时间精确到1/100秒
* COMMAND = Command Name/Line 进程名称(命令名/命令行)PPID = Parent Process pid PPID 父进程id UID = Effective User Id 进程所有者的用户idRUID = Real User Id 进程所有者的真实用户idRUSER = Real User Name 进程所有者的真实用户SUID = Saved User Id SUSER = Saved User Name GID = Group Id 用户组idGROUP = Group Name 用户组PGRP = Process Group Id 进程组idTTY = Controlling Tty 控制台,有如下:? 不是从终端启动的tty1-6 控制台1-6pty 虚拟终端pts/ptmx pts(pseudo-terminal slave)是pty的实现方法,与ptmx(pseudo-terminal master)配合使用实现pty。pts/0 斜杠后的数字代表标号 一般pts都是网络连接进来的程序TPGID = Tty Process Grp Id tty的组SID = Session Id 回话idnTH = Number of Threads 线程数量P = Last Used Cpu (SMP) 最后使用的cpu标号TIME = CPU Time 使用cpu的时间SWAP = Swapped Size (KiB) 进程使用的虚拟内存中,被换出的大小。CODE = Code Size (KiB) 可执行代码占用的物理内存大小DATA = Data+Stack (KiB) 可执行代码以外的部分(数据段+栈)占用的物理内存大小nMaj = Major Page Faults nMin = Minor Page Faults nDRT = Dirty Pages Count 最后一次写入到现在,被修改过的页面数。WCHAN = Sleeping in Function 若该进程在睡眠,则显示睡眠中的系统函数名Flags = Task Flags <sched.h> 任务标志CGROUPS = Control Groups SUPGIDS = Supp Groups IDs SUPGRPS = Supp Groups Names TGID = Thread Group Id 线程组idENVIRON = Environment vars vMj = Major Faults delta vMn = Minor Faults delta USED = Res+Swap Size (KiB) 物理内存和使用的交换区大小nsIPC = IPC namespace Inode nsMNT = MNT namespace Inode nsNET = NET namespace Inode nsPID = PID namespace Inode nsUSER = USER namespace InodensUTS = UTS namespace Inode
#附录:部分列名称的解释(来源于man top)
这里给出英文的原文档,方便大家参考。
3a. DESCRIPTIONS of FieldsListed below are top's available process fields (columns). They are shown instrict ascii alphabetical order. You may customize their position andwhether 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 aresorted high-to-low or low-to-high. For additional information on sort provi‐sions see topic 4c. TASK AREA Commands, SORTING.The fields related to physical memory or virtual memory reference `(KiB)'which is the unsuffixed display mode. Such fields may, however, be scaledfrom KiB through PiB. That scaling is influenced via the `e' interactivecommand or established for startup through a build option.1. %CPU -- CPU UsageThe 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 a process is multi-threaded and top is notoperating in Threads mode, amounts greater than 100% may be reported.You toggle Threads mode with the `H' interactive command.Also for multi-processor environments, if Irix mode is Off, top willoperate in Solaris mode where a task's cpu usage will be divided by thetotal number of CPUs. You toggle Irix/Solaris modes with the `I' inter‐active command.2. %MEM -- Memory Usage (RES)A task's currently used share of available physical memory.3. CGROUPS -- Control GroupsThe names of the control group(s) to which a process belongs, or `-' ifnot applicable for that process.Control Groups provide for allocating resources (cpu, memory, networkbandwidth, etc.) among installation-defined groups of processes. Theyenable fine-grained control over allocating, denying, prioritizing, man‐aging and monitoring those resources.Many different hierarchies of cgroups can exist simultaneously on a sys‐tem and each hierarchy is attached to one or more subsystems. A subsys‐tem represents a single resource.Note: The CGROUPS field, unlike most columns, is not fixed-width. Whendisplayed, it plus any other variable width columns will be allocated allremaining screen width (up to the maximum 512 characters). Even so, suchvariable width fields could still suffer truncation. See topic 5c.SCROLLING a Window for additional information on accessing any truncateddata.4. CODE -- Code Size (KiB)The amount of physical memory devoted to executable code, also known asthe Text Resident Set size or TRS.5. COMMAND -- Command Name or Command LineDisplay the command line used to start a task or the name of the associ‐ated program. You toggle between command line and name with `c', whichis both a command-line option and an interactive command.When you've chosen to display command lines, processes without a commandline (like kernel threads) will be shown with only the program name inbrackets, as in this example:[kthreadd]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. Whendisplayed, it plus any other variable width columns will be allocated allremaining screen width (up to the maximum 512 characters). Even so, suchvariable width fields could still suffer truncation. This is especiallytrue for this field when command lines are being displayed (the `c'interactive command.) See topic 5c. SCROLLING a Window for additionalinformation on accessing any truncated data.6. DATA -- Data + Stack Size (KiB)The amount of physical memory devoted to other than executable code, alsoknown as the Data Resident Set size or DRS.7. ENVIRON -- Environment variablesDisplay all of the environment variables, if any, as seen by the respec‐tive processes. These variables will be displayed in their raw nativeorder, not the sorted order you are accustomed to seeing with an unquali‐fied `set'.Note: The ENVIRON field, unlike most columns, is not fixed-width. Whendisplayed, it plus any other variable width columns will be allocated allremaining screen width (up to the maximum 512 characters). Even so, suchvariable width fields could still suffer truncation. This is especiallytrue for this field. See topic 5c. SCROLLING a Window for additionalinformation on accessing any truncated data.8. Flags -- Task FlagsThis column represents the task's current scheduling flags which areexpressed in hexadecimal notation and with zeros suppressed. These flagsare officially documented in <linux/sched.h>.9. GID -- Group IdThe effective group ID.10. GROUP -- Group NameThe effective group name.11. NI -- Nice ValueThe nice value of the task. A negative nice value means higher priority,whereas a positive nice value means lower priority. Zero in this fieldsimply means priority will not be adjusted in determining a task's dis‐patch-ability.12. P -- Last used CPU (SMP)A number representing the last used processor. In a true SMP environmentthis will likely change frequently since the kernel intentionally usesweak affinity. Also, the very act of running top may break this weakaffinity and cause more processes to change CPUs more often (because ofthe extra demand for cpu time).13. PGRP -- Process Group IdEvery process is member of a unique process group which is used for dis‐tribution of signals and by terminals to arbitrate requests for theirinput and output. When a process is created (forked), it becomes a mem‐ber of the process group of its parent. By convention, this value equalsthe process ID (see PID) of the first member of a process group, calledthe process group leader.14. PID -- Process IdThe task's unique process ID, which periodically wraps, though neverrestarting at zero. In kernel terms, it is a dispatchable entity definedby a task_struct.This value may also be used as: a process group ID (see PGRP); a sessionID for the session leader (see SID); a thread group ID for the threadgroup leader (see TGID); and a TTY process group ID for the process groupleader (see TPGID).15. PPID -- Parent Process IdThe process ID (pid) of a task's parent.16. PR -- PriorityThe scheduling priority of the task. If you see `rt' in this field, itmeans the task is running under real time scheduling priority.Under linux, real time priority is somewhat misleading since tradition‐ally the operating itself was not preemptible. And while the 2.6 kernelcan be made mostly preemptible, it is not always so.17. RES -- Resident Memory Size (KiB)The non-swapped physical memory a task is using.18. RUID -- Real User IdThe real user ID.19. RUSER -- Real User NameThe real user name.20. S -- Process StatusThe status of the task which can be one of:D = uninterruptible sleepR = runningS = sleepingT = stopped by job control signalt = stopped by debugger during traceZ = zombieTasks shown as running should be more properly thought of as ready to run-- their task_struct is simply represented on the Linux run-queue.Even without a true SMP machine, you may see numerous tasks in this statedepending on top's delay interval and nice value.21. SHR -- Shared Memory Size (KiB)The amount of shared memory available to a task, not all of which is typ‐ically resident. It simply reflects memory that could be potentiallyshared with other processes.22. SID -- Session IdA session is a collection of process groups (see PGRP), usually estab‐lished by the login shell. A newly forked process joins the session ofits creator. By convention, this value equals the process ID (see PID)of the first member of the session, called the session leader, which isusually the login shell.23. SUID -- Saved User IdThe saved user ID.24. SUPGIDS -- Supplementary Group IDsThe IDs of any supplementary group(s) established at login or inheritedfrom a task's parent. They are displayed in a comma delimited list.Note: The SUPGIDS field, unlike most columns, is not fixed-width. Whendisplayed, it plus any other variable width columns will be allocated allremaining screen width (up to the maximum 512 characters). Even so, suchvariable width fields could still suffer truncation. See topic 5c.SCROLLING a Window for additional information on accessing any truncateddata.25. SUPGRPS -- Supplementary Group NamesThe names of any supplementary group(s) established at login or inheritedfrom a task's parent. They are displayed in a comma delimited list.Note: The SUPGRPS field, unlike most columns, is not fixed-width. Whendisplayed, it plus any other variable width columns will be allocated allremaining screen width (up to the maximum 512 characters). Even so, suchvariable width fields could still suffer truncation. See topic 5c.SCROLLING a Window for additional information on accessing any truncateddata.26. SUSER -- Saved User NameThe saved user name.27. SWAP -- Swapped Size (KiB)The non-resident portion of a task's address space.28. TGID -- Thread Group IdThe ID of the thread group to which a task belongs. It is the PID of thethread group leader. In kernel terms, it represents those tasks thatshare an mm_struct.29. TIME -- CPU TimeTotal CPU time the task has used since it started. When Cumulative modeis On, each process is listed with the cpu time that it and its deadchildren have used. You toggle Cumulative mode with `S', which is both acommand-line option and an interactive command. See the `S' interactivecommand for additional information regarding this mode.30. TIME+ -- CPU Time, hundredthsThe same as TIME, but reflecting more granularity through hundredths of asecond.31. TPGID -- Tty Process Group IdThe process group ID of the foreground process for the connected tty, or-1 if a process is not connected to a terminal. By convention, thisvalue equals the process ID (see PID) of the process group leader (seePGRP).32. TTY -- Controlling TtyThe name of the controlling terminal. This is usually the device (serialport, pty, etc.) from which the process was started, and which it usesfor input or output. However, a task need not be associated with a ter‐minal, in which case you'll see `?' displayed.33. UID -- User IdThe effective user ID of the task's owner.34. USED -- Memory in Use (KiB)This field represents the non-swapped physical memory a task has used(RES) plus the non-resident portion of its address space (SWAP).35. USER -- User NameThe effective user name of the task's owner.36. VIRT -- Virtual Memory Size (KiB)The total amount of virtual memory used by the task. It includes allcode, data and shared libraries plus pages that have been swapped out andpages that have been mapped but not used.37. WCHAN -- Sleeping in FunctionDepending on the availability of the kernel link map (System.map), thisfield will show the name or the address of the kernel function in whichthe task is currently sleeping. Running tasks will display a dash ('-')in this column.By displaying this field, top's own working set could be increased byover 700Kb, depending on the kernel version. Should that occur, youronly means of reducing that overhead will be to stop and restart top.38. nDRT -- Dirty Pages CountThe number of pages that have been modified since they were last writtento auxiliary storage. Dirty pages must be written to auxiliary storagebefore the corresponding physical memory location can be used for someother virtual page.39. nMaj -- Major Page Fault CountThe number of major page faults that have occurred for a task. A pagefault occurs when a process attempts to read from or write to a virtualpage that is not currently present in its address space. A major pagefault is when auxiliary storage access is involved in making that pageavailable.40. nMin -- Minor Page Fault countThe number of minor page faults that have occurred for a task. A pagefault occurs when a process attempts to read from or write to a virtualpage that is not currently present in its address space. A minor pagefault does not involve auxiliary storage access in making that pageavailable.41. nTH -- Number of ThreadsThe number of threads associated with a process.42. nsIPC -- IPC namespaceThe Inode of the namespace used to isolate interprocess communication(IPC) resources such as System V IPC objects and POSIX message queues.43. nsMNT -- MNT namespaceThe Inode of the namespace used to isolate filesystem mount points thusoffering different views of the filesystem hierarchy.44. nsNET -- NET namespaceThe Inode of the namespace used to isolate resources such as networkdevices, IP addresses, IP routing, port numbers, etc.45. nsPID -- PID namespaceThe Inode of the namespace used to isolate process ID numbers meaningthey need not remain unique. Thus, each such namespace could have itsown `init' (PID #1) to manage various initialization tasks and reaporphaned child processes.46. nsUSER -- USER namespaceThe Inode of the namespace used to isolate the user and group ID numbers.Thus, a process could have a normal unprivileged user ID outside a usernamespace while having a user ID of 0, with full root privileges, insidethat namespace.47. nsUTS -- UTS namespaceThe Inode of the namespace used to isolate hostname and NIS domain name.UTS simply means "UNIX Time-sharing System".48. vMj -- Major Page Fault Count DeltaThe number of major page faults that have occurred since the last update(see nMaj).49. vMn -- Minor Page Fault Count DeltaThe number of minor page faults that have occurred since the last update(see nMin).
(4)top详解 (每周一个linux命令系列)相关推荐
- (5)ps详解 (每周一个linux命令系列)
(5)ps详解 (每周一个linux命令系列) linux命令 ps详解 引言:今天的命令是用来看进程状态的ps命令 ps 我们先看man ps ps - report a snapshot of t ...
- linux sudo yum命令详解,每天一个Linux命令之sudo命令详解
Linux系统的sudo命令是切换用户身份的命令.下面由学习啦小编为大家整理了每天一个Linux命令之sudo命令详解,希望对大家有帮助! 每天一个Linux命令之sudo命令详解 sudo命令用来以 ...
- linux screen 命令详解(后台执行linux命令)
一.背景 系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份.ftp 传输等等.通常情况下我们都是为每一个这样的任务开一个远 ...
- linux中top工具,Linux命令工具 top详解
Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...
- linux查看进程详细信息top,linux查看系统进程信息命令 px,top详解
linux查看系统进程信息命令 px,top详解 发表于:2011-03-10来源:作者:点击数: linux查看系统进程信息命令 px,top详解 软件测试 ps ax命令是显示一个当前系统进程的列 ...
- go ssh 执行多个命令_每天一个 Linux 命令(92): dirname 命令
(给Linux爱好者加星标,提升Linux技能) 转自:恋猫大鲤鱼 dablelv.blog.csdn.net/article/details/103125135 1.命令简介 dirname 命令从 ...
- 【转】Linux命令工具 top详解
Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...
- Linux命令工具 top详解
Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似 于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来 ...
- 每天一个linux命令(25):linux文件属性详解
每天一个linux命令(25):linux文件属性详解 Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下 ...
最新文章
- [Head First设计模式]生活中学设计模式——迭代器模式
- python是基于什么语言开发-2.python是什么编程语言。
- Win7系统下Vmware虚拟机无法使用USB设备问题的解决方法
- java计算器简单吗,java简单计算器
- Hadoop从安装Linux到搭建集群环境
- 宠粉老鱼皮带你 “入坑” GitHub!
- Oracle ORA-02069: 此操作的 global_names 参数必须设置为 TRUE
- 百万年薪挖了个P7程序员,难道是“水货”?
- 微设计(www.weidesigner.com)介绍系列文章(三)
- 【android】环境变量的设置
- 梦幻西游qq表情包YR
- lcd驱动芯片测试软件,LCD Driver IC测试方法及其挑战
- 网络端口号和协议号(大全)
- python any函数_python中的any函数是什么?如何使用any函数?
- 网站HTPPS加密有什么作用
- 二次函数图像如何用计算机绘制,怎么在WPS表格中绘制二次函数曲线图
- SAP ABAP 数据字典教程 SE11:表、锁定对象、视图和结构 -03
- 码支付易支付等接口对接方法
- 大数据揭秘哪个省是高考地狱?结论和想象不太一样
- 第五讲 Matlab/Simulink入门——混合系统仿真实例
热门文章
- - java实现审核流程
- 如何在自己网站上播放上传到优酷的视频
- 工业机器人关节拆装流程_工业机器人关节空间的插值轨迹规划_凌家良
- 【翻译】A Survey on Generative Diffusion Model(生成扩散模型的综述研究)
- PXI/PXIe控制器 4Link架构 16GB带宽 兼容主流PXIe机箱 设计文件
- PCIe转PXI 套件 PXI远程控制器
- MAP 推荐系统 Mean Average Precision
- java iecapt.exe_【C#】NET截屏网页,生成网页快照开发——IECapt、CutyCapt
- JS javascript 睡眠
- 随机森林-sklearn