After our surface swipe into Unix Pipes, let’s steer our ship towards another intriguing concept: Duplex Communication using pipes in Linux. Imagine not just talking but also actively listening, all in real time. That’s the beauty of duplex communication.
When we talk about Unix Pipes, it’s usually a one-way dialogue. But with Duplex Communication, it’s a lively discussion where two processes can chat back and forth simultaneously.
ππ©ππππ
πππ π©πππ
πππ ππππ π·ππππ:
πΊπππππ π³πππ (π―πππ π«πππππ) : Think of this as a narrow bridge where data can either go or come, but not both at the same time.
π«πππππ π³πππ (ππππ π«πππππ): Envision a broad highway with lanes going in both directions, allowing data to flow seamlessly to and fro.

π π―ππ π
π ππ πππππππππ ππ?
Creation of Two Pipes:
Pipe 1: Allows Parent to send data to Child.
Pipe 2: Allows Child to send data to Parent.
Forking:
A call to fork() will create a child process. Both parent and child will have access to both pipes.
Parent Process:
Closes the reading end of Pipe 1 and the writing end of Pipe 2.
Writes to the child via Pipe 1 and reads from the child via Pipe 2.
Child Process:
Closes the writing end of Pipe 1 and the reading end of Pipe 2.
Reads from the parent via Pipe 1 and writes to the parent via Pipe 2.
By doing this, both the parent and child processes can communicate with each other simultaneously, achieving full duplex communication.
While this approach provides full duplex communication, it doesn’t necessarily mean that both processes will be sending and receiving data at the exact same instant. The synchronization of reads and writes is crucial to ensure smooth communication.
Code with Explanation in the following images.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
