title: getrusage not working as I would expect
body: <p>I am trying to measure the amount of memory used by a child process via the getrusage system call with the following code</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  #include &lt;unistd.h&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;sys/resource.h&gt;
  #include &lt;cassert&gt;
  #include &lt;vector&gt;
  
  int main() {
  
      auto child_pid = fork();
      if (!child_pid) {
          cout &lt;&lt; "In child process with process id " &lt;&lt; getpid() &lt;&lt; endl;
          cout &lt;&lt; "Child's parent process is " &lt;&lt; getppid() &lt;&lt; endl;
          std::this_thread::sleep_for(std::chrono::seconds(2));
  
          std::vector&lt;int&gt; vec;
          vec.resize(10000);
          for (auto ele : vec) {
              cout &lt;&lt; ele &lt;&lt; endl;
          }
  
      } else {
          // this will wait for the child above to finish
          waitpid(child_pid, nullptr, 0);
          struct rusage usage;
          int return_val_getrusage = getrusage(RUSAGE_CHILDREN, &amp;usage);
          assert(!return_val_getrusage);
          cout &lt;&lt; "Memory used by child " &lt;&lt; usage.ru_maxrss &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I keep changing the amount of memory I am allocating by putting in different arguments to the <code>vector::resize()</code> call.  This however always prints a value around 2300 for memory usage by child.  I am not sure this is the right way to go about measuring memory usage for a child process.  Even if I add calls to <code>getrusage</code> with <code>RUSAGE_SELF</code> in the child process before the allocation of the vector, the value of <code>ru_maxrss</code> remains the same.  Could someone tell me what I can do better here?</p>