|
|
HP-UX Reference Volume 3 of 5 > ppipe(2) |
|
NAMEpipe — create an interprocess channel DESCRIPTIONpipe() 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:
For more information, see STREAMS/UX for the HP 9000 Reference Manual. EXAMPLESThe 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) /* check process id of child process */ { 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 */ } RETURN VALUEUpon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORSpipe() fails if one or more of the following is true:
|
|