-   Linux - General (
-   -   view memory of a quick running program (

youwin 02-22-2009 06:43 PM

view memory of a quick running program
Is there a way to find out what the maximum amount of memory a program uses in its short run time?

I'm not sure how I can access /proc/pid/stat when its gone so soon after i begin running the program.

I thought I might try to parse the output of an strace, but i havent been able to determine what is the memory usage of the stack with that, only changes with sbrks and mmap2s none of which look like they come from changes on the stack (forgive my ignorance). This might be useful still yet incomplete and probably the wrong way to do it.

It would be good to find what the maximum memory usage is, or better yet, to find what the memory usage is at each time it increases, in a good format to search through it.

norobro 02-23-2009 09:34 PM


top -i -d 0.01 -b | grep foo >
top is very configurable. You can change the fields that are displayed if the default is not what you need. Check the man page.

youwin 02-26-2009 07:13 PM

the problem with using top is that it isnt giving memory for the specific process i need right from the get go. as soon as i start the program whose memory i want to measure, its done.

norobro 02-26-2009 08:38 PM

You need to start the top command I posted in a terminal first and then in another terminal start your program. Then kill the top process (ctrl-c) and look in the file you directed the output to.

From the top man page:

-b : Batch mode operation
Starts top in ’Batch mode’, which could be useful for sending output from top to other programs or to a file.
In this mode, top will not accept input and runs until the iterations limit you’ve set with the ’-n’ com‐
mand-line option or until killed.

All times are GMT -5. The time now is 06:19 AM.