Course contents 25 / 32

25 / 32 · Processes and Concurrency

Inter-process communication

How processes that share no memory exchange data and events through the kernel: pipes and FIFOs, signals and what a handler may safely do, shared memory guarded by a semaphore, message queues, and how to choose among them.

On this page 7

The previous note made threads that share one address space take turns with locks. Processes start from the opposite end. Each has a private address space, so no process can corrupt another’s data, and for the same reason no process can simply hand another a value: there is no variable they both see. Every channel between processes therefore goes through the kernel, which owns the only resources that several processes can name. This note covers the classic channels on Unix: pipes and FIFOs for streams of bytes, signals for events, shared memory for bulk data with a semaphore to coordinate it, and message queues for discrete messages, and ends with how to choose among them.

Baseline: communicating through a file#

Two processes can already talk through the file system. A producer writes its results to results.txt; a consumer reads the file. It works, and it is how many batch pipelines pass data, but as a channel between running processes it fails in four ways:

  • No end-of-message signal. The consumer cannot tell whether the producer has finished writing or is halfway through a line; it must poll, and it may read a partial result.
  • No waiting. A consumer that finds the file empty can only sleep and try again, wasting time or adding delay.
  • Names and cleanup. Two runs that pick the same name overwrite each other, and a crashed producer leaves the file behind.
  • Cost. Every byte goes through the file system, and possibly to the disk, although it is needed only once, by one reader, a moment later.

What the processes need is a channel that the kernel keeps in memory, that blocks a reader until data is there, that tells the reader when the writer is done, and that disappears when the processes do.

Pipes#

pipe(fd) creates a buffer in the kernel and returns two file descriptors: fd[0] reads from the buffer and fd[1] writes to it (Kerrisk, 2010, chapter 44). Data comes out in the order it went in, as a stream of bytes. The kernel does the waiting: read on an empty pipe blocks until some data arrives, and write to a full pipe blocks until the reader has made room. When every write end is closed, read returns 0, the end of file. When every read end is closed, write fails with EPIPE and the kernel sends the writer the signal SIGPIPE, whose default action ends the process: that is why yes | head -1 terminates.

A pipe has no name, so it connects only processes that inherit its descriptors: a process creates the pipe and then forks, and the processes note showed that fork copies the file table. To give the pipe one direction, each process closes the end it does not use.

Figure

A pipe between a parent and a child that runs tr

A pipe between a parent and a child that runs trOn the left the descriptor table of the parent, on the right that of the child, in the middle the pipe buffer in the kernel. After pipe, the parent's descriptor 3 is the read end and 4 the write end. After fork the child has the same table. Then the parent closes 3, the child closes 3 and 4, its descriptor 0 now refers to the read end, and it runs tr. The parent writes to 4, the bytes pass through the buffer to the child's descriptor 0, and tr prints them in capitals. When the parent closes 4, read in tr returns 0.parent0terminal1terminal2terminal3pipe: read end4pipe: write endkernelpipe buffer1child (copy of the parent)0terminal1terminal2terminal3pipe: read end4pipe: write end2closedclosedclosedpipe: read endchild: tr a-z A-Z3writereadbytes␣thstdout: BYTES THROUGH A PIPE4closedread() → 0: end of file5A pipe between a parent and a child that runs trOn the left the descriptor table of the parent, on the right that of the child, in the middle the pipe buffer in the kernel. After pipe, the parent's descriptor 3 is the read end and 4 the write end. After fork the child has the same table. Then the parent closes 3, the child closes 3 and 4, its descriptor 0 now refers to the read end, and it runs tr. The parent writes to 4, the bytes pass through the buffer to the child's descriptor 0, and tr prints them in capitals. When the parent closes 4, read in tr returns 0.parent0terminal1terminal2terminal3pipe: read end4pipe: write endpipe buffer1child (copy of the parent)0terminal1terminal2terminal3pipe: read end4pipe: write end2closedclosedclosedpipe: read endchild: tr a-z A-Z3writereadbytes␣thstdout: BYTES THROUGH A PIPE4closedread() → 0: end of file5
Descriptors are row numbers in each process's file table; the pipe is a buffer in the kernel that two of them refer to. The red arrow is the parent's write to descriptor 4, the blue one the child's read from descriptor 0. Without closing the unused ends the child would never see end of file, because it would still hold a write end itself. The buffer held 65,536 bytes on the machine of the Code section.
  1. The parent calls pipe(fd). The kernel creates the buffer; the parent gets descriptors 3 (read end) and 4 (write end).
  2. The parent forks. The child’s file table is a copy, so both processes now hold both ends.
  3. The child closes the write end, uses dup2(3, 0) to make the read end its standard input, closes 3, and executes tr a-z A-Z. The parent closes the read end.
  4. The parent writes bytes through a pipe\n. The kernel copies the 21 bytes into its buffer; tr reads them from descriptor 0 as it would read a terminal, and prints BYTES THROUGH A PIPE.
  5. The parent closes the write end. It was the last one open, so tr’s next read returns 0, and tr exits.

