gpt4 book ai didi

c - Unix 最大子进程数

转载 作者:太空狗 更新时间:2023-10-29 15:33:03 24 4
gpt4 key购买 nike

我脑子里有个问题。我只想知道一个进程使用fork()系统调用创建子进程的最大数量限制是多少?我正在使用内核为 3.2.0-45-generic 的 UBUNTU OS (12.04)。

最佳答案

以编程方式,

#include <stdio.h>
#include <sys/resource.h>

int main()
{
struct rlimit rl;
getrlimit(RLIMIT_NPROC, &rl);
printf("%d\n", rl.rlim_cur);
}

其中 struct rlimit 是:

struct rlimit {
rlim_t rlim_cur; /* Soft limit */
rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
};

来自 man :

RLIMIT_NPROC

The maximum number of processes (or, more precisely on Linux, threads) that can be created for the real user ID of the calling process. Upon encountering this limit, fork(2) fails with the error EAGAIN.

关于c - Unix 最大子进程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com