69,375
社区成员
发帖
与我相关
我的任务
分享
int main(void)
{
pid_t pid2;
pid_t pid=fork();
if(pid==0)
{
int j ;
for(j=0;j <5;j++)
{
printf("%d--%d: child: %d\n",getpid(), getppid(),j);
fflush(stdout); ///////////////////////
sleep(1);
}
}
else if (pid>0)
{
int i;
for(i=0;i <5;i++)
{
printf("%d--%d: parent: %d\n",getpid(),getppid(),i);
fflush(stdout); ///////////////////////
sleep(1);
}
}
else
{
fprintf(stderr,"can't fork ,error %d\n",errno);
exit(1);
}
pid2=fork();
if(pid2==0){printf("%d--%d: pid2 \n", getpid(), getppid());}
printf("%d--%d: This is the end !\n",getpid(), getppid());
return 0;
}
int main(void)
{
pid_t pid2;
pid_t pid=fork();
if(pid==0)
{
int j ;
for(j=0;j <5;j++)
{
printf("%d--%d: child: %d\n",getpid(), getppid(),j);
sleep(1);
}
}
else if (pid>0)
{
int i;
for(i=0;i <5;i++)
{
printf("%d--%d: parent: %d\n",getpid(),getppid(),i);
sleep(1);
}
}
else
{
fprintf(stderr,"can't fork ,error %d\n",errno);
exit(1);
}
pid2=fork();
if(pid2==0){printf("%d--%d: pid2 \n", getpid(), getppid());}
printf("%d--%d: This is the end !\n",getpid(), getppid());
return 0;
}