[Previous]
[Contents]
[Next]

pipe()

create a pipe

Synopsis:

#include <unistd.h>
int pipe( int fildes[2] );

Description:

The pipe() function creates a pipe (an unnamed FIFO) and places a file descriptor for the read end of the pipe in fildes[0], and a file descriptor for the write end of the pipe in fildes[1]. Their integer values are the two lowest available at the time of the pipe() function call. The O_NONBLOCK flag is cleared for both file descriptors. (The fcntl() call can be used to set the O_NONBLOCK flag.)

Data can be written to file descriptor fildes[1] and read from file descriptor fildes[0]. A read on file descriptor fildes[0] returns the data written to fildes[1] on a first-in-first-out (FIFO) basis.

The pipe buffer is allocated by the resource manager responsible for /pipe, or if /pipe cannot be located, the resource manager responsible for / is used.

This function is typically used to connect together standard utilities to act as filters, passing the write end of the pipe to the data producing process as its STDOUT_FILENO, and the read end of the pipe to the data-consuming process as its STDIN_FILENO (either via the traditional fork(), dup2() or exec(), or the more efficient spawn() calls).

If successful, pipe() marks for update the st_ftime, st_ctime, st_atime and st_mtime fields of the pipe for updating.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EMFILE
The calling process doesn't have at least 2 unused file descriptors available.
ENFILE
The number of simultaneously open files in the system would exceed the configured limit.
ENOSPC
There is insufficient space available to allocate the pipe buffer.
EROFS
The pipe pathname space is a read-only file system.

Examples:

See fork().

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, fcntl(), open(), read(), write()


[Previous]
[Contents]
[Next]