Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pipe

This document describes the pipe implementation in the Kyronix kernel. It is the child of Filesystems.

Source

kernel/fs/pipe.c, kernel/fs/fdpipe.c

Overview

Pipes provide unidirectional inter-process communication. The Kyronix kernel implements both anonymous pipes (pipe/pipe2) and named pipes (FIFOs).

Syscalls

SyscallNumberDescription
pipe22Create anonymous pipe
pipe2293Create pipe with flags (O_CLOEXEC, O_NONBLOCK)

Data Structure

typedef struct {
    uint8_t *buf;        // Ring buffer
    size_t   size;       // Buffer capacity
    size_t   read_pos;   // Read position
    size_t   write_pos;  // Write position
    size_t   count;      // Bytes available
    // Synchronization primitives for blocking read/write
} pipe_t;

Operations

OperationBehavior
read()Blocks if empty; reads up to requested bytes
write()Blocks if full; writes up to requested bytes
close()Signals EOF to readers/writers

Ancillary Data (SCM_RIGHTS)

Pipes support file descriptor passing via SCM_RIGHTS ancillary data on Unix domain sockets. This enables processes to share file descriptors across address spaces.

Blocking

Read and write operations block the calling process when the pipe is empty (read) or full (write). Blocked processes are moved to PROC_WAITING state and woken when data becomes available.

Last reviewed: 2026-07-22