FIFO – building the sender
Now that we know what a FIFO is, we'll move on and write a program that can create and use a FIFO. In this recipe, we'll write a program that creates a FIFO and then sends a message to it. In the next recipe, we'll write a program that receives that message.
Knowing how to use FIFOs programmatically will enable you to write programs that can communicate between themselves using a FIFO directly, without needing to redirect the data via the shell.
Getting ready
We'll need the usual tools; that is, the GCC compiler, the Make tool, and the generic Makefile.
How to do it…
In this recipe, we'll write a program that creates a FIFO and sends a message to it:
- Write the following code in a file and save it as
fifo-sender.c
. This code is a bit longer, so we'll cover it step by step here. Remember that all the code goes in the same file. Let's start with the#include
lines, the prototype for the...