Linux: Pipes(Half Duplex)

Pipe is an effective way of communication(Half Duplex) between process. Pipe has two descriptors. One descriptor is used for reading while other end is used for writing.

Usage of pipe is to have communication between child and parent process. We also use pipe to redirect of output of a process to another process. We often use pipe in our shell scripts.


With half-duplex pipes, any connected processes must share a related ancestry. Since the pipe resides within the confines of the kernel, any process that is not in the ancestry for the creator of the pipe has no way of addressing it. This is not the case with named pipes (FIFOS).

SYSTEM CALL: pipe(); 
PROTOTYPE: int pipe( int fd[2] ); 

RETURNS: 0 on success -1 on error: 
               errno = EMFILE (no free descriptors) 
                          EMFILE (system file table is full) 
                          EFAULT (fd array is not valid) 

NOTES: fd[0] is set up for reading, fd[1] is set up for writing

No comments:

Post a Comment