Project Name: Inter Process Communication
Scope: To setup the communication link between two or more processes so as to transfer data to and fro in between the processes.
Description: We have many IPC techniques in Linux like PIPE, FIFO, Shared Memory, Message Queue. We will start this article from our first topic i.e. PIPE.
PIPE is a stream or we can say a path from where we transfer the data from one process to another. For creating a pipe we us system call “PIPE()”. This call will create a stream between two processes and will return two file descriptors. The two file descriptors returned are connected in a special way. Any data written to file_descriptor[1] can be read back from file_descriptor[0]. The data is processed in a first in, first out basis, usually abbreviated to FIFO. This means that if you write the bytes 1, 2, 3 to file_descriptor[1], reading from file_descriptor[0] will produce 1, 2, 3. This is different from a stack, which operates on a last in, first out basis, usually abbreviated to LIFO. As this stream is unnamed, hence it is visible to only those processes in which one process act as parent and another process act as a child. Now the question arises – What is a child process & Parent process.
We have a system call as “fork()”, this call will create process from main process. The created process is called as child and the main process will be named as parent. After creation of child process, we will send the file descriptors to that child process by calling a call “exec()”. This “exec()” call will create a new process and will replace it with the process from which this was called. Child process generated by the fork() call uses same process context but PCB is different. This replace process created by exec() call will have everything different i.e PCB & process context are different. Now this new process and the parent process both are having the file descriptors and with the help of these descriptors these two processes will share data with each other. Important topics here we have are “Orphan Process” & “Zombies”.
Orphan Process - After a call to fork(), generally its the child process that get time slice to execute. Now say of parent process terminates for some reason before child process, we will have a orphan process as it parent process have died. As every child process have some parent this must be made child of some process, in this condition Dispatcher i.e. Process with PID 1 is automatically made its parent.
Zombies – If for some reason a process is dead but haven’t been removed from the process table it is called as Zombie process. Now this can happen in situation when a child process has terminated and parent process gas gone in some kind of infinite loop which don’t allow child process to exit.
In the next article we will briefly discuss about other IPC techniques – FIFO, Shared memory and Message queue.