Pipes and FIFOs

 

๐Ÿ“ก Pipes and FIFOs
TLPI Chapter 44 โ€” Complete Tutorial Series | EmbeddedPathashala
9 Files
Complete Coverage
25+
Code Examples
50+
Interview Qs
Level
Intermediate

About This Series

This series covers TLPI (The Linux Programming Interface) Chapter 44 โ€” Pipes and FIFOs โ€” in full detail. Every section and subsection is covered across 9 HTML files, each focused on one topic, with inline diagrams, multiple coding examples, and interview questions.

Pipes and FIFOs are foundational IPC (Inter-Process Communication) mechanisms used in every Linux system. From the shell’s | operator to client-server architectures, understanding pipes is essential for any systems programmer.

Topics Covered

pipe() fork() + pipe SIGPIPE EPIPE pipe2() O_CLOEXEC O_NONBLOCK dup2() popen/pclose mkfifo() FIFO semantics Client-Server PIPE_BUF F_SETPIPE_SZ Atomic writes

All Files in This Series

File 1
๐Ÿ“ก Pipes Introduction

The fundamentals โ€” what pipes are, how they work internally, and the pipe() system call.

pipe() syscall fd[0] read end fd[1] write end Byte stream Kernel buffer Pipe vs FIFO
File 2
๐Ÿ”€ Pipes with fork() โ€” Parent-Child IPC

How to use pipes between parent and child processes, including bidirectional communication and sibling communication.

fork() + pipe() FD inheritance Close unused ends EOF detection Bidirectional (two pipes) Sibling processes
File 3
๐Ÿšซ Closing Unused FDs โ€” SIGPIPE and EPIPE

Why closing unused pipe ends is mandatory, what SIGPIPE is, and how to handle broken pipes gracefully.

Why close unused ends EOF rule SIGPIPE signal EPIPE errno SIG_IGN pattern Reference count
File 4
๐Ÿ”ง pipe2() โ€” Linux Extension

The Linux-specific pipe2() call with O_CLOEXEC and O_NONBLOCK flags, eliminating race conditions.

pipe2() flags O_CLOEXEC FD_CLOEXEC O_NONBLOCK EAGAIN Race condition fix
File 5
๐Ÿš Shell Pipelines and popen()

How to implement shell-style pipelines in C using dup2() and exec(), plus the convenient popen/pclose API.

dup2() STDIN redirect STDOUT redirect Multi-stage pipeline popen() pclose()
File 6
๐Ÿ“‚ FIFOs โ€” Named Pipes

Named pipes with filesystem entries, created with mkfifo(). Any two unrelated processes can communicate.

mkfifo() mknod() S_IFIFO Filesystem entry Blocking open() unlink() Unrelated processes
File 7
๐Ÿ”“ FIFO Open Semantics

Complete rules for how open() behaves on FIFOs in blocking and nonblocking modes, plus EOF and re-open behaviour.

Rendezvous behaviour O_NONBLOCK rules ENXIO error EOF on FIFO FIFO re-open O_RDWR trick
File 8
๐Ÿ–ฅ๏ธ FIFO Client-Server Pattern

Building a multi-client server using FIFOs โ€” well-known server FIFO, per-client response FIFOs, and atomic writes.

Well-known FIFO Per-client FIFO Request/Response struct Multiple writers PIPE_BUF atomicity Server loop
File 9
โš›๏ธ Pipe Capacity and Atomicity

Deep dive into pipe buffer sizes, PIPE_BUF atomic write guarantee, F_SETPIPE_SZ tuning, and safe partial-write handling.

65536 byte default PIPE_BUF = 4096 Atomic guarantee F_SETPIPE_SZ F_GETPIPE_SZ write_all() loop

Start Learning

Begin with File 1 and follow the series in order for the best learning experience.

Start: File 1 โ€” Pipe Introduction โ†’ Jump to File 9 โ€” Advanced

Leave a Reply

Your email address will not be published. Required fields are marked *