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.
// C program to implement pipe in Linux #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h> int main() { // array of 2 size a[0] is for reading // and a[1] is for writing over a pipe int a[2]; // opening of pipe using pipe(a) char buff[10]; if (pipe(a) == -1) { perror("pipe"); // error in pipe exit(1); // exit from the program } // writing a string "code" in pipe write(a[1], "code", 5); printf("\n"); // reading pipe now buff is equal to "code" read(a[0], buff, 5); // it will print "code" printf("%s", buff); } |
chevron_right
filter_none
Output :

Recommended Posts:
- Named Pipe or FIFO with example C program
- A Shell program To Find The GCD | Linux
- How to find time taken by a command/program on Linux Shell?
- Linux Kernel Module Programming: Hello World Program
- Program to show that Linux provides time sharing environment to processes
- Linux Virtualization : Linux Containers (lxc)
- Different Shells in Linux
- Permissions in Linux
- du Command in LINUX
- 'dd' command in Linux
- Wikit in Linux
- Linux | Nmon
- od command in Linux with example
- Filters in Linux
- Some useful Linux Hacks
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



