IPC communication using PIPE - wiki4techi

IPC communication using PIPE

PIPE

IPC communication using PIPE:

[AdSense-A]

  1. Pipe is a one way communication channel.
  2. Data input at one end becomes data output at other end.
  3. We can have data / characters passing from one process to the other end which can be received by another process.

IPC communication using PIPE:

Process A       PIPE                                  Process B

*******                                                          *********

*******    =========================> *********

*******                                                          *********

 

The simplest form of pipe in Unix /linux is >ls -l | more

 

Here we have two calls to the write(), one in the parent process and the one in child process.Both the write happen at the write end of the pipe.

The child process reads the content at the read end and prints it

[AdSense-A]

IPC communication using PIPE

 

The pipe is meant for one way communication, to ensure that only a one way process takes place, we need to do something additional.

 

In the parent process before writing, we first close the read end of the pipe, so that even if the time slice is given to the child, its not able to read message halfway.

 

When the write is over, we open the read end.

[AdSense-A]

IPC communication using PIPE

When child process takes over, it closes the write end of pipe, this ensures that parent process can’t write to pipe.

 

So far we have created only unidirectional pipes providing one way of data. Let’s create two pipes, one for each direction.

[AdSense-A]

steps:

  1. create two pipes.
  2. fork, parent closes read-end of pipe 1 and writes at write-end of pipe2.
  3. child closes write end of pipe1 and read end of pipe2.

 

Parent   —> PIPE 1 PP —> Child

<—-   PIPE 2 PC —–

IPC communication using PIPE

IPC using pipe

[AdSense-A]

You may also like...

Leave a Reply

Optimization WordPress Plugins & Solutions by W3 EDGE