what does "ru_maxrss" means in getrusage

1.8k views Asked by At

I compiled and run the following c++ code test.cpp on my macOS Sierra.

#include <iostream>
#include <sys/resource.h>

using namespace std;

int main() {
    int a = 1;
    struct rusage r_usage;
    getrusage(RUSAGE_SELF, &r_usage);
    cout << "Memory usage = " << r_usage.ru_maxrss << endl;
    int b = 2;
    return 0;
}

Then got:

➜  Desktop git:(master) ✗ ./test
Memory usage = 663552

Then I found the unit of ru_maxrss is kilobytes here, so the program used 663552 kilobytes? But I only just created an integer.

Another question is: does ru_maxrss count int b = 2? or it just counts the memory usage before the line calling ru_maxrss.

1

There are 1 answers

0
virusdefender On BEST ANSWER