if(i == 5)
{
printf("I am is father %d\n",getpid());
while(1)
{
pid_t wpid = waitpid(-1,NULL,WNOHANG);
if(wpid == -1)
{
break;
}else if(wpid > 0)
{
printf("waitpid wpid=%d\n",wpid);
}
}
while(1)
{
sleep(1);
}
}
if(i == 5)
{
for (i = 0; i < 5; ++i) {
pid_t wpid = wait(NULL);
printf("回收的pid为: %d\n",wpid);
}
while(1)
{
sleep(1);
}
}
linux c++(进程相关的函数 & 第四篇 多个子进程回收)
原文:https://www.cnblogs.com/lodger47/p/14729655.html