pipe

Creates an inter-process channel.

Library:LibC
Classification:UNIX (nonstandard)
Service:File and Directory I/O

Syntax

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

Parameters

fildes

(OUT) Specifies the file descriptions for the ends of the newly created pipe.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

10

ENFILE

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

11

EMFILE

More than (OPEN_MAX)-2 file descriptors are already in use.

Remarks

The pipe function creates a pipe and places two file descriptions (into fildes[0] and fildes[1]) for the read and write ends of the pipe. Their integer values are two lowest that are available at the time pipe is called. The O_NONBLOCK and FD_CLOEXEC flags, which can be set by calling fcntl, should be clear on both file descriptors.

Data can be written to fildes[1] and read from fildes[0]. A read on fildes[0] accesses the data written to 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, fildes[0]. A process has the pipe open for writing if it has a file descriptor open that refers to the write end, fildes[1].

Upon successful completion, pipe updates the st_atime, st_ctime, and st_mtime fields of the new pipe.

See Also