FIFO – Interprocess Communication

By | September 26, 2021

First In First Out FIFO – Interprocess Communication

  • A FIFO is a named pipe used as a permanent file in UNIX.
  • FIFO pipe operates on the basis of first-in-first-out order and are managed as buffers from within the kernel.
  • A FIFO can be created by the mknod shell command or system call. ‘mknod‘ stands for make node and is used to create non regular directory entries such as special files (device entries), directories and FIFOS.
  • A FIFO is an empty file.

A typical command to create a FIFO is :

$/etc/mknode npipe P

The parameter P specifies that a pipe is required. An entry will now appear in the current directory:

$ls -1 npipe

prw-rw-rw-1 ritchie staff O Aug 15 10:26 npipe

  • The ‘p’ in the first position indicates that it is named pipe. The zero indicates the current file size i.e. as one would expect, it is empty.
  • A FIFO offers the same communication facility as the unnamed pipe and has a name in the file system so that it can be accessed like a file. This allows the named pipe to be used between unrelated processes.

FIFO - Interprocess Communication

  • Since FIFO has all the characteristics of a conventional file, the FIFO can be opened by any number of processes for reading and writing.
  • However, it has to be opened at both ends before one can proceed to perform any input or output operation on it.
  • As FIFO is a named file, the users must have suitable access permissions to perform operations on it.
  • In UNIX, FIFO can be used connect standard output of one command to the standard input of another. For the symbol | is used as a ‘connector’ for linking two commands.

For example, the output of Is command becomes the input to the we command, which counts the number of lines in its input data.

$ ls *.C
$ls *.C | wc-l
  • The above operation is performed like this :

FIFO - Interprocess Communication Example

  • More than two commands can be connected by pipes, one after the other.

Leave a Reply

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