我需要经历许多短暂的生命过程.(但我不想等到它完成.让它运行.).一段时间后,我在执行fork时收到错误(errno==11).看起来派生的进程仍然存在(至少它们在HTOP中是可见的).
例如,请考虑以下示例.我想派生一个进程,然后在不久之后退出它.
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
void RunProc(){
pid_t pid = fork();
if(pid == 0)
{
puts("fork with success");
//no needed to reproduce issue. Used in my code to run some commands.
//execvp()
exit(0);
}
else if (pid == -1) {
printf("Could not start process\n");
printf("Errno: %d\n", errno);
}
else {
}
}
int main()
{
while(true){
RunProc();
}
int res = 0;
int i = 5;
res = scanf("%d", &i);
res = printf("End of program %d\n", i);
return res;
}
一开始,它运行正常.几分钟后,我只收到错误:
无法启动进程 Errno:11
我再也不能开始新的fork 了. 我正在Ubuntu 22.04上运行它