- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program for pipe in Linux
Here, we will create a C program for pipe in Linux. In this program, we will read some text from the input stream and then print it to the output screen.
First, let’s learn basics about pipe in Linux
Pipe is used to transfer data, it can be used for communication between process/ command/ program for transferring standard output between two in Linux or Unix based system.
One important thing to be noted is that pipes are unidirectional i.e. data can either flow from left to right or from right to left in the program.
Here, we will create a pipe that will read input from users and print it to the output screen. The implementation takes an array of size 2 which are used to take input arr[0] and returning output arr[1].
C program for pipe in Linux
Example
#include <errno.h> #include<string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h> int main(){ int Pipe[2]; char string[100]; if (pipe(Pipe) == -1){ perror("Filed to create pipe"); exit(1); } scanf("%s", string); write(Pipe[1], string, strlen(string)+1); printf("\n"); read(Pipe[0], string, 5); printf("%s", string); }
Output
input: TutorialsPoint TutorialsPoint
- Related Articles
- C program to demonstrate fork() and pipe()
- How to use a pipe with Linux find command?
- List of C++ IDEs for Linux
- What is the top IDE for c++ on Linux?
- Recommended IDEs for C# on Windows/Linux/Mac OS
- What is the best IDE for C# on Linux?
- C Program for Program for array rotation?
- Program for EMI Calculator in C program
- Write a Python program to perform table-wise pipe function in a dataframe
- Executing C# code in Linux
- Windows Anonymous Pipe
- File globbing in Linux in C++
- Program for Christmas Tree in C
- Program for Fibonacci numbers in C
- Program for Identity Matrix in C

Advertisements