Inter Process Communication (IPC)
Inter Process Communication (IPC)
Inter Process Communication (IPC)
(IPC)
Inter Process Communication (IPC)
• Shared Memory:-
It can be referred to as a type of memory that can be used or
accessed by multiple processes simultaneously. It is primarily used so
that the processes can communicate with each other. Therefore the
shared memory is used by almost all POSIX and Windows operating
systems as well.
Approaches to Interprocess Communication
• Message Queue:-
In general, several different messages are allowed to read and write the
data to the message queue. In the message queue, the messages are
stored or stay in the queue unless their recipients retrieve them. In short,
we can also say that the message queue is very helpful in inter-process
communication and used by all operating systems.
• Message Passing:-
It is a type of mechanism that allows processes to synchronize and
communicate with each other. However, by using the message passing,
the processes can communicate with each other without restoring the
hared variables.
Operations that inter-process communication mechanism:
• send (message)
• received (message)
Approaches to Interprocess Communication
• Direct Communication:-
In this type of communication process, usually, a link is created or
established between two communicating processes. However, in every
pair of communicating processes, only one link can exist.
• Indirect Communication:-
Indirect communication can only exist or be established when processes
share a common mailbox, and each pair of these processes shares
multiple communication links. These shared links can be unidirectional
or bi-directional.
FIFO:-
• It is a type of general communication between two unrelated
processes. It can also be considered as full-duplex, which means that
one process can communicate with another process and vice versa.
Some other different approaches
• Socket:-
It acts as a type of endpoint for receiving or sending the data in a
network. It is correct for data sent between processes on the same
computer or data sent between different computers on the same
network. Hence, it used by several types of operating systems.
• File:-
A file is a type of data record or a document stored on the disk and can
be acquired on demand by the file server. Another most important thing
is that several processes can access that file as required or needed.
Some other different approaches
• Signal:-
As its name implies, they are a type of signal used in inter process
communication in a minimal way. Typically, they are the massages of
systems that are sent by one process to another. Therefore, they are not
used for sending data but for remote commands between multiple
processes.
What is a race condition?
A race condition is a situation that may occur inside a critical section.
This happens when the result of multiple thread execution in critical
section differs according to the order in which the threads execute.
The problem with the lock variable mechanism is that, at the same
time, more than one process can see the vacant tag and more than
one process can enter in the critical section. Hence, the lock variable
doesn't provide the mutual exclusion that's why it cannot be used in
general.
Critical Section Solutions :
3. Test Set Lock Mechanism :
Sometimes Process reads the old value of lock variable and enters
the critical section. Due to this reason, more than one process might
get into critical section. This doesn't affect the algorithm but, by
doing this, we can manage to provide the mutual exclusion to some
extent but not completely.
Critical Section Solutions :
3. Test Set Lock Mechanism :
In the updated version of code, the value of Lock is loaded into the
local register R0 and then value of lock is set to 1.
However, in step 3, the previous value of lock (that is now stored
into R0) is compared with 0. if this is 0 then the process will simply
enter into the critical section otherwise will wait by executing
continuously in the loop.
The benefit of setting the lock immediately to 1 by the process itself
is that, now the process which enters into the critical section carries
the updated value of lock variable that is 1.
Section 1 Section 2
1. Load Lock, R0
2. Store #1, Lock
3. CMP R0, #0
4. JNZ step 1
What if the process gets preempted just after executing the first
instruction of the assembly code written in section 2? In that case, it
will carry the old value of lock variable with it and it will enter into
the critical section regardless of knowing the current value of lock
variable. This may make the two processes present in the critical
section at the same time.
Critical Section Solutions :
3. Test Set Lock Mechanism :
To get rid of this problem, we have to make sure that the
preemption must not take place just after loading the previous value
of lock variable and before setting it to 1. The problem can be solved
if we can be able to merge the first two instructions.
In order to address the problem, the operating system provides a
special instruction called Test Set Lock (TSL) instruction which simply
loads the value of lock variable into the local register R0 and sets it
to 1 simultaneously.
The process which executes the TSL first will enter into the critical
section and no other process after that can enter until the first
process comes out.
Section 2
No process can execute the critical
TSL Lock, R0
section even in the case of preemption CMP R0, #0
JNZ step 1
of the first process.
Critical Section Solutions :
3. Test Set Lock Mechanism :
• Mutual Exclusion is guaranteed in TSL mechanism since a process
can never be preempted just before setting the lock variable.
• According to the definition of the progress, a process which
doesn't want to enter in the critical section should not stop other
processes to get into it.
• Bounded Waiting is not guaranteed in TSL. Some process might
not get a chance for so long. We cannot predict for a process that
it will definitely get a chance to enter in critical section after a
certain time.
Critical Section Solutions :
4. Strict Alternation Approach :
Strict Alternation Approach is the software mechanism implemented
at user mode. It is a busy waiting solution which can be
implemented only for two processes. In this approach, A turn
variable is used which is actually a lock.
This approach can only be used for only two processes. In general,
let the two processes be Pi and Pj. They share a variable called turn
variable.
• Binary Semaphores
The binary semaphores are quite similar to counting semaphores,
but their value is restricted to 0 and 1. In this type of semaphore,
the wait operation works only if semaphore = 1, and the signal
operation succeeds when semaphore= 0. It is easy to implement
than counting semaphores.
Semaphore
Some point regarding P and V operation:
• P operation is also called wait, sleep, or down operation, and V
operation is also called signal, wake-up, or up operation.
• Both operations are atomic and semaphore(s) is always initialized
to one. Here atomic means that variable on which read, modify
and update happens at the same time/moment with no pre-
emption i.e. in-between read, modify and update no other
operation is performed that may change the variable.
• A critical section is surrounded by both operations to implement
process synchronization.
Wait and Signal Operations in Semaphores
Wait for Operation
This type of semaphore operation helps you to control the entry of a
task into the critical section. However, If the value of wait is positive,
then the value of the wait argument X is decremented. In the case of
negative or zero value, no operation is executed. It is also called P(S)
operation.