Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > P


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


pipe() — create an interprocess channel


int pipe(int fildes[2]);


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).

By default, HP-UX pipes are not STREAMS-based. It is possible to generate the kernel so that all pipes created on a system are STREAMS-based. This can only be done for HP-UX releases 10.0 and later. STREAMS-based FIFOs (created by mknod or mkfifo) are not supported on HP-UX.

To generate a kernel that supports STREAMS-based pipes:

  • STREAMS/UX must be installed.

  • The module pipemod and the driver pipedev must be included in the /stand/system file. (When STREAMS/UX is installed, pipemod and pipedev are automatically added to the system file.)

  • The tunable parameter streampipes (see streampipes(5)) must be set to 1 in the /stand/system file. (This is not automatically done when STREAMS/UX is installed.)

  • The kernel must be generated and the system rebooted. Once this is done, all pipes created by pipe() will be STREAMS-based.

For more information, see STREAMS/UX for the HP 9000 Reference Manual.


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); /* check process id of child process */ if ((pid = fork()) == (pid_t)0) { close(1); /* close stdout */ dup (pipefd[1]); /* points pipefd at file descriptor */ close (pipefd[0]); execlp ("ls", "ls", (char *)0); /* child process does ls */ } else if (pid > (pid_t)0) { close(0); /* close stdin */ dup (pipefd[0]); /* point the child's standard output to parent's standard input */ close (pipefd[1]); execlp ("sort", "sort", (char *)0); /* parent process does sort */ }


pipe() returns one of the following values:


Successful completion.


Failure. errno is set to indicate the error.


pipe() sets errno to one of the following error values if the corresponding condition is true.


NFILE-1 or more file descriptors are currently open.


The system file table is full.


The file system lacks sufficient space to create the pipe.


Could not allocate resources for both Stream heads (STREAMS-based pipes only).


pipe(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.