Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ pipe(2) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh(1)

read(2)

write(2)

popen(3S)

PIPE(2)

NAME

pipe − create an interprocess channel

SYNOPSIS

int pipe (fildes)
int fildes[2];

DESCRIPTION

Pipe creates an I/O mechanism called a pipe and returns two file descriptors, fildes[0] and fildes[1]. Fildes[0] is opened for reading and fildes[1] is opened for writing.

A read-only file descriptor fildes[0] accesses the data written to fildes[1] on a first-in-first-out (FIFO) basis.  For details of the I/O behavior of pipes see read(2) and write(2).

EXAMPLES

The following example uses pipe to implement the command string "ls | sort":

#include <sys/types.h>
pid_t pid;
int pipefd[2];

/*  Assumes file descriptor 0 and 1 are open  */
pipe (pipefd);
if ((pid = fork()) == (pid_t)0) {
close(1); /* close stdout */
dup (pipefd[1]);
execlp ("ls", "ls", (char *)0);
}
else if (pid > (pid_t)0) {
close(0);/* close stdin  */
dup (pipefd[0]);
execlp ("sort", "sort", (char *)0);
}

RETURN VALUE

Upon successful completion, a value of 0 is returned.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

ERRORS

Pipe fails if one or more of the following is true:

[EMFILE] NFILE - 1 or more file descriptors are currently open. 

[ENFILE] The system file table is full. 

[ENOSPC] The file system lacks sufficient space to create the pipe. 

SEE ALSO

sh(1), read(2), write(2), popen(3S). 

STANDARDS CONFORMANCE

pipe: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

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