Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine max memory usage of a process in Linux?

Tags:

I have a program that's running in two different modes. I want to compare the two modes with regard to runtime and memory requirements. Determining runtime is easy with using time. In fact, in this case it's really easy because the program reports both the CPU time and the wallclock time at the end of the test. However, determining memory usage is a bit harder.

How can I get details of the memory usage of the process throughout its lifetime? I want to know both the maximum usage and the average. In fact, ideally I'd like some graph of memory usage throughout the life of the run.

like image 854
Nathan Fellman Avatar asked Feb 24 '09 21:02

Nathan Fellman


People also ask

How do I find the highest memory utilization process in Linux?

Use ps Command to Find Top Processes by Memory and CPU Usage ps is a Linux command-line utility with many options that helps you to display output in different formats. You can use the ps command with –sort argument to sort the output by memory and CPU usage.

How do I see how much memory a process is using?

In the Activity Monitor utility, you can see the name of each process running ("Process Name" column) and how much memory each process is using ("Real Mem" column).


1 Answers

time has a verbose mode which gives you the maximum and average resident set size.

(The resident set size is the portion of a process's memory that is held in RAM).

$ /usr/bin/time -v command_that_needs_to_measured |& grep resident     Maximum resident set size (kbytes): 6596     Average resident set size (kbytes): 0 

Remember to use the binary /usr/bin/time, which has a -v option. You can view its documentation by running man time. If you fail to specify its path, bash's built-in time will run instead, which doesn't have a -v option. You can view its documentation in the bash man page or by running help time.

like image 175
Flimm Avatar answered Sep 22 '22 14:09

Flimm