Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __linux__
- long getRSS()
- {
- int pid;
- char comm[512];
- char state;
- int ppid, pgrp, session, tty_nr, tpgid, flags;
- long minflt, cminflt, majflt, cmajflt, utime, stime, cutime, cstime, priority, nice, num_threads, itrealvalue;
- long long starttime;
- long vsize;
- long rss = 0;
- FILE* fp = fopen("/proc/self/stat", "r");
- if (fp) {
- fscanf(
- fp,
- "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld",
- &pid, comm, &state, &ppid, &pgrp, &session, &tty_nr, &tpgid, &flags,
- &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime, &cstime,
- &priority, &nice, &num_threads, &itrealvalue, &starttime, &vsize, &rss);
- rss = rss * sysconf(_SC_PAGE_SIZE)/1024; //in kb
- fclose(fp);
- }
- return rss;
- }
- #endif
Add Comment
Please, Sign In to add comment