[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

pipe Subroutine

Purpose

Creates an interprocess channel.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>


int pipe ( FileDescriptor)
int FileDescriptor[2];

Description

The pipe subroutine creates an interprocess channel called a pipe and returns two file descriptors, FileDescriptor[0] and FileDescriptor[1]. FileDescriptor[0] is opened for reading and FileDescriptor[1] is opened for writing.

A read operation on the FileDescriptor[0] parameter accesses the data written to the FileDescriptor[1] parameter on a first-in, first-out (FIFO) basis.

Write requests of PIPE_BUF bytes or fewer will not be interleaved (mixed) with data from other processes doing writes on the same pipe. PIPE_BUF is a system variable described in the pathconf (pathconf or fpathconf Subroutine) subroutine. Writes of greater than PIPE_BUF bytes may have data interleaved, on arbitrary boundaries, with other writes.

If O_NONBLOCK or O_NDELAY are set, writes requests of PIPE_BUF bytes or fewer will either succeed completely or fail and return -1 with the errno global variable set to EAGAIN. A write request for more than PIPE_BUF bytes will either transfer what it can and return the number of bytes actually written, or transfer no data and return -1 with the errno global variable set to EAGAIN.

Parameters

FileDescriptor Specifies the address of an array of two integers into which the new file descriptors are placed.

Return Values

Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned, and the errno global variable is set to identify the error.

Error Codes

The pipe subroutine is unsuccessful if one or more the following are true:

EFAULT The FileDescriptor parameter points to a location outside of the allocated address space of the process.
EMFILE The number of open of file descriptors exceeds the OPEN_MAX value.
ENFILE The system file table is full, or the device containing pipes has no free i-nodes.

Related Information

The read subroutine, select subroutine, write subroutine.

The ksh command, sh command.

Files, Directories, and File Systems for Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]