Closing the unused ends is not housekeeping. If the child kept its own copy of the write end, the pipe would never lose its last writer, tr would wait for input forever, and so would the parent in waitpid.

This is how a shell runs ls | wc -l: it creates a pipe, forks twice, makes the write end the standard output of the child that executes ls and the read end the standard input of the child that executes wc, and closes both ends in itself. Neither program knows that it talks to the other.

How much a pipe holds. On the Apple M1 used here (macOS 26), a writer that never reads could put 65,536 bytes into a pipe before a non-blocking write failed with EAGAIN (the Code section). Linux gives a pipe 16 pages, 65,536 bytes with 4 KiB pages, by default (pipe(7)). Programs must not rely on either number: a writer simply blocks while the pipe is full. A related guarantee does matter. A write of at most PIPE_BUF bytes is atomic: when several processes write into one pipe, such a write is never interleaved with the bytes of another. POSIX requires PIPE_BUF to be at least 512; it is 512 on macOS and 4,096 on Linux.

A stream, not messages. Two writes of 10 bytes may be read as one read of 20, and a write of 100 may arrive in two reads of 50. A program that sends records over a pipe must mark their boundaries itself: a newline after each line, or a length before each record.

FIFOs: pipes with a name#

A FIFO, or named pipe, is a pipe with an entry in the file system. mkfifo("/tmp/jobs", 0600) creates it; afterwards any process with permission can open it, one for reading and another for writing, without being related. Opening a FIFO for reading blocks until some process opens it for writing, and the other way round, which makes the two processes meet. The data never touches the disk: the name is just a way to find the kernel’s buffer. In a shell, mkfifo /tmp/f; wc -c < /tmp/f & ls > /tmp/f connects two programs that were started separately.

Signals#

A signal is a notification that the kernel delivers to a process asynchronously, at whatever instruction the process happens to be executing (Kerrisk, 2010, chapters 20–22; Bryant and O’Hallaron, 2016, §8.5). It carries no data beyond its number. Signals come from three places:

  • Other processes, through kill(pid, sig) (and the kill command): SIGTERM asks a process to terminate, SIGKILL forces it, SIGUSR1 and SIGUSR2 mean whatever the program decides.
  • The terminal: Ctrl-C sends SIGINT, Ctrl-Z SIGTSTP.
  • The kernel itself: SIGSEGV for an invalid memory access and SIGFPE for an arithmetic error, each the user-visible end of an exception; SIGCHLD when a child exits; SIGPIPE for a write to a pipe with no reader.

Each signal has a default action: terminate the process (most of them), terminate and write a core dump (SIGSEGV, SIGQUIT), ignore (SIGCHLD), stop (SIGTSTP, SIGSTOP) or continue (SIGCONT). A process can replace the action with ignore or with a handler, a function the kernel calls when the signal arrives, except for SIGKILL and SIGSTOP, which always take effect.

How a handler runs. A signal sent to a process is first marked pending in its PCB. When the process next returns from the kernel to user mode, after a system call, an interrupt or a time slice, the kernel checks for pending signals that are not blocked. For each one with a handler it saves the process’s registers on the user stack, arranges for execution to continue at the handler, and makes the handler’s return enter the kernel through sigreturn, which restores the saved registers. The interrupted code then continues as if nothing had happened. A system call that was blocked when the signal arrived, such as a read on an empty pipe, returns −1-1 with errno set to EINTR unless the handler was installed with SA_RESTART.

