Inter Process Communication(IPC) Short Note
A process can be of two type:
- Independent process.
- Co-operating process.
An independent process is not affected by the execution of other processes while a co-operating process can be affected by other executing processes.
Inter process communication (IPC) is a mechanism which allows processes to communicate each other and synchronize their actions.
Processes can communicate with each other using these two ways:
1) Shared Memory
2) Message Passing
- An operating system can implement both method of communication.
- Communication between processes using shared memory requires processes to share some variable and it completely depends on how programmer will implement it.
i) Shared Memory Method
Ex: Producer-Consumer problem
- There are two processes: Producer and Consumer.
- There are two processes: Producer and Consumer.
- Producer produces some item and Consumer consumes that item.
- The two processes shares a common space or memory location known as buffer where the item produced by Producer is stored and from where the Consumer consumes the item if needed.
- There are two version of this problem: first one is known as unbounded buffer problem in which Producer can keep on producing items and there is no limit on size of buffer, the second one is known as bounded buffer problem in which producer can produce up to a certain amount of item and after that it starts waiting for consumer to consume it. We will discuss the bounded buffer problem.
- First, the Producer and the Consumer will share some common memory, then producer will start producing items. If the total produced item is equal to the size of buffer, producer will wait to get it consumed by the Consumer. Similarly, the consumer first check for the availability of the item and if no item is available, Consumer will wait for producer to produce it. If there are items available, consumer will consume it.
ii) Messaging Passing Method
In this method, processes communicate with each other without using any kind of shared memory. If two processes p1 and p2 want to communicate with each other, they proceed as follow:
- Establish a communication link (if a link already exists, no need to establish it again.)
- Start exchanging messages using basic primitives.
We need at least two primitives:
– send(message, destinaion) or send(message)
– receive(message, host) or receive(message)
The message size can be of fixed size or of variable size. if it is of fixed size, it is easy for OS designer but complicated for programmer and if it is of variable size then it is easy for programmer but complicated for the OS designer. A standard message can have two parts: header and body.
The header part is used for storing Message type, destination id, source id, message length and control information. The control information contains information like what to do if runs out of buffer space, sequence number, priority. Generally, message is sent using FIFO style.
The header part is used for storing Message type, destination id, source id, message length and control information. The control information contains information like what to do if runs out of buffer space, sequence number, priority. Generally, message is sent using FIFO style.
for more info :- visit