#include <stdio.h>
/* TODO: 在此处引用程序需要的其他头文件 */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char* argv[]){
/* TODO: 在此处添加自己的代码 */
int i,r,p1,p2,fd[2];
char buf[50],s[50];
pipe(fd);
while((p1=fork())==-1);
if(p1==0){
lockf(fd[1],1,0);
sprintf(buf,"P1,hhh");
write(fd[1],buf,50);
//sleep(5);
lockf(fd[1],0,0);
exit(0);
}
else{
while((p2=fork())==-1);
if(p2==0){
lockf(fd[1],1,0);
printf("shenghuo\n");
sprintf(buf,"P2,hhh");
write(fd[1],buf,50);
sleep(40000);
lockf(fd[1],0,0);
exit(0);
}
wait(0);
if(r=read(fd[0],s,50)==-1)
printf("can't read!\n");
else
printf("1xx.%s\n",s);
//wait(0);
if(r=read(fd[0],s,50)==-1)
printf("can't read!\n");
else
printf("2xx.%s\n",s);
exit(0);
}
return 0;
}