- Invoke the mkfifo function to create a new FIFO special file.
- Open the FIFO special file in write-only mode by invoking the open function.
- Enter the text to be written into the FIFO special file.
- Close the FIFO special file.
The writefifo.c program for writing into a FIFO is as follows:
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int fw;
char str[255];
mkfifo("FIFOPipe", 0666);
fw = open("FIFOPipe", O_WRONLY);
printf("Enter text: ");
gets(str);
write(fw,str, sizeof(str));
close(fw);
return 0;
}
Let's go behind the scenes.