#include <unistd.h>
|
int
pipe (int *fildes); |
By convention, the first descriptor is normally used as the read end of the pipe, and the second is normally the write end, so that data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one thread to be sent to another thread: the source’s standard output is set up to be the write end of the pipe, and the sink’s standard input is set up to be the read end of the pipe. The pipe itself persists until all its associated descriptors are closed.
A pipe that has had an end closed is considered widowed. Writing on such a pipe causes the writing process to fail and errno is set to EPIPE Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count.
#include <unistd.h> #include <stdio.h> int main(void) { int fds[2]; if (pipe(fds) == -1) { printf("Pipe creation failed\n"); } /* fds[0] - opened for read */ /* fds[1] - opened for write */ close(fds[0]); close(fds[1]); return 0; }
[EMFILE] | |
Too many descriptors are active. | |
[ENFILE] | |
The system file table is full. | |
© 2005-2007 Nokia |