用 systemd-cgtop 按服务查看资源占用
以服务(cgroup)为单位查看 CPU、内存和 I/O 占用,比 top 更直观。
执行 systemd-cgtop --order=cpu --depth=2,按 CPU 排序查看每个服务的资源占用——相当于服务版的 top。
01命令
命令
$ systemd-cgtop --order=cpu --depth=202作用说明
top 显示的是单个进程,但一个浏览器就有几十个进程,一个服务还会 fork 出多个 worker。systemd-cgtop 按控制组聚合用量,docker.service 或 user.slice 下所有进程都归为一行。按 m 按内存排序、按 i 按 I/O 排序,按 1 可以展开查看单个任务。
03风险
!注意: 部分发行版默认关闭内存和 I/O 统计,对应列会显示 0,需要先在 systemd 配置或对应 unit 中设置 MemoryAccounting=yes / IOAccounting=yes。命令会一直运行,按 q 退出。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- systemd-cgtop(1) — Debian bookworm依据: Same synopsis systemd-cgtop [OPTIONS...]; describes ordering by CPU, memory or I/O load and the --depth= cut-off.
- systemd-cgtop(1) - Linux manual page依据: Documents systemd-cgtop [OPTIONS...] with options --order=, --depth=, -P, -m showing task/CPU/memory/I/O usage per control group.
最后验证: 2026-09-19 · 分类: 系统与设置