EmbLogic's Blog

PIPE : IPC mechanism

Pipe is a method of creating the standard output of one process to the standard input of another process.When a process creates a pipe using pipe() system call , the pipe() system call finds the first two available file-descriptors in the process file table and allocates them for reading and writing purposes.pipe() system call returns 0 on success and -1 on failure.

In half duplex pipes , fd[0] and fd[1] are set for reading and writing respectively.The pipe is automatically removed by the operating system when all the processes associated with the pipe terminates.

Certain points which should be kept in mind while implementing pipe:

1.If a process calls read() when the pipe is empty then the process is blocked untill some data is sent through the pipe.

2.If a process calls write() when the pipe is full then the calling process is blocked untill some data is read from the pipe.

3.The process must first call pipe() and then fork().Otherwise the two pipes will be entirely different from each other , i.e parent-child relationship must exist.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>