xref: /illumos-gate/usr/src/man/man2/pipe.2 (revision b1e2e3fb17324e9ddf43db264a0c64da7756d9e6)

Sun Microsystems, Inc. gratefully acknowledges The Open Group for
permission to reproduce portions of its copyrighted documentation.
Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.

The Institute of Electrical and Electronics Engineers and The Open
Group, have given us permission to reprint portions of their
documentation.

In the following statement, the phrase ``this text'' refers to portions
of the system documentation.

Portions of this text are reprinted and reproduced in electronic form
in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
Standard for Information Technology -- Portable Operating System
Interface (POSIX), The Open Group Base Specifications Issue 6,
Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
Engineers, Inc and The Open Group. In the event of any discrepancy
between these versions and the original IEEE and The Open Group
Standard, the original IEEE and The Open Group Standard is the referee
document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html.

This notice shall appear on any product containing this material.

The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.

You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions
and limitations under the License.

When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at usr/src/OPENSOLARIS.LICENSE.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]


Copyright 1989 AT&T
Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved.
Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc.
All Rights Reserved.

PIPE 2 "Apr 19, 2013"
NAME
pipe - create an interprocess channel
SYNOPSIS

#include <unistd.h>

int pipe(int fildes[2]);

int pipe2(int fildes[2], int flags);
DESCRIPTION

The pipe() and pipe2() functions create an I/O mechanism called a pipe and returns two file descriptors, fildes[0] and fildes[1]. The files associated with fildes[0] and fildes[1] are streams and are both opened for reading and writing. The pipe() call will clear the O_NDELAY, O_NONBLOCK, and FD_CLOEXEC flags on both file descriptors. The fcntl(2) function can be used to set these flags.

The pipe2() call will clear the O_NDELAY on both filedescriptors. The flags argument may be used to specify attributes on both file descriptors. pipe2() called with a flags value of 0 will behave identically to pipe(). Values for flags are constructed by a bitwise-inclusive-OR of flags from the following list, defined in <fcntl.h>. O_NONBLOCK

Both file descriptors will be placed in non-blocking mode. This corresponds to the O_NONBLOCK flag to fcntl(2).

O_CLOEXEC

Both file descriptors will be opened with the FD_CLOEXEC flag set. Both file descriptors will be closed prior to any future exec() calls.

A read from fildes[0] accesses the data written to fildes[1] on a first-in-first-out (FIFO) basis and a read from fildes[1] accesses the data written to fildes[0] also on a FIFO basis.

Upon successful completion pipe() marks for update the st_atime, st_ctime, and st_mtime fields of the pipe.

RETURN VALUES

Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.

ERRORS

The pipe() and pipe2() functions will fail if: EMFILE

More than {OPEN_MAX} file descriptors are already in use by this process.

ENFILE

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

EFAULT

The fildes[2] argument points to an illegal address.

The pipe2() function will also fail if: EINVAL

The flags argument is illegal. Valid flags are zero or a bitwise inclusive-OR of O_CLOEXEC and O_NONBLOCK.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Standard
MT-Level Async-Signal-Safe
SEE ALSO

sh(1), fcntl(2), fstat(2), getmsg(2), poll(2), putmsg(2), read(2), write(2), open(2), attributes(5), standards(5), streamio(7I)

NOTES

Since a pipe is bi-directional, there are two separate flows of data. Therefore, the size (st_size) returned by a call to fstat(2) with argument fildes[0] or fildes[1] is the number of bytes available for reading from fildes[0] or fildes[1] respectively. Previously, the size (st_size) returned by a call to fstat() with argument fildes[1] (the write-end) was the number of bytes available for reading from fildes[0] (the read-end).