Ordinary pipes are uni-directional, with a reading end and a writing end. ( If bidirectional communications are needed, then a second pipe is required. )
In UNIX ordinary pipes are created with the system call "int pipe( int fd [ ] )".
The return value is 0 on success, -1 if an error occurs.
The int array must be allocated before the call, and the values are filled in by the pipe system call:
fd[ 0 ] is filled in with a file descriptor for the reading end of the pipe
fd[ 1 ] is filled in with a file descriptor for the writing end of the pipe
UNIX pipes are accessible as files, using standard read( ) and write( ) system calls.
Ordinary pipes are only accessible within the process that created them.
Typically a parent creates the pipe before forking off a child.
When the child inherits open files from its parent, including the pipe file(s), a channel of communication is established.
Each process ( parent and child ) should first close the ends of the pipe that they are not using. For example, if the parent is writing to the pipe and the child is reading, then the parent should close the reading end of its pipe after the fork and the child should close the writing end.
Figure 3.22 shows an ordinary pipe in UNIX