Install handlers with sigaction, which states exactly what happens; the older signal function behaves differently between systems. sigprocmask blocks and unblocks signals: a blocked signal stays pending until it is unblocked. Standard signals are not queued: pending is a single bit per signal. In the Code section a process blocks SIGUSR1, sends it to itself three times, and unblocks it; the handler runs once.

Async-signal safety. A handler can interrupt the main program at any instruction, including in the middle of malloc updating its free list or printf filling its buffer. If the handler then calls malloc or printf itself, it works on a data structure that is half updated, and the program can crash or deadlock on a lock that the interrupted code holds. POSIX therefore lists the functions that are async-signal-safe, safe to call from a handler: write, read, _exit, kill, sigaction and others, but not printf, malloc or exit (signal-safety(7)). The usual pattern does almost nothing in the handler: it sets a flag of type volatile sig_atomic_t, which can be written in one step, and the main loop checks the flag and does the real work.

static volatile sig_atomic_t stop = 0;
static void on_term(int sig) { (void)sig; stop = 1; }     /* only set the flag */
/* main loop: while (!stop) { serve_one_request(); }  then clean up and exit */

Shared memory#

A pipe copies every byte twice: write copies it from the sender’s buffer into the kernel, read copies it from the kernel into the receiver’s buffer. For large data, such as video frames or a database’s cache, those copies dominate. Shared memory removes them: the kernel maps the same physical pages into two address spaces, and a store by one process is visible to a load by the other (Kerrisk, 2010, chapter 54).

The POSIX interface uses the same calls as files and memory-mapped files:

  1. int fd = shm_open("/acos-demo", O_CREAT | O_RDWR, 0600) creates or opens a shared-memory object by name.
  2. ftruncate(fd, size) sets its size; a new object is empty.
  3. void *p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) maps it. MAP_SHARED is what makes stores visible to other processes; with MAP_PRIVATE each process would get copy-on-write pages of its own.
  4. close(fd); the mapping stays valid. munmap removes the mapping, and shm_unlink removes the name. The object itself disappears when the name is gone and no process maps it.

Another process that opens the same name and maps it sees the same bytes. Related processes can skip the name: an anonymous mapping created with MAP_SHARED | MAP_ANONYMOUS before fork is shared by parent and child.

Figure

Shared memory: one physical frame in two address spaces

Shared memory: one physical frame in two address spacesThree vertical bars: the address space of process A, physical memory, and the address space of process B. Each process has a stack, a heap, code and a shared region, lower in A and higher in B. Arrows from both shared regions lead to the same highlighted frame of physical memory.process Aphysical memoryprocess Bvirtual addressesvirtual addressesstacksharedheapcodestacksharedheapcodeA's page tableB's page tableboth: shm_open("/acos-demo"),then mmap(..., MAP_SHARED, ...)Shared memory: one physical frame in two address spacesThree vertical bars: the address space of process A, physical memory, and the address space of process B. Each process has a stack, a heap, code and a shared region, lower in A and higher in B. Arrows from both shared regions lead to the same highlighted frame of physical memory.process Aphysical memoryprocess Bstacksharedheapcodestacksharedheapcodeboth: shm_open("/acos-demo"),then mmap(..., MAP_SHARED, ...)
After shm_open and mmap with MAP_SHARED, the page tables of the two processes translate different virtual addresses to the same physical frame (blue). A store by one process is visible to the other at once, with no copy through the kernel; the kernel provides no waiting and no mutual exclusion either. Because the region sits at different addresses, a pointer stored in it by one process is meaningless to the other: shared structures store offsets.

The two mappings usually start at different virtual addresses, since each process’s mmap picks a free range in its own address space. A pointer stored in the shared region by one process is therefore meaningless to the other; shared data structures store offsets from the start of the region instead.

