仅仅是一个小例子
#include "stdio.h"
main()
{
int id,i,j,k;
char father[7]={'f','a','t','h','e','r','\n'},//以下用这样的方式是因为要测试进程交错执行会不会导致字符串内乱序,事实证明纯属乱想
son1[9]={'b','r','o','t','h','e','r','1','\n'},
son2[9]={'b','r','o','t','h','e','r','2','\n'};
id=fork();
if(id==0)
{
for(i=0;i<9;i++)
{
printf("%c",son1[i]);
}
}
else if(id==-1)
{
printf("process create filed");
}
else
{
for(j=0;j<7;j++)
{
printf("%c",father[j]);
}
id=fork();
if(id==-1)
{
printf("process create filed");
}
if(id==0)
{
for(k=0;k<9;k++)
{
printf("%c",son2[k]);
}
}
}