Inter Process Communication

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Inter Process Communication (IPC)

Inter process communication in OS is way by which multiple processes can communicate with
each other. Shared memory in OS, message queues, FIFO etc are some of the ways to achieve
ipc in os.

What is Inter Process Communication in OS?

A system can have two types of processes i.e. independent or cooperating. Cooperating processes
affect each other and may share data and information among themselves.

Interprocess Communication or IPC provides a mechanism to exachange data and information


across multiple processes, which might be on single or multiple computers connected by a
network. This is essential for many tasks, such as:

 Sharing data
 Coordinating activities
 Managing resources
 Achieving modularity

Approaches for Inter-Process Communication


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.

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:
o 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.
o 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.

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.

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".

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.

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.

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.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy