Named Pipes (FIFOs)

Command lines are formed regularly under UNIX to pipe information from one process to another. These pipes are anonymous. When unrelated processes want to pipe information, they usually require the help of a named pipe. Because pipes process information on a first-in, first-out basis, they are also known as FIFOs.

A FIFO can be created from a C/C++ program using the mkfifo(2) function. The function synopsis is as follows:

#include <sys/types.h>
#include <sys/stat.h>

int mkfifo(const char *path, mode_t mode);

The FIFO is created with the pathname path with permissions specified by the argument mode. The permission bits in mode are subject to the current umask(2) value in effect.

The function mkfifo(2) returns 0 when successful or -1 with an error code in errno when it fails. The following shows how a named pipe, /tmp/my_pipe, can be created with read and write access for everyone (subject to the umask(2) setting):

if ( mkfifo("/tmp/my_pipe",0666) == -1 )
    /* Report errors */
else
    /* Successful */

Note

On some platforms, the mkfifo(2) call may be implemented in terms of another function. For example, SGI's IRIX 6.5 and Solaris 8 implement mkfifo(2) by calling mknod(path,(mode|S_IFIFO),0).


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.230