Shared memory needs synchronization. The kernel does nothing after the mapping is set up: no copying, but also no waiting and no mutual exclusion. Two processes that increment a shared counter race exactly as the threads of the previous note did, and a reader can see a record that the writer has half written. A named semaphore coordinates them: sem_open("/acos-lock", O_CREAT, 0600, 1) gives every process that opens the same name the same semaphore. In the Code section a parent and a child each increment a counter in shared memory 100,000 times under a semaphore initialized to 1, used as a lock, and the total is exactly 200,000; a second semaphore, initialized to 0, lets the child tell the parent that a message is ready, so the parent sleeps in sem_wait instead of polling. (A process-shared mutex, pthread_mutexattr_setpshared with PTHREAD_PROCESS_SHARED, placed in the shared region, does the same job where it is supported.)

Message queues#

A message queue keeps discrete messages instead of a byte stream: each send adds one message, each receive removes one whole message, and the boundaries are preserved. POSIX message queues (Kerrisk, 2010, chapter 52) are opened by name with mq_open, and every message carries a priority: mq_receive returns the oldest message of the highest priority (mq_receive(3)). On Linux a queue created without attributes holds at most 10 messages of up to 8,192 bytes each (mq_overview(7)); a sender blocks when the queue is full and a receiver when it is empty.

/* POSIX message queues. Linux only (macOS has no <mqueue.h>); run in a Debian 13 container, glibc 2.41, arm64.
   Compile with -lrt on older glibc. */
#include <fcntl.h>
#include <mqueue.h>
#include <stdio.h>
#include <string.h>

int main(void) {
    struct mq_attr attr = { .mq_maxmsg = 10, .mq_msgsize = 64 };
    mqd_t q = mq_open("/acos-q", O_CREAT | O_RDWR, 0600, &attr);
    mq_send(q, "low",  strlen("low") + 1, 1);
    mq_send(q, "high", strlen("high") + 1, 7);
    mq_send(q, "mid",  strlen("mid") + 1, 4);
    char buf[64]; unsigned prio;
    for (int i = 0; i < 3; i++) {
        mq_receive(q, buf, sizeof buf, &prio);      /* the oldest message of the highest priority */
        printf("%s (%u)\n", buf, prio);             /* high (7), mid (4), low (1) */
    }
    mq_close(q);
    mq_unlink("/acos-q");
    return 0;
}

The older System V interface (msgget, msgsnd, msgrcv) exists on both Linux and macOS (Kerrisk, 2010, chapter 46). Its messages carry a positive type instead of a priority, and a receiver can ask for the first message of a given type, so several kinds of request can share one queue. The runnable example in the Code section uses it. Its objects are identified by numeric keys rather than names and outlive the processes until they are removed explicitly, which makes them easy to leak.

Choosing among them#

ChannelDataBoundariesWho can use itWaiting built inCopies per byte
Pipebytes, one directionnonerelated processes (inherited descriptors)yes2
FIFObytes, one directionnoneany process that can open the pathyes2
Signala numberone eventany process with permission to killhandler runs asynchronously—
Shared memoryanythingdefined by the processesany process that can open the nameno: add a semaphore0
Message queuemessagespreservedany process that can open the nameyes2
Socketbytes or datagramsdepends on the typeprocesses on this or another machineyes2

Some rules of thumb follow from the table. A pipe is the default for a stream from one process to another, and the shell builds pipelines out of nothing else. Signals are for events, not data: stop, reload the configuration, a child has exited. Shared memory is for large data that several processes read and update in place, and only with a synchronization protocol designed together with the data layout. Message queues suit requests and replies of moderate size where each message matters on its own. And when the processes may run on different machines, or the program should be ready for that, sockets offer the same read/write interface over a network.

What changed#

Communicating through a fileKernel channels
Where the data livesthe file system, possibly the diska kernel buffer, or pages mapped into both processes
Waiting for datapollingread and mq_receive block; a semaphore for shared memory
End of dataunknownend of file when the last writer closes
Eventsnonesignals
Cleanupfiles left behindpipes vanish with the processes; named objects need unlink
Copieswrite and read through the page cache2 for pipes and queues, 0 for shared memory

Limitations#

  • Pipes and FIFOs carry bytes without structure. The processes must agree on a framing, and a FIFO with several writers interleaves anything longer than PIPE_BUF.
  • Signals are coarse and fragile. One bit per standard signal, no data, handlers restricted to async-signal-safe calls, and system calls interrupted with EINTR.
  • Shared memory puts correctness on the programmer. It needs a synchronization protocol, offsets instead of pointers, and care when a process dies while holding the lock.
  • Named objects persist. A crashed program leaves shared-memory objects, semaphores and System V queues behind until they are unlinked or the machine reboots.
  • Portability. macOS lacks POSIX message queues and unnamed semaphores; System V queues behave slightly differently between systems.

