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

Inter Process Communication

Inter-Process Communication (IPC) encompasses various mechanisms for data exchange between processes, either on the same computer or across different systems. Key IPC methods include shared memory, pipes, message queues, and semaphores, each with specific use cases and advantages. IPC can be categorized into unicast and multicast communication, facilitating both local and distributed interactions among processes.
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)
28 views

Inter Process Communication

Inter-Process Communication (IPC) encompasses various mechanisms for data exchange between processes, either on the same computer or across different systems. Key IPC methods include shared memory, pipes, message queues, and semaphores, each with specific use cases and advantages. IPC can be categorized into unicast and multicast communication, facilitating both local and distributed interactions among processes.
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/ 26

UNIT-III: Inter Process

Communication
IPC between processes on a single computer system, IPC between
processes on different systems, using pipes, FIFOs, message queues,
shared memory.

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Interprocess Communication

Inter-process Communication is a set of mechanisms or techniques for


exchanging Data between two processes or applications.

Operating System Concepts – 10th Edition 3.2 Silberschatz, Galvin and Gagne ©2018
Interprocess Communication

Operating System Concepts – 10th Edition 3.3 Silberschatz, Galvin and Gagne ©2018
Interprocess Communication

Operating System Concepts – 10th Edition 3.4 Silberschatz, Galvin and Gagne ©2018
Inter-Process Communication Types
Inter-process communication can be:-
Unicast: When communication is from one process to a single other process.
e.g. Socket communication.
Multicast: When communication is from one process to a group of processes.
e.g. Publish/Subscribe Message model.

Inter-Process Communication (IPC) refers to the mechanisms that allow

processes to exchange data and synchronize their execution. IPC can occur:

• Within a single system (Local IPC)

• Between different systems (Distributed IPC)

For IPC between different systems, network-based communication mechanisms

are essential.

Operating System Concepts – 10th Edition 3.5 Silberschatz, Galvin and Gagne ©2018
IPC b/w Process in Single System

Operating System Concepts – 10th Edition 3.6 Silberschatz, Galvin and Gagne ©2018
IPC b/w Process in Single System

Inter-Process • Shared Memory: Directly


Communication accessing a shared memory
segment, considered very fast for
(IPC) between
large data transfers between
processes on a processes on the same machine.
single computer
• Pipes: A unidirectional data stream
system typically between processes, suitable for
uses simple data exchange.
mechanisms like • Message Queues: A queue of
1. pipes, messages that processes can send
2. shared and receive, providing a buffer for
memory, data exchange.
3. semaphores, • Semaphores: Used for
and
Operating System Concepts – 10th Edition
synchronization
3.7
between processes
Silberschatz, Galvin and Gagne ©2018
IPC b/w Process in Different Systems

IPC between processes on different


systems primarily relies on network sockets,
allowing communication across a network
between machines
•Sockets (TCP/UDP)
•Distributed Message Queues (e.g., Apache Kafka, MQTT)
•Remote Procedure Calls (RPC)
•Middleware solutions (e.g., CORBA, gRPC, WebSockets)

Operating System Concepts – 10th Edition 3.8 Silberschatz, Galvin and Gagne ©2018
Shared Memory
Message Passing
Message queue
Pipe
Named Pipe(FIFO)

Operating System Concepts – 10th Edition 3.9 Silberschatz, Galvin and Gagne ©2018
Shared memory

• Communication between processes using shared memory


requires processes to share some variable and it completely
depends on how programmer will implement it.
• One way of communication using shared memory can be
imagined like this:
• Suppose process A and process B are executing simultaneously
and they share some resources or use some information from
other process, process A generate information about certain
computations or resources being used and keeps it as a record
in shared memory.
• When process B need to use the shared information, it will
check in the record stored in shared memory and take note of
the information generated by process A and act accordingly.
• Processes can use shared memory for extracting information as
a record from other process as well as for delivering any
specific information to other process.

Operating System Concepts – 10th Edition 3.10 Silberschatz, Galvin and Gagne ©2018
Message passing

In this method, processes communicate with each other


