Increasing the stack limit in OS X Yosemite
I am looking for a way to (not necessarily permanently) increase the stack size available to terminal applications in OS X 10.10.
I know there are a lot of questions related to changing environment variables, including stack limit, on the internet and here in particular (e.g. this one) but none of the proposed solutions I have found seems to work for me.
The most I get out of launchctl
is using sudo launchctl limit stack 67104768 67104768
where 67104768 is the default hard limit. Other launchctl
commands with higher limits seem to have no effect.
Then there is sysctl
, but its man pages report kern.stack_size
as unchangeable.
I hope I have not overlooked any solutions that have already been proposed somewhere; any help would be greatly appreciated!
Edit: I would like to increase the stack limit to work around what seems to be a bug in ocamlopt, the OCaml native compiler, that stack-overflows processing a particular (sensible) program; I can't seem to find the bug report right now.
Solution 1:
One way to increase the stack size is to use ulimit
:
shell> ulimit -s new_size_in_kb
Just keep in mind that there seems to be a hard limit on how big the stack can be on OSX and that limit appears to be 65532 kb:
shell> ulimit -s 65533
ulimit: value exceeds hard limit
shell> ulimit -s 65532
shell> ulimit -a | grep stack
-s: stack size (kbytes) 65532
Also ulimit -s
is temporary and resets once the terminal session ends.
If you want to make sure that the stack is increased for every terminal session, you could put the ulimit -s
command in your .zshrc or equivalent.