I need to get the memory usage of the current process in C. Can someone offer a code sample of how to do this on a Linux platform?
I\'m aware of the cat /proc/
#include
#include
errno = 0;
struct rusage* memory = malloc(sizeof(struct rusage));
getrusage(RUSAGE_SELF, memory);
if(errno == EFAULT)
printf("Error: EFAULT\n");
else if(errno == EINVAL)
printf("Error: EINVAL\n");
printf("Usage: %ld\n", memory->ru_ixrss);
printf("Usage: %ld\n", memory->ru_isrss);
printf("Usage: %ld\n", memory->ru_idrss);
printf("Max: %ld\n", memory->ru_maxrss);
I used this code but for some reason I get 0 all the time for all 4 printf()