How to measure the stack size of a process?

后端 未结 2 467
离开以前
离开以前 2021-01-12 02:44

How do I find the stack size of a process ? /proc/5848/status gives me VmStk but this doesnt change

No matter how much ever while loop and recursion I do in my test

2条回答
  •  臣服心动
    2021-01-12 03:12

    There really is no such thing as the "stack size of a process" on Linux. Processes have a starting stack, but as you see, they rarely allocate much from the standard stack. Instead, processes just allocate generic memory from the operating system and use it as a stack. So there's no way for the OS to know -- that detail is only visible from inside the process.

    A typical, modern OS may have a stack size limit of 8MB imposed by the operating system. Yet processes routinely allocate much larger objects on their stack. That's because the application is using a stack that is purely application-managed and not a stack as far as the OS is concerned.

    This is always true for multi-threaded processes. For single-threaded processes, it's possible they are actually just using very, very little stack.

提交回复
热议问题