Inter-Process Communication Using Pipes
Inter-Process Communication Using Pipes
1️⃣ What is a Pipe?
A pipe is a unidirectional communication channel that allows one process to write data and another process to read data.
-
Created using the system call:
| End | Description |
|---|---|
fd[0] | Read end |
fd[1] | Write end |
2️⃣ When are Pipes Used?
-
Communication between parent and child processes
-
Data flows in one direction
-
Used in commands like:
3️⃣ How IPC Using Pipe Works
-
Parent creates a pipe
-
Parent forks a child
-
Child inherits the pipe
-
One process writes data
-
Other process reads data
4️⃣ Important System Calls Used
| System Call | Purpose |
|---|---|
pipe() | Creates pipe |
fork() | Creates child process |
write() | Writes to pipe |
read() | Reads from pipe |
close() | Closes unused pipe ends |
5️⃣ Simple Example: Parent Writes, Child Reads
🔹 Program Explanation
-
Parent sends a message to child
-
Child reads and prints the message
6️⃣ C Program: IPC Using Pipe
7️⃣ Sample Output
8️⃣ Key Points to Remember
-
Pipes are unidirectional
-
Used for related processes
-
Child inherits pipe descriptors
-
Must close unused ends to avoid blocking
Comments
Post a Comment