This blog aims at helping you learn C, Java and TASM programming languages and thus enabling you to use its immense possibilities in the computing world.It features Step by step instructions on doing a C program ,Complete Source Codes of C, Java and TASM Programs ,sample program downloads,programming tutorials and general tips for programmers.

Thursday, November 17, 2011

C Program to implement Inter Process Communication(IPC) by using Pipe

Inter Process communication is a technique by which a thread in one process shares some information with threads in other processes.A pipe is a buffer,specifically a FIFO(First in First Out) buffer that has 2 ends,a read end and a write end.A thread can write or read depending on the file reference it has.
read() is used to read data and write() is used to write data.

The following is an implementation of Pipe in C Language.There is a main process P1 and 2 child processes C1 and C2 , the main process reads a string and passes it to one of the child process ,the child process C1 receive string from P1,find its length and sends the value to P1.C1 also reads an integer array of length equal to the length of the string and sends it to C2.C2 receive integer array from C1,find the sum of the elements and sends the sum to the parent process P1.The sleep() function is used in the program to suspend the processes for a desired interval of time.
The complete C language source code of this example program that implements IPC(Interprocess Communication) using PIPE is given below.