- Open the FIFO special file in read-only mode by invoking the open function.
- Read the text from the FIFO special file using the read function.
- Close the FIFO special file.
The readfifo.c program for reading from the named pipe (FIFO) is as follows:
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#define BUFFSIZE 255
int main()
{
int fr;
char str[BUFFSIZE];
fr = open("FIFOPipe", O_RDONLY);
read(fr, str, BUFFSIZE);
printf("Read from the FIFO Pipe: %s\n", str);
close(fr);
return 0;
}
Let's go behind the scenes.