Using FIFOs

Problem

You want to create and use an UNIX FIFO.



Solution

FIFO means first in, first out.

To create a FIFO (also called a named pipe), UNIX supplies the mknod command.



Example


This is the code to generate a FIFO:


$ mknod myFIFO p

Then the resulting named pipe:


$ ls -ld myFIFO
prw-r--r-- 1 marcus adm 0 Jun 13 21:15 myFIFO

To use the FIFO, you need to have a process that is reading from it. This could be a bit of Perl, C code, etc.

A perfect way to demonstrate using FIFOs, is tail -f:


$ tail -f myFIFO

Then a test:


$ echo "
Hello there
This is a test of FIFOs
" > myFIFO

From the tail -f when now see following output:

Hello there
This is a test of FIFOs





Previous Post

Leave a Reply

Your email address will not be published. Required fields are marked *