Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "ru_maxrss" means in getrusage

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.

like image 368
sirius Avatar asked Oct 28 '25 04:10

sirius


1 Answers

Under OSX, the unit is bytes.

https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/getrusage.2.html

like image 132
virusdefender Avatar answered Oct 29 '25 17:10

virusdefender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!