title: Segmentation fault with ulimit set correctly
body: <p>I tried to help an OP on <a href="https://stackoverflow.com/questions/31271742/proc-crashes-even-if-it-allocates-less-memory-than-limited-by-ulimit/31271833?noredirect=1#comment50570004_31271833">this question</a>.</p>
  
  <p>I found out that a code like the one below causes segmentation fault randomly even if the stack is set to 2000 Kbytes.</p>
  
  <pre><code>int main ()
  {
     int a[510000];
     a[509999] = 1;
     printf("%d", a[509999]);
     return 0;
  }
  </code></pre>
  
  <p>As you can see the array is <code>510000 x 4</code> bytes = <code>2040000</code> bytes.</p>
  
  <p>The stack is set to 2000 Kbytes (2048000 bytes) using ulimit command:</p>
  
  <ul>
  <li>ulimit -s 2000</li>
  <li>ulimit -Ss 2000</li>
  </ul>
  
  <p>Based on those numbers the application has room to store the array, but randomly it return segmentation fault.</p>
  
  <p>Any ideas?</p>