Named pipes and Unix sockets

A FIFO is useful for streaming data between unrelated processes without a temporary regular file. A Unix domain socket is preferable for request/response protocols, multiple clients or bidirectional communication.

In terminal A:

cd ~/fs-lab
mkfifo feed
cat feed

In terminal B:

cd ~/fs-lab
printf 'hello from another process\n' > feed

cat exits when all writers close. A FIFO is a byte stream, not a message queue. For sockets, install socat if necessary and use two terminals:

# Terminal A
cd ~/fs-lab
socat UNIX-LISTEN:demo.sock STDIO
# Terminal B
cd ~/fs-lab
socat STDIO UNIX-CONNECT:demo.sock

Type in either terminal to send data to the other. Stop both processes before removing the socket and FIFO.

rm -f ~/fs-lab/demo.sock ~/fs-lab/feed

Which should I choose?

Use a FIFO for simple one-way streaming between unrelated programs. Use a Unix socket for a service that accepts connections and exchanges requests and replies. A regular anonymous shell pipe is simpler when both commands can be launched together.

Read the full filesystem tutorial .

Resources library · Random Linux Stuff! on YouTube