What does “ulimit -s unlimited” do?

后端 未结 3 1673
遇见更好的自我
遇见更好的自我 2020-12-02 15:08

There are understandably many related questions on stack allocation

What and where are the stack and heap?

Why is there a limit on the stack size?

Si

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 15:59

    stack size can indeed be unlimited. _STK_LIM is the default, _STK_LIM_MAX is something that differs per architecture, as can be seen from include/asm-generic/resource.h:

    /*
     * RLIMIT_STACK default maximum - some architectures override it:
     */
    #ifndef _STK_LIM_MAX
    # define _STK_LIM_MAX           RLIM_INFINITY
    #endif
    

    As can be seen from this example generic value is infinite, where RLIM_INFINITY is, again, in generic case defined as:

    /*
     * SuS says limits have to be unsigned.
     * Which makes a ton more sense anyway.
     *
     * Some architectures override this (for compatibility reasons):
     */
    #ifndef RLIM_INFINITY
    # define RLIM_INFINITY          (~0UL)
    #endif
    

    So I guess the real answer is - stack size CAN be limited by some architecture, then unlimited stack trace will mean whatever _STK_LIM_MAX is defined to, and in case it's infinity - it is infinite. For details on what it means to set it to infinite and what implications it might have, refer to the other answer, it's way better than mine.

提交回复
热议问题