0% found this document useful (0 votes)
12 views1 page

Pipe

Uploaded by

vipuldangat103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Pipe

Uploaded by

vipuldangat103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
#include <unistd.h>
int main()
{
int pipefds1[2],pipefds2[2];
int returnstatus1,returnstatus2;
int pid;
char writemessage1[20]={"HI"};
char writemessage2[20]={"Hello"};
char readmessage[20];

returnstatus1=pipe(pipefds1);
if (returnstatus1 == -1)
{
printf("Unable to create pipe\n");
return 1;
}

returnstatus2=pipe(pipefds2);
if (returnstatus2 == -1)
{
printf("Unable to create pipe\n");
return 1;
}

pid=fork();
if (pid!=0)
{
//Parent Process
close(pipefds1[0]);
close(pipefds2[1]);
printf("Writing to pipe by parent- %s\n",writemessage1);
write(pipefds1[1],writemessage1,sizeof(writemessage1));

read(pipefds2[0],readmessage,sizeof(readmessage));
printf("Reading from pipe by parent- %s\n",readmessage);
}

else
{
close(pipefds2[0]);
close(pipefds1[1]);
printf("Writing to pipe by child- %s\n",writemessage2);
write(pipefds2[1],writemessage2,sizeof(writemessage2));

read(pipefds1[0],readmessage,sizeof(readmessage));
printf("Reading from pipe by child- %s\n",readmessage);
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy