用 pidstat 分析单个进程的资源占用
pidstat 可按时间序列输出某个 PID(或全部任务)的 CPU、内存和 I/O 统计,适合长时间记录进程行为。
运行 `pidstat -u -r -d -p <PID> 2 5` 每 2 秒采样该进程的 CPU、内存和 I/O 统计,共 5 次;省略 -p 则监控所有任务。
01命令
命令
$ pidstat -u -r -d -p 1234 2 502作用说明
top 只能给出瞬时快照,而 pidstat 生成可以记录和对比的时间间隔采样,因此更适合分析特定 PID。-u 增加 CPU 统计(%usr、%system),-r 增加内存统计(RSS、缺页),-d 增加 I/O 统计(kB_read/s、kB_wrtn/s),可以像示例中那样在一条命令里组合。不带 -p 时会报告所有任务并标记已退出的任务;也可以用 `pidstat -G <名称>` 按进程名过滤。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- pidstat(1) - Report statistics for Linux tasks依据: pidstat reports statistics for Linux tasks (processes): -u CPU usage, -r memory, -d I/O, -p selects a task, with interval and count arguments.
最后验证: 2026-09-17 · 分类: 系统与设置