「top」- 显示 Linux 进程

语法格式

top -hv|-bcEHiOSs1 -d secs -n max -u|U user -p pid -o fld -w [cols]

The traditional switches `-‘ and whitespace are optional.

命令描述

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.

The program provides a limited interactive interface for process manipulation as well as a much more extensive interface for personal configuration — encompassing every aspect of its operation. And while top is referred to throughout this document, you are free to name the program anything you wish. That new name, possibly an alias, will then be reflected on top’s display and used when reading and writing a configuration file.

us, user : 运行未 Nice 进程花费的时间;

sy, system : 运行内核进程的时间;

ni, nice : 运行 Nice 的进程花费的时间;

id, idle : 在内核空闲处理程序中花费的时间;

wa, IO-wait : 等待 IO 完成的时间;

hi : 处理硬中断花费的时间;

si : 处理软中断花费的时间;

st : 虚拟机监控程序从此虚拟机窃取的时间;

相关手册

free(1), ps(1), uptime(1), atop(1), slabtop(1), vmstat(8), w(1)

应用

切换排序:

# top
Shift + M %MEM
Shift + N PID
Shift + P %CPU
Shift + T TIME+

// 这些快捷键是为了兼容,新版本仅支持少部分排序快捷键
// 更多内容,参考 SORTING of task window 部分

命令过滤:

// 执行 top 命令
// 然后,按 [O] 键,输入 COMMAND=systemd 表达式,按 [ENTER] 键执行

查看特定进程

How to view a specific process in top – Unix & Linux Stack Exchange

top -p ‘pid’

参考

man 1 top, Version 23.3.15-2
linux – How to see top processes sorted by actual memory usage? – Stack Overflow