Search code examples
bashcommand-lineprocessps

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


I am trying to display memory usage of active processes using the command ps. I read in the manual that one can use the keyword %mem in association with -O or -o but I fail to understand how.

When I try that for example

ps -a -o=%mem

I get the list of keywords

%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

I know I can get this info with top as well but I would like to use ps as I don't think one can pipe output of top in a convenient fashion.

I use bash (Terminal version 3.6.1) on MAC OS X 10.11.3


Solution

  • From the MacOS man page's syntax summary, emphasis added:

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

    Notably, -o fmt is not -o=fmt -- and replacing = from your command with a space prevents the error in question.