代码: 全选
#include<stdio.h>
int main(void)
{
int pid,pid2,i;
while((pid=fork())==-1);
if(pid==0)
for(i=0;i<10;i++)
printf("son %d\n",i);
else
{
while((pid2=fork())==-1);
if(pid2==0)
for(i=0;i<10;i++)
printf("son %d\n",i);
else
for(i=0;i<10;i++)
printf("father %d\n",i);
}
return 0;
}
代码: 全选
son 0
son 1
son 2
son 3
son 4
son 5
son 6
son 7
son 8
son 9
son 0
son 1
son 2
son 3
son 4
son 5
son 6
son 7
son 8
son 9
father 0
father 1
father 2
father 3
father 4
father 5
father 6
father 7
father 8
father 9
parent…
son…
daughter..
daughter..
或parent…
son…
parent…
daughter…等
呢?