在 makefile 中设置堆栈大小?
我知道如何在命令行中将堆栈大小设置为无限制:
ulimit -s unlimited
并且,在 bash 中,当我将堆栈大小设置为无限制时,我的代码会成功运行并终止。
我可以在 makefile 中将堆栈大小设置为无限制(或某个指定大小)(使用 g++ 作为编译器)吗?如果是这样,怎么办?
注意:我只能提交我的项目的源文件(*.cpp、*.h)和 makefile。也就是说,(1) 运行 makefile,(2) 运行代码。因此,事先没有执行任何脚本或其他特殊指令,这就是为什么必须在 makefile 中进行更改......除非有人有其他/更好/绝妙的想法?
提前致谢!
I know how to set the stack size to unlimited in the command line:
ulimit -s unlimited
And, in bash, when I set the stack size to unlimited, my code runs and terminates successfully.
Can I set the stack size to unlimited (or some specified size) in a makefile (with g++ as the compiler)? If so, how?
Note: I can only submit my source files (*.cpp, *.h) and a makefile for my project. That is, (1) the makefile is run, (2) the code is run. So, no scripts, or other special instructions are executed beforehand, which is why the changes must be made in the makefile...unless anyone has other/better/brilliant ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,另一个避免使用 ulimit 的好主意(在 makefile 中将其作为单独的应用程序调用(或通过使用脚本等)。这是通过在您自己的程序中复制 ulimit 命令来复制它的功能(例如在 为了实现这
一点,请查看 man 2 setrlimit ( 手册页 ),然后看一下 RLIMIT_STACK
你可能想将其设置为 RLIM_INFINITY
Well, another brilliant idea to avoid the usage of ulimit (as invoking it as a separate application in your makefile (or by using scripts etc). This is by copying the functionality of the ulimit command by duplicating it in your own program (e.g. in your main).
In order to accomplish this, have a look at man 2 setrlimit ( manpage ), and take a look at RLIMIT_STACK
and you probably want to set it to RLIM_INFINITY
您可以针对每个命令执行此操作:
这将允许 foo 以无限堆栈运行。不幸的是,您需要在每个需要更大堆栈的命令之前添加此命令。
你可以做一些更一般的事情,如下所示:
You can do it for a per command basis:
This will allow foo to be run with an unlimited stack. Unfortunately, you will need to do add this before every command that needs the larger stack.
You can do something more general like this: