How to display Activity Monitor’s “Memory” columns through Terminal

activity-monitormemoryterminalxcode

Activity Monitor has a number of columns that show different measurements of memory usage for each process. Including:

  • Memory
  • Real Memory (various)
  • Compressed Memory

How can I display these for a specific process or app in Terminal, AppleScript or Xcode?

Best Answer

The terminal command top -stats is what you need to use. Executing man top will give you all the usage info.

Note: The keys used in the -stat option are listed under the -o option.

Here are some sample top -stats commands you can try to see what you can glean from the output with different keys.

top -stats cpu,mem,pid

top -stats cpu,mem,pid -pid 106

top -stats cpu,mem,pid,command

The last command example outputs this:

%CPU                         MEM                            PID                           COMMAND
3.6                          2308K                          2191                          top
0.0                          3156K                          2190                          mdworker
0.0                          3248K                          2187                          mdworker
0.0                          3132K                          2186                          mdworker
0.0                          3280K                          2185                          mdworker
0.0                          3240K                          2184                          mdworker
0.0                          3156K                          2183                          mdworker
0.0                          3196K                          2182                          mdworker
0.0                          3156K                          2181                          mdworker
0.0                          4704K                          2175                          quicklookd
1.7                          17M                            2067                          backupd
0.0                          7652K                          2046                          mdworker
0.0                          17M                            2045                          mdworker
0.0                          19M                            2044                          mdworker