without using any kind of of shared memory. If two
processes pA and pB 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)

Operating System Concepts – 10th Edition 3.11 Silberschatz, Galvin and Gagne ©2018
Message Passing
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.

Operating System Concepts – 10th Edition 3.12 Silberschatz, Galvin and Gagne ©2018
Message queue

Message Queue is a method of Inter Process Communication in OS. It involves the use of a
shared queue, where processes can add messages and retrieve messages for
communication.
The queue acts as a buffer for the messages and provides a way for processes to exchange
data and coordinate their activities.

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. Additionally, Message Queue IPC
supports the communication between processes running on different hosts, as the message
queue can be implemented as a network service.

Operating System Concepts – 10th Edition 3.13 Silberschatz, Galvin and Gagne ©2018
Message queue
Disadvantage of Message Queue IPC: 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. Despite these limitations, Message Queue IPC
remains a popular and widely used method of IPC in operating systems.

Features:
1. OS provides for inserting and deleting the message-pointers or messages.
2. Each queue for a message need initialization (creation) before using the functions in the
scheduler for the message queue
3. There may be a provision for multiple queues for the multiple types or destinations of messages. Each
queue may have an ID.
4. Each queue either has a user definable size (upper limit for number of bytes) ora fixed predefined size
assigned by the scheduler
5. When the queue becomes full, there may be a need for error handling and user codes for blocking the tasks

Operating System Concepts – 10th Edition 3.14 Silberschatz, Galvin and Gagne ©2018
Message queue
implementation

Operating System Concepts – 10th Edition 3.15 Silberschatz, Galvin and Gagne ©2018
Pipe
• Pipe is a device used for the inter process communication.
• A message-pipe is a device for inserting (writing) and deleting (reading) from that
between two given inter-connected tasks or two sets of tasks
• Conceptually, a pipe is a connection between two processes, such that the standard
output from one process becomes the standard input of the other process.
• Writing and reading from a pipe is like using a C command fwrite with a file name to
write into a named file, and C command fread with a file name to read into a named
file.
• Pipe is one-way communication only i.e we can use a pipe such that One process write
to the pipe, and the other process reads from the pipe. It opens a pipe, which is an area
of main memory that is treated as a“virtual file”.
• The pipe can be used by the creating process, as well as all its child processes, for
reading and writing. One process can write to this “virtual file” or pipe and another
related process can read from it.
• If a process tries to read before something is written to the pipe, the process is
suspended until something is written.
• The pipe system call finds the first two available positions in the process’s open file
table and allocates them for the read and write ends of the pipe.
Operating System Concepts – 10th Edition 3.16 Silberschatz, Galvin and Gagne ©2018
Pipes issues
 Acts as a conduit allowing two processes to communicate
 Issues:
• Is communication unidirectional or bidirectional?
• In the case of two-way communication, is it half or full-duplex?
• Must there exist a relationship (i.e., parent-child) between the communicating
processes?
• Can the pipes be used over a network?
• The communication between pipes are meant to be unidirectional.
• Pipes were restricted to one-way communication in general and need at least two pipes
for two-way communication.
• Pipes are meant for inter-related processes only.
• Pipes can’t be used for unrelated processes communication, say, if we want to execute
one process from one terminal and another process from another terminal, it is not
possible with pipes.

Operating System Concepts – 10th Edition 3.17 Silberschatz, Galvin and Gagne ©2018
Types of Pipes: Ordinary Pipes
Ordinary pipes – cannot be accessed from outside the process that
created it. Typically, a parent process creates a pipe and uses it to
communicate with a child process that it created.
Named pipes – can be accessed without a parent-child relationship.
 Ordinary Pipes allow communication in standard producer-consumer style
 Producer writes to one end (the write-end of the pipe)
 Consumer reads from the other end (the read-end of the pipe)
 Ordinary pipes are therefore unidirectional
 Require parent-child relationship between communicating processes

 Windows calls these anonymous pipes

Operating System Concepts – 10th Edition 3.18 Silberschatz, Galvin and Gagne ©2018
Named Pipes
 Named Pipes are more powerful than ordinary pipes
 Communication is bidirectional
 No parent-child relationship is necessary between the communicating