What you should remember#

  • Processes share nothing, so they communicate through kernel objects: buffers that the kernel copies through, or pages it maps into both.
  • pipe returns a read end and a write end; after fork each process closes the end it does not use. read returns 0 only when every write end is closed; a write with no reader raises SIGPIPE.
  • A shell pipeline is pipe, fork, dup2 onto descriptors 0 and 1, and exec. A FIFO is a pipe with a name for unrelated processes.
  • A pipe is a byte stream; writes up to PIPE_BUF bytes are atomic. Capacity is 64 KiB on the macOS machine here and by default on Linux, but programs should not rely on it.
  • A signal is an asynchronous event with a default action; sigaction installs a handler, sigprocmask blocks. Standard signals do not queue. A handler may call only async-signal-safe functions: set a volatile sig_atomic_t flag.
  • Shared memory (shm_open, ftruncate, mmap with MAP_SHARED) avoids copies and needs a semaphore or a process-shared mutex.
  • Message queues preserve message boundaries; POSIX queues add priorities and exist on Linux, System V queues on both systems.

Code#

A pipe from a parent to a child that runs tr, then the capacity of a pipe. Compile and run with clang -std=c17 -Wall -Wextra -O0 pipe.c -o pipe && ./pipe:

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

int main(void) {
    /* 1. parent | tr a-z A-Z: the parent writes, a child running tr reads */
    int fd[2];
    if (pipe(fd) < 0) { perror("pipe"); return 1; }  /* fd[0] is the read end, fd[1] the write end */
    pid_t pid = fork();
    if (pid == 0) {
        close(fd[1]);                                /* the reader keeps only the read end */
        dup2(fd[0], STDIN_FILENO);                   /* tr reads its stdin from the pipe */
        close(fd[0]);
        execlp("tr", "tr", "a-z", "A-Z", (char *)NULL);
        _exit(127);
    }
    close(fd[0]);                                    /* the writer keeps only the write end */
    const char *msg = "bytes through a pipe\n";
    write(fd[1], msg, strlen(msg));
    close(fd[1]);                                    /* last write end closed: tr sees end of file */
    waitpid(pid, NULL, 0);

    /* 2. how much a pipe holds before a writer would block */
    pipe(fd);
    fcntl(fd[1], F_SETFL, O_NONBLOCK);               /* fail with EAGAIN instead of blocking */
    char page[4096] = {0};
    long total = 0;
    ssize_t n;
    while ((n = write(fd[1], page, sizeof page)) > 0) total += n;
    printf("capacity: %ld bytes (%s)\n", total, errno == EAGAIN ? "then EAGAIN" : strerror(errno));
    return 0;
}
/* Output (the capacity on macOS 26, Apple M1; Linux also gives 65536 by default):
BYTES THROUGH A PIPE
capacity: 65536 bytes (then EAGAIN)
*/

Signals: a handler installed with sigaction, three signals sent while blocked, and a child terminated by SIGTERM:

#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

static volatile sig_atomic_t hits = 0;

static void on_usr1(int sig) {
    (void)sig;
    hits++;                                          /* only async-signal-safe work here */
    write(STDOUT_FILENO, "  handler ran\n", 14);     /* write is async-signal-safe; printf is not */
}

int main(void) {
    struct sigaction sa;
    memset(&sa, 0, sizeof sa);
    sa.sa_handler = on_usr1;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGUSR1, &sa, NULL);

    sigset_t block, old;
    sigemptyset(&block);
    sigaddset(&block, SIGUSR1);
    sigprocmask(SIG_BLOCK, &block, &old);            /* hold SIGUSR1 pending */
    for (int i = 0; i < 3; i++) kill(getpid(), SIGUSR1);
    printf("sent 3 while blocked, hits=%d\n", (int)hits);
    fflush(stdout);
    sigprocmask(SIG_SETMASK, &old, NULL);            /* unblock: the pending signal is delivered */
    printf("after unblocking, hits=%d (standard signals do not queue)\n", (int)hits);

    pid_t child = fork();
    if (child == 0) { pause(); _exit(0); }           /* sleeps until a signal arrives */
    sleep(1);
    kill(child, SIGTERM);                            /* no handler in the child: default action, terminate */
    int status;
    waitpid(child, &status, 0);
    printf("child terminated by SIGTERM: %s\n", WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM ? "yes" : "no");
    return 0;
}
/* Output:
sent 3 while blocked, hits=0
  handler ran
after unblocking, hits=1 (standard signals do not queue)
child terminated by SIGTERM: yes
*/

