为什么在 Linux 上 fork 或 exec 后 RLIMIT_STACK 会丢失?
在 Linux 上,据说进程的 rlimit 在 fork 或 exec 之后保持不变。但是在 fork 或 exec 之后,我在子进程中丢失了 RLIMIT_STACK 。有人可以解释一下吗?
这是我的程序的一些描述性输出。
//父进程有一个像这样的RLIMIT_STACK
RLIMIT_STACK, soft - 10485760,hard - -1
//在fork之后,子进程立即失去它的RLIMIT_STACK
在fork之后的子进程中,RLIMIT_STACK, soft - -1,hard - -1
//在child,在exec之前,RLIMIT_STACK软设置为10485760,再次
RLIMIT_STACK设置OK。
在设置后的子级中,RLIMIT_STACK,软 - 10485760,硬 -1 Child pid = 3096
//exec后,新进程再次失去RLIMIT_STACK RLIMIT_STACK
得到,soft - -1,hard - -1
提前感谢
冯
On linux, it is said that rlimit of a process is kept intact after either fork or exec. But I lose my RLIMIT_STACK in the child either after fork or after exec. Would someone please give some explain?
Here is some descriptive output of my program.
//The parent has an RLIMIT_STACK like this
RLIMIT_STACK, soft - 10485760, hard - -1
//Right after fork, the child loses its RLIMIT_STACK
In child after fork, RLIMIT_STACK, soft - -1, hard - -1
//In the child, before exec, RLIMIT_STACK soft is set to 10485760 again
RLIMIT_STACK set OK.
In child after set, RLIMIT_STACK, soft - 10485760, hard - -1
Child pid = 3096
//After exec, the new process loses its RLIMIT_STACK again
RLIMIT_STACK got, soft - -1, hard - -1
Thanks in advance
Feng
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是 libpthread 的 linuxthread 实现的一个问题(我不确定这是否是一个错误)。
我写了一个简单的程序:
}
如果该程序在没有 -lpthread 选项的情况下编译和链接,则它在任何地方都可以正常运行。但是当它与 -lpthread 选项链接时,会发生连线的事情:如果它在动态链接到 libpthread 的 linuxthread 版本的机器上运行,它会给出:
但是当在动态链接到 NPTL 的机器上运行时libpthread 版本,它给出了预期的结果:
This seems a problem(I am not sure if it is a bug) of linuxthread implementation of libpthread.
I wrote a simple program:
}
If this program is compiled and linked without -lpthread option, it runs OK everywhere. But when it is linked with -lpthread option, wired things happen: if it is run on a machine where it is dynamically linked to a linuxthread version of libpthread, it gives:
But when run on a machine where it is dynamically linked to a NPTL version of libpthread, it gives the expected result: