Untitled
unknown
plain_text
4 years ago
917 B
4
Indexable
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
int p[2];
int pid;
char inbuf[10],outbuf[10];
if(pipe(p)==-1)// Error in Pipe creation //
{
printf("pipe failed\n");
return 1;
}
else //Pipe created successfully //
{
pid=fork();
// Fork call to create child process //
if(pid) //// Code of Parent process
{
printf("In parent process\n");
printf("type the data to be sent to child");
scanf("%s",outbuf);
// Writing a message into the pipe
write (p[1],outbuf, sizeof(outbuf)); //p[1] indicates write sleep(2); // To allow the child to run
printf("after sleep in parent process\n");
}
else // Coding of child process //
{
printf("In child process\n");
read(p[0],inbuf,10); // Read the content written by parent
printf("the data received by the child is %s\n",inbuf);
}
return 0;
}
} Editor is loading...