
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
person with short curly hair, distressed and surrounded by question marks: I printed some text but it didn’t appear on the screen. why??
cheerful person with long straight hair: time to learn about flushing!
On Linux, you write to files & terminals with the system call <3 write
<3
process, represented by a box with a smiley face: please write “I <3 cats” to file #1 (stdout
)
Linux, also represented by a box with a smiley face: okay!
I/O libraries don’t always call write
when you print
printf("I <3 cats");
printf
: I’ll wait for a newline before actually writing
This is called buffering and it helps save on syscalls.
3 kinds of buffering
(defaults vary by library)
- None. this is the default for
stderr
- Line buffering (write after newline). The default for terminals.
- “full” buffering (write in big chunks). The default for files and pipes.
flushing
(little picture of a toilet)
To force your I/O library to write everything it has in its buffer right now, call flush
~
stdio
: I’ll call write
right away!
when it’s useful to flush
- when writing an interactive prompt!
Python example:
print ("password: ", flush=True)
- when you’re writing to a pipe/socket
program: no seriously, actually write to that pipe please