IPC Lect 5
IPC Lect 5
SYSTEM (O.S)
Lect-6
INTER PROCESS COMMUNICATION
(IPC)
Inter process communication (IPC) is used for exchanging data between multiple threads in one
or more processes or programs. The Processes may be running on single or multiple computers
connected by a network.
It is a set of programming interfaces that enable a programmer to coordinate actions across
multiple processes that can run concurrently in an operating system. This enables a given
program to handle several user requests at the same time.
Each user request may cause multiple processes to operate in the operating system, the
processes may need to communicate with one another. This is essential for many tasks, such as:
Sharing data
Coordinating activities
Managing resources
Achieving modularity
Total 16 slides
SYNCHRONIZATION IN INTERPROCESS COMMUNICATION
Synchronization in Inter Process Communication (IPC) is the process of ensuring that multiple processes are
coordinated and do not interfere with each other. This is important because processes can share data and
resources, and if they are not synchronized, they can overwrite each other's data or cause other problems.
There are a number of different mechanisms that can be used to synchronize processes, including:
Total 16 slides
Here are some examples of how synchronization is used in IPC:
Total 16 slides
APPROACHES TO INTERPROCESS
COMMUNICATION
Here, are few important methods for interprocess communication:
Total 16 slides
PIPES
Pipes are a simple form of shared memory that allows two processes to communicate with each other.
It is a half duplex method (or one way communication) used for IPC between two related processes .
One process writes data to the pipe, and the other process reads data from the pipe.
It is like a scenario like filling water with a tap into a bucket. The filling process is writing into the pipe
and the reading process is retrieving from the pipe.
Pipes can be either named or anonymous, depending on whether they have a unique name or not.
Named pipes are a type of pipe that has a unique name, and can be accessed by multiple processes.
Named pipes can be used for communication between processes running on the same host or between
processes running on different hosts over a network.
Anonymous pipes, on the other hand, are pipes that are created for communication between a parent
process and its child process. Anonymous pipes are typically used for one-way communication
between processes, as they do not have a unique name and can only be accessed by the processes that
created them.
Total 16 slides
Total 16 slides
SHARED MEMORY
Shared memory is a region of memory that is accessible to multiple processes. This allows
processes to communicate with each other by reading and writing data from the shared
memory region.
Shared memory is a fast and efficient way for processes to communicate, but it can be
difficult to use if the processes are not carefully synchronized.
There are two main types of shared memory:
Anonymous shared memory: Anonymous shared memory is not associated with any file or
other system object. It is created by the operating system and is only accessible to the
processes that created it.
Mapped shared memory: Mapped shared memory is associated with a file or other system
object. It is created by mapping a file into the address space of one or more processes.
Multiple processes can access a common shared memory. Multiple processes communicate
by shared memory, where one process makes changes at a time and then others view the
change. Shared memory does not use kernel.
Total 16 slides
Total 16 slides
MESSAGE PASSING
Message passing is a method of Inter Process Communication in OS. It involves the exchange of messages
between processes, where each process sends and receives messages to coordinate its activities and exchange data
with other processes.
Processes can communicate without any shared variables, therefore it can be used in a distributed environment
on a network.
In message passing, each process has a unique identifier, known as a process ID, and messages are sent from one
process to another using this identifier. When a process sends a message, it specifies the recipient process ID and
the contents of the message, and the operating system is responsible for delivering the message to the recipient
process. The recipient process can then retrieve the contents of the message and respond, if necessary.
Message passing in shared memory has a number of advantages over other IPC mechanisms. First, it is very fast,
as messages are simply copied from one process's address space to another. Second, it is very flexible, as any type
of data can be shared between processes. Third, it is relatively easy to implement, as it does not require any
special support from the operating system.
However, message passing in shared memory also has some disadvantages. First, it can be difficult to ensure that
messages are delivered in the correct order. Second, it can be difficult to manage the size of the message queue.
Third, it can be difficult to port to other platforms, as the implementation of shared memory can vary from one
operating system to another.
Total 16 slides
MESSAGE QUEUES
FIFO (First In First Out) is a type of message queue that guarantees that messages are
delivered in the order they were sent.
It involves the use of a FIFO buffer, which acts as a queue for exchanging data between
processes.
Used to communicate between two processes that are not related.
In the FIFO method, one process writes data to the FIFO buffer, and another process reads the
data from the buffer in the order in which it was written.
Full-duplex method - Process P1 is able to communicate with Process P2, and vice versa.
The main advantage of the FIFO method is that it provides a simple way for processes to
communicate, as data is exchanged sequentially, and there is no need for processes to
coordinate their access to the FIFO buffer.
However, the FIFO method can also introduce limitations, as it may result in slow performance
if the buffer becomes full and data must be written to the disk, or if the buffer becomes empty
and data must be read from the disk.
Total 16 slides
WHY INTER PROCESS
COMMUNICATION (IPC) IS REQUIRED?
Inter-process communication (IPC) is required for a number of reasons:
Sharing data: IPC allows processes to share data with each other. This is essential for
many tasks, such as sharing files, databases, and other resources.
Coordinating activities: IPC allows processes to coordinate their activities. This is
essential for tasks such as distributed computing, where multiple processes are working
together to solve a problem.
Managing resources: IPC allows processes to manage resources such as memory, devices,
and files. This is essential for ensuring that resources are used efficiently.
Achieving modularity: IPC allows processes to be developed and maintained
independently of each other. This makes it easier to develop and maintain large and
complex software systems.
Flexibility: IPC allows processes to run on different hosts or nodes in a network,
providing greater flexibility and scalability in large and complex systems.
Total 16 slides