Using FIFOs

[problem]

You want to create and use an UNIX FIFO.

[/problem]

[solution]

FIFO means first in, first out.

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

[/solution]

[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

[/example]

[reference]

– as always an excellent description on wikipedia

[/reference]

[reference]

[tags]FIFO, Named Pipes, mknod, Unix Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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