
Here's a preview from my zine, Bite Size Linux!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
panel 1
Sometimes you want to send the output of one process to the input of another
$ ls | wc -l
53
(53 files!)
a pipe is a pair of 2 magical file descriptors
Illustration of a tube where the left side is labelled “IN” and the right side is labelled “OUT”. There is an arrow between them. “IN” is labelled “pipe input” and “OUT” is labelled “pipe output”
stdin
-> ls
-> IN -> OUT -> wc
-> stdout
panel 3
when ls
does write (IN, “hi”) wc
can read it!
read (OUT) -> “hi”
Pipes are one way -> You can’t write to OUT.
Linux creates a buffer for each pipe
ls
-> IN [Buffer: data waiting to be read] OUT -> wc
If data gets written to the pipefaste than it’s read, the buffer will fill up.
When the buffer is full, writes to IN will block (wait) until the reader reads. This is normal & ok (smiley face).
what if your target process dies?
-> ls
-> [dead IN face] [dead OUT face] -> [dead wc
face] ->
If wc
dies, the pipe will close and ls
will be sent SIGPIPE
. By default, SIGPIPE
terminates your process.
named pipes
$ mkfifo my-pipe
This lets 2 unrelated pocesses communicate through a pipe
process 1, wearing a hat:
f=open(./my_pipe)
f.write("hi!\n")
process 2, with curly hair:
f=open(./my_pipe)
f.readline() <- "hi!"
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!