title: How to change the stack size using ulimit or per process on Mac OS X for a C or Ruby program?
body: <p>It seems that the recommended way to set stack size for a C program or Ruby program (which uses the C stack), is by using <code>ulimit</code> in the Bash shell.  But</p>
  
  <pre><code>$ ulimit -s
  8192
  
  $ ulimit -s 16384
  -bash: ulimit: stack size: cannot modify limit: Operation not permitted
  </code></pre>
  
  <p>and <code>sudo</code> doesn't help either.  Is there a way to set it to 16MB, 32MB, or 64MB?  I thought there should be a way to set it per program invocation instead of setting a system wide parameter as well?</p>
  
  <p>Right now <code>8192</code> probably means 8MB which is quite small, if that is compared to how much a process can be using, sometimes as much as 2GB of RAM.</p>
  
  <p>(<strong>updated note:</strong> <code>ulimit -a</code> can show its current values).</p>
  
  <p>(<strong>update 2:</strong> it actually seems like <code>ulimit -s &lt;value&gt;</code> is per shell, and that if you set it the first time, it usually works.  The problem is when you set it the second time, then it may return an error)</p>