我目前正在阅读 Michael Kerrisk “The Linux programming interface”。在专门介绍系统限制的章节中写道:
SUSv3 requires that the value returned by sysconf() for a particular limit be constant for the lifetime of the calling process.
这是否意味着如果我获得当前系统限制并以某种方式在当前进程中使用它们,那么在 fork 之后在子进程中再次获得它们是一个很好的品味规则?
最佳答案
原则上是的。如果您想要一个反射(reflect)对特定进程设置的实际限制的动态值,最好为每个进程调用一次 sysconf()
。
但是,有些配置值肯定是不会变的。例如,PAGESIZE
不会在对 fork()
的调用之间发生变化。可能没有必要再次调用 sysconf()
。
关于c - linux中子进程的系统限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44709306/