c++clinuxstack-memoryulimit

Is there a limit of stack size of a process in linux


Is there a limit on the stack size of a process in Linux? Is it simply dependent on the RAM of the machine?

I want to know this in order to limit the depth of recursive calls to a function.


Solution

  • The stack is normally limited by a resource limit. You can see what the default settings are on your installation using ulimit -a:

    stack size              (kbytes, -s) 8192
    

    (this shows that mine is 8MB, which is huge).

    If you remove or increase that limit, you still won't be able to use all the RAM in the machine for the stack - the stack grows downward from a point near the top of your process's address space, and at some point it will run into your code, heap or loaded libraries.