Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FILE* status = fopen( "/proc/self/status", "r" );
- long ru_idrss; /* integral unshared data size */
- long ru_isrss; /* integral unshared stack size */
- #include <sys/resource.h>
- #include <errno.h>
- errno = 0;
- struct rusage* memory = malloc(sizeof(struct rusage));
- getrusage(RUSAGE_SELF, memory);
- if(errno == EFAULT)
- printf("Error: EFAULTn");
- else if(errno == EINVAL)
- printf("Error: EINVALn");
- printf("Usage: %ldn", memory->ru_ixrss);
- printf("Usage: %ldn", memory->ru_isrss);
- printf("Usage: %ldn", memory->ru_idrss);
- printf("Max: %ldn", memory->ru_maxrss);
- typedef struct {
- unsigned long size,resident,share,text,lib,data,dt;
- } statm_t;
- void read_off_memory_status(statm_t& result)
- {
- unsigned long dummy;
- char statm_path[100];
- snprintf(statm_path,99,"/proc/%d/statm",PID);
- FILE *f = fopen(statm_path,"r");
- if(!f){
- perror(statm_path);
- abort();
- }
- if(7 != fscanf(f,"%ld %ld %ld %ld %ld %ld %ld",
- &result.size,&result.resident,&result.share,&result.text,&result.lib,&result.data,&result.dt))
- {
- perror(statm_path);
- abort();
- }
- fclose(f);
- }
- /proc/[pid]/statm
- Provides information about memory usage, measured in pages.
- The columns are:
- size total program size
- (same as VmSize in /proc/[pid]/status)
- resident resident set size
- (same as VmRSS in /proc/[pid]/status)
- share shared pages (from shared mappings)
- text text (code)
- lib library (unused in Linux 2.6)
- data data + stack
- dt dirty pages (unused in Linux 2.6)
Add Comment
Please, Sign In to add comment