0% found this document useful (0 votes)
9 views

IPC Lect 5

Uploaded by

syed.12682
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

IPC Lect 5

Uploaded by

syed.12682
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

OPERATING

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:

 In a database, multiple processes may need to access the same data.


Synchronization is used to ensure that only one process can write to the data at a
time, and that other processes do not read the data while it is being written.
 In a web server, multiple processes may need to handle requests from clients.
Synchronization is used to ensure that only one process handles a request at a
time, and that other processes do not interfere with the request.
 In a distributed system, multiple processes may need to communicate with each
other. Synchronization is used to ensure that messages are sent and received in
the correct order, and that processes do not take actions based on outdated
information.

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

 Message queues are a more advanced form of pipes.


 They allow processes to send messages to each other, and they can be used to communicate between processes
that are not running on the same machine.
 Message queues are a good choice for communication between processes that need to be decoupled from each
other.
 In Message Queue IPC, each message has a priority associated with it, and messages are retrieved from the queue
in order of their priority. This allows processes to prioritize the delivery of important messages and ensures that
critical messages are not blocked by less important messages in the queue.
 Message Queue IPC provides a flexible and scalable method of communication between processes, as messages
can be sent and received asynchronously, allowing processes to continue executing while they wait for messages
to arrive.
 The main disadvantage of Message Queue IPC is that it can introduce additional overhead, as messages must be
copied between address spaces, and the queue must be managed by the operating system to ensure that it
remains synchronized and consistent across all processes.
 We have linked list to store messages in a kernel of OS and a message queue is identified using "message queue
identifier". Total 16 slides
Total 16 slides
DIRECT COMMUNICATION

 In this, process that wanna communicate must name sender or reciever .


 A pair of communicating processes must have one link between them.
 A link (generally bi-directional) establishes between every pair of communicating processes.
 In direct communication, the sender process must know the identifier of the receiver process in
order to send a message to it. This identifier can be a process ID, a port number, or some other
unique identifier. Once the sender process has the identifier of the receiver process, it can send a
message to it directly.
 The main advantage of direct communication is that it provides a simple and direct way for
processes to communicate, as processes can access each other’s data directly without the need
for intermediate communication mechanisms.
 However, direct communication also has some limitations, as it can lead to tight coupling
between processes, and it can make it more difficult to change the communication mechanism in
the future, as direct communication is hardcoded into the processes themselves.
Total 16 slides
Total 16 slides
INDIRECT COMMUNICATION

 Indirect communication in IPC is a method of communication in which processes do not explicitly


name the sender or receiver of the communication. Instead, processes communicate through a shared
medium such as a message queue or mailbox.
 Pairs of communicating processes have shared mailbox.
 Link (uni-directional or bi-directional) is established between pairs of processes.
 Sender process puts message in the port or mailbox of reciever process and reciever process takes out
(or deletes) the data from mailbox.
 The sender and receiver processes do not need to know each other's identifiers in order to communicate
with each other.
 The main advantage of indirect communication is that it provides a more flexible and scalable way for
processes to communicate, as processes do not need to have direct access to each other’s data.
 However, indirect communication can also introduce additional overhead, as data must be copied
between address spaces, and the communication mechanism must be managed by the operating system
to ensure that it remains synchronized and consistent across all processes.
Total 16 slides
FIFO

 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

You might also like