title: What does maximum resident set size mean?
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int main() {
    int i = 0;
    struct rusage r_usage;
    while (++i &lt;= 10) {
      void *m = malloc(20*1024*1024);
      memset(m,0,20*1024*1024);
      getrusage(RUSAGE_SELF,&amp;r_usage);
      printf("Memory usage = %ld\n",r_usage.ru_maxrss);
      sleep (3);
    }
    printf("\nAllocated memory, sleeping ten seconds after which we will check again...\n\n");
    sleep (10);
    getrusage(RUSAGE_SELF,&amp;r_usage);
    printf("Memory usage = %ld\n",r_usage.ru_maxrss);
  
  
    return 0;
  }
  </code></pre>
  
  <p>The above code uses <em>ru_maxrss</em> attribute of <em>rusage</em> structure. It gives the value of maximum resident set size. What does it mean? Each time the program is executed it gives a different value. So please explain the output of this code?</p>
  
  <p><a href="https://i.stack.imgur.com/XSjd9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XSjd9.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/hvdAl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hvdAl.png" alt="enter image description here"></a></p>
  
  <p>These are screenshots of two executions of the same code which give different outputs, how can these numbers be explained or what can be interpreted from these two outputs?</p>