Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh(1)

fork(2)

read(2)

socketpair(2)

write(2)

pipe(2)

Name

pipe − create an interprocess channel

Syntax

include <limits.h> /*Definition of PIPE_MAX*/

pipe(fildes)
int fildes[2];

Arguments

fildes Passing an address as an array of two integers into the pipe system call.

Description

The pipe system call creates an I/O mechanism called a pipe. The file descriptors returned can be used in read and write operations.  Their integer values will be the two lowest available at the time of the pipe function call.  The O_NONBLOCK and FD_CLOEXEC flags will be clear on both file descriptors.

When the pipe is written using the descriptor fildes[1], up to PIPE_MAX bytes of data are buffered before the writing process is suspended. A read using the descriptor fildes[0] picks up the data.

It is assumed that after the pipe has been set up, two (or more) cooperating processes (created by subsequent fork calls) pass data through the pipe with read and write calls.

The shell has a syntax to set up a linear array of processes connected by pipes. 

For further information on how read and write calls behave with pipes, see the read() and write() reference pages.

A signal is generated if a write on a pipe with only one end is attempted. 

Restrictions

Should more than 4096 bytes be necessary in any pipe among a loop of processes, deadlock may occur. 

The underlying implementation of pipes is no longer socket based, but rather implemented through the file system.  Any application that needs socket functionality from pipes should use the socketpair system call.

Return Values

The function value zero is returned if the pipe was created; −1 if an error occurred. 

Diagnostics

The pipe call fails if:

[EMFILE] Too many descriptors are active. 

[ENFILE] The system file table is full. 

[EFAULT] The fildes buffer is in an invalid area of the process’s address space. 

Environment

Differs from the System V definition in that ENFILE is not a possible error condition. 

See Also

sh(1), fork(2), read(2), socketpair(2), write(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026