Shared memory between a parent and a child, with one named semaphore as a lock and another as a signal:

#include <fcntl.h>
#include <semaphore.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>

struct shared { long counter; char text[64]; };      /* the layout both processes agree on */
#define N 100000

int main(void) {
    int fd = shm_open("/acos-demo", O_CREAT | O_RDWR, 0600);
    if (fd < 0) { perror("shm_open"); return 1; }
    ftruncate(fd, sizeof(struct shared));            /* a new object has size 0 */
    struct shared *s = mmap(NULL, sizeof *s, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    close(fd);                                       /* the mapping stays valid */
    memset(s, 0, sizeof *s);

    sem_t *lock = sem_open("/acos-lock", O_CREAT, 0600, 1);   /* 1: a binary semaphore used as a lock */
    sem_t *ready = sem_open("/acos-ready", O_CREAT, 0600, 0); /* 0: nothing posted yet */
    if (lock == SEM_FAILED || ready == SEM_FAILED) { perror("sem_open"); return 1; }

    pid_t pid = fork();
    for (int i = 0; i < N; i++) {                    /* parent and child both run this loop */
        sem_wait(lock);
        s->counter++;
        sem_post(lock);
    }
    if (pid == 0) {
        snprintf(s->text, sizeof s->text, "hello from the child");
        sem_post(ready);                             /* tell the parent the text is there */
        _exit(0);
    }
    sem_wait(ready);                                 /* sleeps until the child posts */
    printf("text: %s\n", s->text);
    waitpid(pid, NULL, 0);
    printf("counter=%ld (expected %d)\n", s->counter, 2 * N);

    munmap(s, sizeof *s);
    shm_unlink("/acos-demo");                        /* remove the names; the objects go when unused */
    sem_close(lock); sem_close(ready);
    sem_unlink("/acos-lock"); sem_unlink("/acos-ready");
    return 0;
}
/* Output:
text: hello from the child
counter=200000 (expected 200000)
*/

A System V message queue, which runs on both Linux and macOS: messages keep their boundaries, and a receiver can pick a message by type:

#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>

struct note { long type; char text[32]; };          /* the type must be positive */

int main(void) {
    int q = msgget(IPC_PRIVATE, IPC_CREAT | 0600);   /* a new queue, known only to this process tree */
    if (q < 0) { perror("msgget"); return 1; }
    const char *texts[] = {"job 1", "status?", "job 2"};
    long types[] = {1, 2, 1};                        /* 1 = job, 2 = query */
    for (int i = 0; i < 3; i++) {
        struct note m = { types[i], "" };
        strcpy(m.text, texts[i]);
        msgsnd(q, &m, strlen(m.text) + 1, 0);
    }
    struct note m;
    msgrcv(q, &m, sizeof m.text, 2, 0);              /* the first message of type 2, ahead of the jobs */
    printf("type %ld: %s\n", m.type, m.text);
    while (msgrcv(q, &m, sizeof m.text, 0, IPC_NOWAIT) >= 0)   /* type 0: the oldest message */
        printf("type %ld: %s\n", m.type, m.text);
    msgctl(q, IPC_RMID, NULL);                       /* System V queues persist until removed */
    return 0;
}
/* Output:
type 2: status?
type 1: job 1
type 1: job 2
*/

Next#

Every channel in this note lives only as long as the processes and the kernel that hold it: a pipe vanishes when its last descriptor is closed, and shared memory when it is unlinked and unmapped. The pipe, though, already looked like a file: a small integer passed to read and write. The next note turns to real files, data that outlives the program that wrote it: what a descriptor refers to inside the kernel, why buffering matters, and how a file system finds the bytes of a file by its name.

References#