| www.delorie.com/gnu/docs/glibc/libc_297.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The primitive for creating a pipe is the pipe function. This
creates both the reading and writing ends of the pipe. It is not very
useful for a single process to use a pipe to talk to itself. In typical
use, a process creates a pipe just before it forks one or more child
processes (see section 26.4 Creating a Process). The pipe is then used for
communication either between the parent or child processes, or between
two sibling processes.
The pipe function is declared in the header file
`unistd.h'.
pipe function creates a pipe and puts the file descriptors
for the reading and writing ends of the pipe (respectively) into
filedes[0] and filedes[1].
An easy way to remember that the input end comes first is that file
descriptor 0 is standard input, and file descriptor 1 is
standard output.
If successful, pipe returns a value of 0. On failure,
-1 is returned. The following errno error conditions are
defined for this function:
EMFILE
ENFILE
ENFILE. This error never occurs in
the GNU system.
Here is an example of a simple program that creates a pipe. This program
uses the fork function (see section 26.4 Creating a Process) to create
a child process. The parent process writes data to the pipe, which is
read by the child process.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
/* Read characters from the pipe and echo them to |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |