用 ps 查看单个进程的内存占用(RSS)
精确查看某个进程占用了多少物理内存,不必打开活动监视器。
运行 ps -o pid,rss,comm -p 1234,即可显示该进程的 PID、以 KB 为单位的 RSS 和命令路径。
01命令
命令
$ ps -o pid,rss,comm -p <PID>02作用说明
RSS(常驻内存集)是进程当前占用的物理内存,活动监视器的内存列就来自这个数值。用 -o 只选 pid、rss、comm 三列,再用 -p 指定单个 PID,就能得到便于脚本处理的结果;数值除以 1024 即为 MB。想看整机情况,可用 ps aux -m 按内存对全部进程排序。
03风险
!注意: 多个进程共享的内存(框架、库)会在各自的 RSS 中重复计算,把所有进程的 RSS 相加会高估真实用量。另外 macOS 的 rss 单位是 KB。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- PS(1) — macOS man page依据: The man page lists rss among the standard output keywords ("... vsz=SZ, rss, wchan, state=S ...") and documents -o for selecting columns and -p for selecting a single process ID.
- ps(1) man page依据: The page documents the rss output keyword (resident set size, the process's non-swapped physical memory in kilobytes) and the -p pid process-selection option.
最后验证: 2026-09-19 · 分类: 系统与设置