title: C/C++ memory usage API in Linux/Windows
body: <p>I'd like to obtain memory usage information for both per process and system wide. In Windows, it's pretty easy. GetProcessMemoryInfo and GlobalMemoryStatusEx do these jobs greatly and very easily. For example, GetProcessMemoryInfo gives "PeakWorkingSetSize" of the given process. GlobalMemoryStatusEx returns system wide available memory.</p>
  
  <p>However, I need to do it on Linux. I'm trying to find Linux system APIs that are equivalent GetProcessMemoryInfo and GlobalMemoryStatusEx.</p>
  
  <p>I found 'getrusage'. However, max 'ru_maxrss' (resident set size) in struct <a href="http://www.delorie.com/djgpp/doc/libc/libc_416.html" rel="nofollow noreferrer">rusage</a> is just zero, which is not implemented. Also, I have no idea to get system-wide free memory.</p>
  
  <p>Current workaround for it, I'm using "system("ps -p %my_pid -o vsz,rsz");". Manually logging to the file. But, it's dirty and not convenient to process the data.</p>
  
  <p>I'd like to know some fancy Linux APIs for this purpose.</p>