Fundamentals 15 min read

How Linux Pipes, FIFOs, and Signals Enable Interprocess Communication

This article explains the fundamentals of Linux pipes and named pipes (FIFOs), their kernel implementation, read/write APIs with code examples, and an overview of signal mechanisms, types, and handling in the context of inter‑process communication.

ITPUB
ITPUB
ITPUB
How Linux Pipes, FIFOs, and Signals Enable Interprocess Communication

Pipe Overview

Pipes provide a buffered communication channel between related processes; named pipes (FIFOs) extend this capability to unrelated processes by giving the pipe a pathname in the file system.

Implementation Mechanism

In Linux the pipe is not a special data structure but a kernel‑managed buffer backed by a VFS inode. Two file structures point to the same temporary inode, which in turn references a physical memory page. The kernel abstracts pipe operations as ordinary file reads and writes.

Read/Write Functions

The core pipe functions reside in fs/pipe.c. The most important are pipe_read() and pipe_write(), which copy data between user buffers and the memory page referenced by the inode. Access is synchronized with locks, wait queues, and signals.

#include <unistd.h>
int pipe(int filedes[2]);

Typical usage requires closing the unused end of the descriptor in each process.

int main(void) {
    int n;
    int fd[2];
    pid_t pid;
    char line[MAXLINE];
    if (pipe(fd) < 0) { exit(0); }
    if ((pid = fork()) < 0) exit(1);
    else if (pid > 0) { /* parent writes */
        close(fd[0]);
        write(fd[1], "
hello world
", 14);
    } else { /* child reads */
        close(fd[1]);
        n = read(fd[0], line, MAXLINE);
        write(STDOUT_FILENO, line, n);
    }
    exit(0);
}

Named Pipe (FIFO)

FIFOs are created with mkfifo() (or mknod() with S_IFIFO) and appear as special files in the file system. One process opens the FIFO for reading, another for writing, and the kernel connects them without involving the disk.

#include <sys/types.h>
#include <sys/stat.h>
int mkfifo(const char *filename, mode_t mode);
int mknod(const char *filename, mode_t mode | S_IFIFO, (dev_t)0);
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
int main() {
    int res = mkfifo("/tmp/my_fifo", 0777);
    if (res == 0) {
        printf("FIFO created
");
    }
    exit(EXIT_SUCCESS);
}

Compile with gcc -o fifo1 fifo1.c, run ./fifo1, and verify the FIFO with ls -lF /tmp/my_fifo (the leading p indicates a pipe).

Signal Basics

Signals are asynchronous notifications sent to a process to indicate events such as hardware interrupts, software conditions, or explicit calls like kill, raise, alarm, and sigaction. Each signal has a default action (usually termination) that can be ignored, caught, or restored.

Non‑ignorable signals: SIGKILL (forces termination) and SIGSTOP (stops the process).

Signal handlers are user‑space functions invoked when the process returns from kernel mode to user mode.

When a sleeping process receives a signal, the kernel may wake it depending on the sleep priority.

For SIGCHLD, the parent can install a handler to reap terminated children.

Signal handling must be performed in user space; the kernel never executes user‑defined handlers directly.

Signal types diagram
Signal types diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxIPCC programmingOS fundamentalssignalspipesnamed pipes
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.