write C programs to illustrate IPC using pipes mechanisms.
- Create a child process usingfork()
- Create a simple pipe with C, we make use of the pipe() systemcall.
- Create two file descriptor fd[0] is set up for reading, fd[1] is set up forwriting
- Close the read end of parent process using close() and perform writeoperation
- Close the write end of child process and performreading
- Display thetext.
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
int fd[2],child; char a[10];
printf("\n Enter the string:");
scanf("%s",a);
pipe(fd);
child=fork();
if(!child)
{
close(fd[0]);
write(fd[1],a,5); wait(0);
}
else
{close(fd[1]);
read(fd[0],a,5);
printf("The string received from pipe is: %s",a);
}
return 0;
}
Thus, IPC using pipes mechanisms is illustrated using c program successfully