C program for pipe in Linux
Working and implementation of Pipe in Linux.
Prerequisite : Pipe in Linux
Approach : Pipe is highly used in Linux. Basically, pipe has 2 parts, one part is for writing and another is used for reading. So, an array of size 2 is taken. a[1] is used for writing and a[0] for reading.After reading from pipe, program will show output on console.
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main()
{
int a[2];
char buff[10];
if (pipe(a) == -1)
{
perror ( "pipe" );
exit (1);
}
write(a[1], "code" , 5);
printf ( "\n" );
read(a[0], buff, 5);
printf ( "%s" , buff);
}
|
Output :
More examples on pipe()
Last Updated :
26 Apr, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...