不懂得:进程实现父进程与子进程同步
不懂得:进程实现父进程与子进程同步
#include<unistd.h>
#include<sys/types.h>
main()
{
int pid1,pid2;
while((pid1=fork()==-1);
if(pid1>0)
{
while((pid2=fork())==-1);
if(pid2>0)
{
wait(0);
wait(0);
printf("\n this is parent !!\n");
exit(0);
}
else
{
printf("\n child process 2 is builded");
}
else
{
sleep(3);
printf("\n child process 1 is builded by parent !!\n");
exit(0);
}
}
为什么会显示出三句.教师说这是程序的并发实行.我不太明白(在linux下vi 编的)