如何衡量一个进程的堆栈大小? [英] How to measure the stack size of a process?
问题描述
如何找到进程的堆栈大小? /proc/5848/status给了我VmStk,但这并没有改变
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 program this value hardly changes.
当我查看/proc/pid/status时,所有过程都只有136k,不知道该值从何而来.
when I looked at /proc/pid/status all of the process has 136k and have no idea where that value comes from.
谢谢
推荐答案
在Linux上确实没有进程的堆栈大小"之类的东西.进程具有一个起始堆栈,但是如您所见,它们很少从标准堆栈中分配太多资源.相反,进程只是从操作系统分配通用内存,并将其用作堆栈.因此,操作系统无法知道-只能从流程内部看到详细信息.
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.
典型的现代OS可能具有由操作系统施加的8MB的堆栈大小限制.然而,进程通常会在其堆栈上分配更大的对象.这是因为应用程序使用的是纯粹由应用程序管理的堆栈,而不是就操作系统而言的堆栈.
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.
这篇关于如何衡量一个进程的堆栈大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!