1. Calculating memory used by a program
I am interested to compute the total memory used by a program.
I tried to use the getrusage function, but had some problems.
The man page for getrusage says :
The getrusage subroutine returns information describing the
resources utilized by the current process, or all its terminated
child processes.
However, the resources seem to be the same even after I allocate 1 MB
dynamically. What am I doing wrong in calculating the memory resource
used by my program? My program and the output follow.
Also, is there a function other than getrusage that can be used for this
purpose?
Raghu V. Hudli
IBM Corp.
===========================================================================
Disclaimer: The opinions expressed in this note are my own and do not
necessarily reflect those of my employer
=============================== program =================================
#include <sys/resource.h>
void dumprusage();
main(){
int i;
int *j;
printf("i ? ");
scanf("%d",&i);
printf("resources before memory allocation\n");
dumprusage();
j = malloc(i*1024);
printf("resources after memory allocation\n");
dumprusage();
void dumprusage() {
int who = RUSAGE_SELF;
struct rusage Rusage;
getrusage(who,&Rusage);
printf("ru_utime %d\n",Rusage.ru_utime.tv_usec);
printf("ru_stime %d\n",Rusage.ru_stime.tv_usec);
printf("ru_maxrss %d\n",Rusage.ru_maxrss);
printf("ru_ixrss %d\n",Rusage.ru_ixrss);
printf("ru_idrss %d\n",Rusage.ru_idrss);
printf("ru_isrss %d\n",Rusage.ru_isrss);
printf("inputs %d\n",Rusage.ru_inblock);
printf("outputs %d\n",Rusage.ru_oublock);
=============================== output =================================
i ? 1024
resources before memory allocation
ru_utime 90000
ru_stime 160000
ru_maxrss 59
ru_ixrss 360
ru_idrss 156
ru_isrss 0
inputs 0
outputs 0
resources after memory allocation
ru_utime 90000
ru_stime 160000
ru_maxrss 59
ru_ixrss 360
ru_idrss 156
ru_isrss 0
inputs 0
outputs 0
2. SMS alert at root login
3. how to assess what is using various proportions of memory
4. Zooed Slackware
5. How to calculate Used Memory???
6. SCO 3.2v4.2 & MMX Machines.
7. How much memory am i using ?
8. redhat 4.1 install problem: mount failed
9. How do I get into the setup program when I am using Tom's Rboot?
10. How to see memory used per user; memory used per process
11. calculating the memory footprint of an application
12. C pgm to calculate memory
13. Calculating memory Usage