#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/types.h>
int main()
{
int p1[2],p2[2],i;
char buf[20];
pipe(p1);
pipe(p2);
if(fork()==0)
{
printf("\n this is child(the input text is text)\n");
close(p1[1]);
close(p2[0]);
read(p1[0],buf,20);
write(p2[1],"Hello Papa ! I m fine",25);
printf("\n Parent send the message : %s \n",buf);
}
else
{
printf("\n this is parent(the output text is text)\n");
close(p2[1]);
close(p1[0]);
write(p1[1],"how r u beta",20);
read(p2[0],buf,20);
printf("\n child sending message to parent : %s \n",buf);
}
return 0;
}
Output:
#include<stdlib.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/types.h>
int main()
{
int p1[2],p2[2],i;
char buf[20];
pipe(p1);
pipe(p2);
if(fork()==0)
{
printf("\n this is child(the input text is text)\n");
close(p1[1]);
close(p2[0]);
read(p1[0],buf,20);
write(p2[1],"Hello Papa ! I m fine",25);
printf("\n Parent send the message : %s \n",buf);
}
else
{
printf("\n this is parent(the output text is text)\n");
close(p2[1]);
close(p1[0]);
write(p1[1],"how r u beta",20);
read(p2[0],buf,20);
printf("\n child sending message to parent : %s \n",buf);
}
return 0;
}
Output:
No comments:
Post a Comment