-1

My program wants to detect how much memory it's using & issue a warning if it goes larger than a threshold. I don't care about memory that has been allocated but never accessed, since that's not backed by either RAM or swap. How do I get the total RAM + swap used by my process? Does "resident set size" include swap?

Edit: As others have pointed out, getting the resident size is easy, but doesn't include swap. So this question is really about how to get the amount of swap used by a process.

Martin C. Martin
  • 3,463
  • 3
  • 26
  • 35
  • 2
    there is a [good question](http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process?rq=1) about that – fotanus May 23 '13 at 19:55
  • Use the [proc(5)](http://man7.org/linux/man-pages/man5/proc.5.html) filesystem, notably `/proc/self/stat` – Basile Starynkevitch May 23 '13 at 20:08
  • That question doesn't provide swap, and from man 5 stat, nswap and cnswap fields are not maintained. Any other ideas about where to get the swap? – Martin C. Martin May 23 '13 at 21:22

1 Answers1

-1

There's already a thread about this: How to get memory usage at run time in c++?

See this page: How to get the resident set size

RSS is the RAM portion, excluding the swap and unloaded.

Community
  • 1
  • 1
gongzhitaao
  • 6,239
  • 3
  • 35
  • 44