如何将关键字与“ps”(进程状态)一起使用?

How to use keywords with `ps` (process status)?

我正在尝试使用命令 ps 显示活动进程的内存使用情况。我在手册中读到可以将关键字 %mem-O-o 结合使用,但我不明白如何使用。

例如,当我尝试这样做时

ps -a -o=%mem

我得到关键字列表

%cpu %mem acflag acflg args blocked caught comm command cpu cputime etime f flags gid group ignored inblk inblock jobc ktrace
ktracep lim login logname lstart majflt minflt msgrcv msgsnd ni nice nivcsw nsignals nsigs nswap nvcsw nwchan oublk oublock p_ru
paddr pagein pcpu pending pgid pid pmem ppid pri pstime putime re rgid rgroup rss ruid ruser sess sig sigmask sl start stat state
stime svgid svuid tdev time tpgid tsess tsiz tt tty ucomm uid upr user usrpri utime vsize vsz wchan wq wqb wql wqr xstat

我知道我也可以使用 top 获取此信息,但我想使用 ps,因为我认为无法通过管道方便地输出 top时尚

我在 MAC OS X 10.11.3

上使用 bash(终端版本 3.6.1)

来自 MacOS 手册页的语法摘要,重点添加:

ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]] [-g grp[,grp...]] [-u uid[,uid...]] [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]

值得注意的是,-o fmt 不是 -o=fmt -- 将命令中的 = 替换为 space 可防止出现相关错误。