Course contentsShow
← Linux
Lesson 42 of 1,8191. Shell Architecture and Process EnvironmentFree lesson

Named Pipes and Persistent Communication

Implement persistent FIFO buffers for asynchronous data exchange between independent shell processes.

In this lesson, you will learn how to create a permanent "bridge" between two independent terminal processes using Named Pipes, allowing them to pass data asynchronously without needing a parent-child relationship.

The Concept: Pipes That Stay

Standard pipelines (using the | operator) create a temporary connection that vanishes the moment your command finishes. A Named Pipe, or FIFO (First-In, First-Out), is different: it exists as a special file on your filesystem. Because it has a name, any process on your system can open it as a file, write data into it, or read data from it, even if those processes were started hours apart.

Creating and Using a FIFO

To create a named pipe, we use the mkfifo command. Think of this as creating a "mailbox" that both sides of your conversation can access.

  1. Create the pipe:

    mkfifo my_channel
    
  2. The Receiver (Terminal A): Open the pipe and wait for data. The process will "block" (pause) here until something is sent.

    cat < my_channel
    
  3. The Sender (Terminal B): Send data into the pipe. The data will flow directly into the waiting cat command in Terminal A.

    echo "Hello from the other side" > my_channel
    

Why this matters

In our previous lessons, we discussed environment variables and process inheritance, which are great for configuration. However, Named Pipes provide a dedicated "data lane." Because the FIFO file acts like a persistent buffer on your hard drive, it allows for asynchronous communication. You don't need to coordinate complex inheritance chains or shell sub-processes to move information; you simply point both processes to the same path on the disk. The operating system handles the internal buffering, ensuring the data passes safely between the processes regardless of when they start or stop.

Key Takeaway: Named Pipes allow independent processes to communicate by creating a permanent file-based buffer that persists beyond the lifetime of a single command.