Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

pipe - create pipe

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

int pipe(int fildes[2]);

Description

pipe() creates a pipe and places two file descriptors, which refer to the open file
descriptions for the read and write ends of the pipe, into the arguments fildes[0] and
fildes[1]. These integer values are the two lowest available at the time of the pipe() call.
The O_NONBLOCK bit is not set for either of the two file descriptors (the fcntl() function
can be used to set the O_NONBLOCK bit).

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

A process has the pipe open for reading if it has a file descriptor open that refers to the read
end of the pipe, i.e. fildes[0]; the same applies to writing and the write end, i.e. fildes[1].

Upon successful completion, pipe() will mark the stat structure components of the pipe,
i.e. st_atime, st_ctime and st_mtime, for update.

The FD_CLOEXEC bit is not set for either of the two file descriptors.

Return val.

0

if successful.


-1

if an error occurs. errno is set to indicate the error.

Errors

pipe() will fail if:

 

EMFILE

{OPEN_MAX} minus 2 file descriptors are already open for this process.

 

ENFILE

The number of simultaneously open files in the system would exceed a system-imposed limit.

Notes

pipe() is executed only for POSIX files.

See also

fcntl(), read(), write(), unistd.h.