Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run top, print output, then quit OR how to get real memory usage without top

Tags:

memory

exit

quit

I'm running Mac OS 10.6. I want to run top to get memory usage, but not in interactive mode, or any mode that updates. I just want memory usage at that point in time then return to prompt. I've looked for other utilities to get memory usage... but came up short (vm_stat is for virtual memory). Can someone direct me how to get top or something else to print memory usage to stdout?

like image 348
physicsmichael Avatar asked Mar 01 '10 02:03

physicsmichael


People also ask

Does top show memory usage?

By default, top doesn't display processes in order of memory usage. It's easy to re-order the menu by using the key combination Shift + M. This will refresh the list with the %MEM column showing memory usage in descending order.

How do you find the top memory consuming process?

Use ps Command to Find Top Processes by Memory and CPU Usage You can use the ps command with –sort argument to sort the output by memory and CPU usage.

How does top command calculate memory usage?

Open shell to run top command, if we run top it will display only command name of the running process, to see full command we use -c option with top. Then press SHIFT + m from the keyboard to sort by memory usage.

How do I check memory usage?

Go about your work as normal, and if the computer begins to slow down, press Ctrl+Shift+Esc to bring up Windows Task Manager. Click the Performance tab and select Memory in the sidebar to see a graph of your current RAM usage.


2 Answers

top -l 1 will put just one sample to standard output (you can redirect it, filter it, etc, as you wish of course). man top for many more details.

like image 189
Alex Martelli Avatar answered Oct 11 '22 09:10

Alex Martelli


you can also use the ps command. eg

ps -eo pmem,comm

check the ps man page for more output formatting. eg rss, size etc..

like image 42
ghostdog74 Avatar answered Oct 11 '22 07:10

ghostdog74