Upload
kiran-george-chennattucherry
View
229
Download
3
Embed Size (px)
Citation preview
PROGRAM CODE
#include<stdio.h>#include<string.h>#include<fcntl.h>main(){int pfd1[2],pfd2[2],p,x1,x2;char msg1[ ]="from parent: Hey..hello!"; char msg2[ ]="from child: How are you?"; char buf[50];x1=strlen(msg1);x2=strlen(msg2);pipe(pfd1);pipe(pfd2);p=fork();
if(p==0){close(pfd1[1]);read(pfd1[0],buf,x1); printf("\nChild recieved %s\n",buf);}else{close(pfd1[0]);write(pfd1[1],msg1,x1);}
if(p==0){close(pfd2[0]);write(pfd2[1],msg2,x2);}else{close(pfd2[1]);read(pfd2[0],buf,x2); printf("\nParent recieved %s\n",buf);}}
EXECUTION STEPS
gcc pipeipc.c./a.out
OUTPUT
Child recieved from parent: Hey..hello!
Parent recieved from child: How are you?