Linux 如何找到最大堆栈大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7535994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find the maximum stack size?
提问by Bruce
I am working on Ubuntu 11.04. How do I find out the maximum call stack size of a process and also the size of each frame of the stack?
我正在 Ubuntu 11.04 上工作。如何找出进程的最大调用堆栈大小以及每个堆栈帧的大小?
采纳答案by Marcelo Cantos
You can query the maximum process and stack sizes using getrlimit
. Stack frames don't have a fixed size; it depends on how much local data (i.e., local variables) each frame needs.
您可以使用 查询最大进程和堆栈大小getrlimit
。堆栈帧没有固定大小;这取决于每个帧需要多少局部数据(即局部变量)。
To do this on the command-line, you can use ulimit.
要在命令行上执行此操作,您可以使用 ulimit。
If you want to read these values for a running process, I don't know of any tool that does this, but it's easy enough to query the /proc filesystem:
如果您想为正在运行的进程读取这些值,我不知道有任何工具可以执行此操作,但是查询 /proc 文件系统很容易:
cat /proc/<pid>/limits
回答by sashang
You can use getrlimit
to see the stack size and setrlimit
to change it.
您可以使用getrlimit
来查看堆栈大小并对其setrlimit
进行更改。
There's an example in the Increase stack size in Linux with setrlimitpost.
在 Linux 中使用 setrlimit 增加堆栈大小帖子中有一个示例。
回答by fruchtose
A quick Google search should reveal some information on this subject.
一个快速的谷歌搜索应该会显示一些关于这个主题的信息。
> ulimit -a # shows the current stack size
回答by cprcrack
The following call to ulimit
returns the maximum stack size in kibibytes (210= 1024 bytes):
以下调用ulimit
返回以千字节为单位的最大堆栈大小(2 10= 1024 字节):
ulimit -s
回答by user9558595
getrlimit()
and setrlimit()
are not Linux commands. They are system calls.
getrlimit()
并且setrlimit()
不是 Linux 命令。它们是系统调用。
So in order to get the result of them, you need something like a bash script or any other executable script that returns the result of the system call.
因此,为了获得它们的结果,您需要诸如 bash 脚本或任何其他返回系统调用结果的可执行脚本之类的东西。