#define MAX_BUF 1024
char * myfifo = "/tmp/myfifo";
/* open, read, and display the message from the FIFO */
fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Received: %s\n", buf);
A named pipe, also called a FIFO for its behavior, can be used to connect two unrelated processes and exists independently of the processes; meaning it can exist even if no one is using it. A FIFO is created using the mkfifo() library function.
A regular pipe can only connect two related processes. It is created by a process and will vanish when the last process closes it.
I take it this example needs some tweaking to work on windows? unistd.h being POSIX and all...
Probably processes which are related via one or more parent/child relations (e.g. includes siblings). The common ancestor would have created the two ends of the pipe. Unrelated processes lack that common ancestor.
This will not work if the reader kicks off first. A quick fix would be to put the open() of the reader inside a loop. However +1 because you provide a two programs example.
Yes, it will need tweaking for Windows. The Wikipedia article on named pipes discusses some of the Unix/Windows differences and a quick Google search can help with the Windows implementation.