//测试系统能创建多少进程
// 4752
// 4753
// 4754
// 4755
//当子进程退出,父进程还在运行,并且父进程没有回收子进程资源,
//那么这个子进程就成了僵尸进程(子进程资源必须由父进程回收)
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
int num = 0;
while(true)
{
pid_t pid = fork();
if(pid > 0)//父进程
{
printf("%d\n",num++);
}
if(pid == 0)//子进程
{
exit(1);
}
}
// 4752
// 4753
// 4754
// 4755
//当子进程退出,父进程还在运行,并且父进程没有回收子进程资源,
//那么这个子进程就成了僵尸进程(子进程资源必须由父进程回收)
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
int num = 0;
while(true)
{
pid_t pid = fork();
if(pid > 0)//父进程
{
printf("%d\n",num++);
}
if(pid == 0)//子进程
{
exit(1);
}
}
}