13

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.

8
  • 1
    Are you explicitly asking how to increase Yosemite's stack limit?
    – user1415571
    Feb 1, 2015 at 18:38
  • 1
    Yes. Sorry, if that wasn't clear from the text. Feb 1, 2015 at 18:48
  • 1
    I found a question at superuser.com/questions/836883/… that might help you... In the first answer, it shows a maxfiles limit. Perhaps change it to stack limit and save as limit.stack.plist into launchDaemons?
    – John K
    Apr 20, 2015 at 8:53
  • 1
    Thanks! I just tried that, but no luck. Apr 23, 2015 at 9:41
  • 1
    Ok. And did you actually find the limit file? If it is not there. I will spend time looking for it and fixing the problem. And configuring that plist I instructed earlier.
    – John K
    Apr 23, 2015 at 9:42

1 Answer 1

6

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.

2
  • Thanks for that! Unfortunately in this particular case I need to increase the stack size beyond OSX's hard limit and I was hoping to find a solution that increases this limit. Sep 6, 2015 at 15:14
  • Yeah: also a ulimit -s unlimited seems to be limited to 65532 Kb: ulimit -a | grep stack gives -s: stack size (kbytes) 65532
    – fpierfed
    Sep 6, 2015 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .