We will start by defining a macro called BUFFSIZE of size 255 and a string called str of size BUFFSIZE, that is, 255 characters. We will open the FIFO special file named FIFOPipe in read-only mode by invoking the open function. The file descriptor of the opened FIFO special file will be assigned to the fr variable.
Using the read function, the text from the FIFO special file will be read and assigned to the str string variable. The text that's read from the FIFO special file will then be displayed on the screen. Finally, the FIFO special file will be closed.
Now, press Alt + F2 to open a second Terminal window. In the second Terminal window, let's use GCC to compile the readfifo.c program, as follows:
$ gcc readfifo.c -o readfifo
If you get no errors or warnings, this means that the readfifo.c program has compiled into an executable file, readfifo.exe. Let's run this executable file:
$ ./readfifo
Read from the FIFO Pipe: This is a named pipe demo example called FIFO
The moment you run the readfifo.exe file, you will find, that on the previous Terminal screen where writefifo.c program was run will prompt you to enter a string. The moment you enter a string on that Terminal and press Enter key, you will get the output from the readfifo.c program.
Voila! We've successfully communicated between processes using a FIFO. Now, let's move on to the next recipe!