Inter Process Communication in Distributed System
Inter Process Communication:
The process needs frequently to communicate with other processes.
Example: Consider a shell pipeline in UNIX or DOS.
$ process1 | process2
Here the first process must be passed the output to process2. Process1 output is to be input to process2. So, there is a need for communication between processes. This type of communication is said to be ‘Inter Process Communication‘.
Types of Methods for Inter-Process Communication:
Shared Memory is the fastest method for inter-process communication. It provides a common block in the main memory. Each process can read the messages from the common block and each process can write the messages in the common block.
Message Passing system provides a mechanism to allow the process to communicate and synchronize. These actions without sharing the same address space. It is particularly useful in a distributed environment where the communicating processes may reside on different computers collected by the network. This facility or system provides at least two operations – send (message), and receive (message).
A Pipe is a mechanism that allows a stream of data to be passed between reader and writer processes. It is a first-in-first-out queue and it is written by one process and read by another process. When a pipe is created, it is given fixed-size bytes. When a process wants to write something into the pipe, the request will be accepted if that has room for data writing, otherwise, the process is blocked.
A signal is a software mechanism that informs processes of the occurrence of asynchronous events. When a signal is sent the operating system interrupts the target process flow of execution to deliver the signal. Execution can be interrupted during any non-atomic instruction. If the process has previously registered a signal handler that routine is executed and otherwise the default signal handler is executed.
Example: Some predefined signals in Unix:
1. #define SIGHUP // Hangup (POSIX) 2. #define SIGINT // Interrupt (ANSI) 3. #define SIGKILL // Kill, unblocked (POSIX) 4. #define SIGALRM // Alarm Clock (POSIX) 5. #define SIGQUIT // Quit (POSIX)
A semaphore is an integer value used for signalling among processes. Only three operations may be performed on a semaphore, all of which are atomic, initialize, decrement and increment. The decrement operation may result in the blocking of a process and the increment operation may result in the unblocking of a process. A semaphore in UNIX allows the process to synchronize execution by doing a set of operations atomically on a set of semaphores.