●main() ● char inbufMSGSIZE|; int p2l3j, pid; /*open pipe*/ if(pipe<o)i perror( pipe call); exit(1); if(pid=fork(<0)i perror(“ fork ca); eXI t(2); 48
08:48 ⚫ main( ) ⚫ { ⚫ char inbuf[MSGSIZE]; ⚫ int p[2],j,pid; ⚫ /*open pipe*/ ⚫ if(pipe<0) { ⚫ perror(“pipe call”); ⚫ exit(1); ⚫ } ⚫ if((pid=fork( )<0) { ⚫ perror(“fork call”); ⚫ exit(2); ⚫ } ⚫
e /if parent, then close read file descriptor and write down pipe"/ if(pid>0 close(p[oD; write(pill, msgI, MSGSIZE); write(pll, msg2, MSGsIZE); write(pill, msg, MSGSIZE wait((int**)0); ./ifchild, then close write file descriptor and read from pipe*/ if (pid==0) close(pllD for(=0j<3:j++) read(p[Ol, inbuf, MSGSIZE); printf(%os\n, inbuf); exit(O); f0848
08:48 ⚫ /*if parent, then close read file descriptor and write down pipe*/ ⚫ if(pid>0 { ⚫ close(p[0]); ⚫ write(p[1],msg1,MSGSIZE); ⚫ write(p[1],msg2,MSGSIZE); ⚫ write(p[1],msg3,MSGSIZE); ⚫ wait((int*)0); ⚫ } ⚫ /*if child ,then close write file descriptorand read from pipe*/ ⚫ if (pid==0){ ⚫ close(p[1]); ⚫ for(j=0;j<3;j++) ⚫ read(p[0],inbuf,MSGSIZE); ⚫ printf(“%s\n,inbuf”); ⚫ } ⚫ } ⚫ exit(0); ⚫ }