title: C Program on Linux to exhaust memory
body: <p>I would like to write a program to consume all the memory available to understand the outcome. I've heard that linux starts killing the processes once it is unable to allocate the memory.</p>
  
  <p>Can anyone help me with such a program.</p>
  
  <p>I have written the following, but the memory doesn't seem to get exhausted:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  int main()
  {
          while(1)
          {
                  malloc(1024*1024);
          }
          return 0;
  }
  </code></pre>