program memory usage [cross-post]

September 23rd, 2011 - 05:11 am ET by Alessandro Basili | Report spam
I have written a program in C language, but I'm facing a memory problem,
since from time to time the memory usage (shown with ps and/or top
utilities) increases.

I used the getrusage function from the GNU C library, but
unfortunately the kernel we are using (linux 2.6) is not supporting the
fields for memory usage in the rusage structure.

After some search I started to use the /proc file system and the statm
file related to the pid of the running program.
Now I have inserted throughout the program several calls to a function
that prints the statistics from the statm file in order to isolate the
increase of memory usage.

Unfortunately the result points to a part of the program that does not
have any hidden ambiguities related to memory usage, which is also
confirmed by isolating it in a test program.

Now my questions:

- is there any replacement to the getrusage function?
- is there any alternative method to figure out the memory usage of the
program within the program itself?
- is there any where explained how the GNU/Linux system updates the
statm file and how much it is reliable at spotting increasing memory usage?

Thanks for any suggestion.

Al

p.s.: my apologies for the cross-posting, I also posted a similar
article to the comp.lang.c but I was advised to search somewhere else,
since none of those questions where C related.

A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
email Follow the discussionReplies 4 repliesReplies Make a reply

Replies

#1 Chris Davies
September 23rd, 2011 - 04:41 pm ET | Report spam
Alessandro Basili wrote:
- is there any alternative method to figure out the memory usage of the
program within the program itself?



One of the debugging/profiling malloc libraries may help.

Chris

Similar topics