processes
 Several processes can use the named pipe for communication
 Provided on both UNIX and Windows systems

Operating System Concepts – 10th Edition 3.19 Silberschatz, Galvin and Gagne ©2018
Pipe implementation

#include<unistd.h>

int pipe(int pipedes[2]);

This system call would create a pipe for one-way


communication i.e., it creates two descriptors,
first one is connected to read from the pipe and
other one is connected to write into the pipe.

Descriptor pipedes[0] is for reading and pipedes[1]


is for writing. Whatever is written into pipedes[1]
can be read from pipedes[0].

This call would return zero on success and -1 in


case of failure. To know the cause of failure, check
with errno variable or perror() function.

Operating System Concepts – 10th Edition 3.20 Silberschatz, Galvin and Gagne ©2018
FIFO(named pipe)
FIFO (First-In-First-Out) is a method of Inter Process Communication in OS. It involves the
use of a FIFO buffer, which acts as a queue for exchanging data between processes.

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. The FIFO buffer acts as a
queue, with the oldest data being read first, and the newest data being added to the end
of the queue.

The main advantage of the FIFO method is that it provides a simple and straightforward
way for processes to communicate, as data is exchanged in a sequential manner, and
there is no need for processes to coordinate their access to the FIFO buffer. This makes
FIFO particularly useful for applications that need to exchange data in a sequential
manner, such as printing applications or pipeline-based processing systems.

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. Additionally, the FIFO method
is limited in terms of the amount of data that can be exchanged, as the buffer has a finite
size. Despite these limitations, the FIFO method remains a popular and widely used
method of IPC in operating systems.
Operating System Concepts – 10th Edition 3.21 Silberschatz, Galvin and Gagne ©2018
FIFO(named pipe)

It can use single named pipe that can be used for two-way communication
(communication between the server and the client, plus the client and the server at
the same time) as Named Pipe supports bi-directional communication.

Another name for named pipe is FIFO (First-In-First-Out). Let us see the system call
(mknod()) to create a named pipe, which is a kind of a special file.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int mknod(const char *pathname, mode_t mode, dev_t dev);

Operating System Concepts – 10th Edition 3.22 Silberschatz, Galvin and Gagne ©2018
Direct Communication

• Direct communication involves the direct exchange of data between


processes, without the use of intermediate communication
mechanisms such as message passing, message queues, or shared
memory.

• In direct communication, processes communicate with each other by


exchanging data directly, either by passing data as parameters to
function calls or by reading and writing to shared data structures in
memory.

• Direct communication is typically used when processes need to


exchange small amounts of data, or when they need to coordinate
their activities in a simple and straightforward manner.

Operating System Concepts – 10th Edition 3.23 Silberschatz, Galvin and Gagne ©2018
Direct Communication

Advantage of direct communication:


1. 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.
2. This can result in lower overhead and improved performance,
as data does not need to be copied between address spaces.

Limitations of direct communication:


3. 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.
4. Direct communication remains a popular and widely used
method of IPC in operating systems.

Operating System Concepts – 10th Edition 3.24 Silberschatz, Galvin and Gagne ©2018
Indirect Communication

• Indirect communication involves the use of intermediate communication


mechanisms, such as message passing, message queues, or shared
memory, to exchange data between processes.

• In indirect communication, processes communicate with each other by


adding messages to a shared communication mechanism, such as a
message queue or a shared memory region. The communication
mechanism acts as an intermediary, allowing processes to exchange data
and coordinate their activities in a more decoupled and flexible manner.

Operating System Concepts – 10th Edition 3.25 Silberschatz, Galvin and Gagne ©2018
Indirect Communication

• 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. This can result in a more
modular and maintainable system, as processes can be developed and
maintained independently, and the communication mechanism can be
changed or updated without affecting the processes themselves.

• Disadvantage: 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. Despite these limitations, indirect communication remains a
popular and widely used method of IPC in operating systems.

Operating System Concepts – 10th Edition 3.26 Silberschatz, Galvin and Gagne ©2018

You might also like