0% found this document useful (0 votes)
6 views9 pages

TASK COMMUNICATION

Uploaded by

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

TASK COMMUNICATION

Uploaded by

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

Unit V

TASK COMMUNICATION:

In a multitasking system, multiple tasks/processes run concurrently (in pseudo parallelism) and each
process may or may not interact between. Based on the degree of interaction, the processes running on
an OS are classified as

Co-operating Processes: In the co-operating interaction model one process requires the inputs from
other processes to complete its execution.

Competing Processes: The competing processes do not share anything among themselves but they
share the system resources. The competing processes compete for the system resources such as file,
display device, etc. Co-operating processes exchanges information and communicate through the
following methods.

Co-operation through Sharing: The co-operating process exchange data through some shared
resources.

Co-operation through Communication: No data is shared between the processes. But they
communicate for synchronisation. The mechanism through which processes/tasks communicate each
other is known as Inter Process/Task Communication (IPC). Inter Process Communication is essential
for process co-ordination.

Figure 1: Inter Process Communication

The various types of Inter Process Communication (IPC) mechanisms adopted by process are
kernel (Operating System) dependent. Some of the important IPC mechanisms adopted by
various kernels are explained below.

1. Shared Memory:

 Shared Memory is a method of inter-process communication (IPC) where multiple processes


can access the same region of memory.
 It allows processes to share data directly without the need for message passing or other forms
of communication.
 Shared memory provides fast and efficient communication between processes.
 However, it requires synchronization mechanisms (such as semaphores or mutexes) to ensure
data consistency and avoid race conditions.
 Shared memory is commonly used in scenarios where high-performance data sharing is
required, such as in parallel computing or multimedia applications.
 To understand this, consider the 2 processes as process 1 and process 2. If one process creates
memory, then the other process will access it by means of sharing. The communication
between the processes in IPC using the shared memory method is shown in the figure below.

A. Pipes:

 Pipes are a type of shared memory used for inter-process communication (IPC).
 They follow the client-server architecture, where the process creating the pipe is the pipe
server, and the process connecting to the pipe is the pipe client.
 Pipes act as conduits for information flow and have two conceptual ends.
 The unidirectional pipe can be visualised as

There are two types of pipes for Inter Process Communication in Microsoft Windows
Desktop Operating Systems:

a. Anonymous Pipes: Anonymous pipes are unnamed and unidirectional pipes used for data
transfer between two processes. They are limited to one-way communication.
b. Named Pipes: Named pipes are named, unidirectional, or bidirectional pipes used for data
exchange between processes. Named pipes allow point-to-point communication and can be
used between processes on the same machine or different machines connected to a network.

B. Memory-Mapped Objects:

 Memory-mapped objects are another type of shared memory mechanism.


 In this approach, a region of shared memory is mapped into the address space of multiple
processes, allowing them to access and modify the shared data as if it were regular
memory.
 Memory mapping involves associating a file or device with a range of virtual memory
addresses.
 Changes made by one process to the shared memory are visible to other processes
mapping the same region.
 Memory-mapped objects offer a more flexible and general-purpose shared memory
mechanism compared to pipes.
 They can be used for various purposes, including inter-process communication, shared
data structures, and efficient file I/O operations.

Advantages of Pipes:

i. Simple and straightforward to use.


ii. Suitable for sequential data transfer between processes.
iii. Efficient for one-way communication and basic synchronization.

Disadvantages of Pipes:

i. Limited to communication between related processes (parent-child or related


processes).
ii. Unidirectional pipes may not be ideal for bidirectional communication scenarios.
iii. Lack of flexibility and extensibility in terms of data structures and functionality.

Advantages of Memory-Mapped Objects:

i. Provide a flexible shared memory mechanism for inter-process communication.


ii. Can be used for both communication and shared data storage.
iii. Support random access and efficient data sharing between processes.
iv. Allow multiple processes to access shared data simultaneously.

Disadvantages of Memory-Mapped Objects:

i. Requires careful synchronization and locking mechanisms to ensure data consistency


and avoid race conditions.
ii. May have additional complexity compared to pipes in terms of managing memory
mappings and synchronization.
iii. Limited to processes running on the same machine or connected through shared file
systems or shared memory architectures.

2. Message Passing:

 Message Passing is a form of inter-process communication where processes exchange data by


sending and receiving messages.
 Each process has its own memory space, and communication occurs through message passing
primitives provided by the operating system or programming language.
 Message passing can be implemented using both synchronous and asynchronous mechanisms.
 Synchronous message passing involves blocking the sending process until the message is
received, while asynchronous message passing allows the sender to continue execution
without waiting for a response.
 Message passing provides a higher level of abstraction compared to shared memory, making
it easier to reason about and control the flow of communication.
 It is commonly used in distributed systems and parallel computing environments.
From the above figure, process 1 sends (writes) the message (M) to the kernel. While process 2
receives (reads) the message from the kernel sent by process 1.

Suppose, process 1 and process 2 communicated together by establishing the communication link as
shown in the figure above. After that, they exchange the message through send and receive
operations. The message is transferred in the First In First Out (FIFO) style. The standard message
exchanged by the processes contains 2 parts. Such as

Header: It contains the type of message, source and destination identities, length of the message, and
control information like priority, sequence number, and low disk space actions.

Body: It contains the original message that is to be exchanged.

Types of message passing:

Message Queue:
 A message queue is a form of inter-process communication (IPC) that allows processes to
exchange messages through a shared queue.
 Processes can send messages to the queue, and other processes can retrieve and process those
messages.
 Message queues typically provide features such as FIFO (First-In-First-Out) ordering,
priority-based message handling, and buffering.
 They are commonly used in multi-threaded or multi-process systems where communication
needs to be asynchronous and decoupled.

Advantages of Message Queues:

 Asynchronous communication allows processes to operate independently without waiting for


direct response.
 Supports reliable and ordered message delivery.
 Provides flexibility in message handling, such as prioritization and buffering.
 Allows communication between unrelated processes or processes running on different
machines.

Disadvantages of Message Queues:

 Requires synchronization mechanisms to ensure thread/process safety and avoid race


conditions.
 Overhead involved in managing and maintaining the message queue.
 Limited to message-based communication, which may introduce serialization and
deserialization overhead for complex data structures.

Mailbox:
 A mailbox is another form of message passing IPC where processes can exchange messages
through a designated mailbox.
 Each process has its own mailbox, which acts as a storage location for incoming and outgoing
messages.
 Processes can send messages to other processes' mailboxes, and the recipient process can
retrieve and process those messages from its mailbox.
 Mailboxes are typically implemented as a data structure in memory or as part of an operating
system's IPC facilities.

Advantages of Mailboxes:

 Simple and intuitive communication mechanism.


 Provides a direct and efficient way for processes to exchange messages.
 Supports both synchronous and asynchronous communication modes.
 Can be used for communication between related or unrelated processes.
Disadvantages of Mailboxes:

 Requires synchronization mechanisms to ensure thread/process safety and avoid race


conditions.
 Limited to processes running on the same machine or connected through a shared memory
architecture.
 Lack of built-in prioritization or buffering features compared to message queues.

Signaling:
 Signaling is a method of communication where one process notifies another process about an
event or condition.
 It involves the use of signals or flags to indicate a specific state or event to other processes.
 Signaling can be implemented through various mechanisms such as signals, interrupts, shared
variables, or semaphores.
Advantages of Signaling:

 Lightweight and efficient communication mechanism.


 Can be used for simple and immediate notifications or event-driven programming.
 Enables inter-process coordination and synchronization.
Disadvantages of Signaling:

 Lack of explicit data transfer between processes.


 May require additional synchronization mechanisms to ensure correct signaling handling.
 Limited to basic event-driven communication and may not be suitable for complex data
exchange.

3. Remote Procedure Call (RPC):

 Remote Procedure Call is a communication protocol that allows a program to execute


procedures or functions on a remote computer or server.
 RPC hides the details of network communication and makes remote procedure invocations
appear as if they were local function calls.
 It provides a transparent and convenient way to access resources or services on remote
machines.
 RPC typically involves client and server components, where the client initiates a request and
the server processes the request and returns the result.
 It abstracts away the complexities of low-level communication protocols and provides a
higher-level interface for distributed computing.

4. Sockets:

 Sockets are a programming interface that enables communication between processes over a
network.
 They provide a reliable, bidirectional, and stream-oriented communication channel between
two endpoints (client and server).
 Sockets can be used for various network protocols, such as TCP (Transmission Control
Protocol) or UDP (User Datagram Protocol).
 TCP sockets provide reliable, ordered, and error-checked communication, while UDP sockets
offer a connectionless and lightweight communication mechanism.
 Sockets are widely used in client-server architectures, web applications, and network
programming.
 They allow processes running on different machines to communicate and exchange data.

In summary, task communication can be achieved through various methods such as shared memory,
message passing, remote procedure call (RPC), and sockets. Each method has its own advantages and
use cases, and the choice of communication mechanism depends on factors such as performance
requirements, data sharing needs, and network architecture.

Miscellaneous:
1. Shared Memory:

Advantages:

i. Fast and efficient communication as processes can directly access shared data.
ii. Low overhead as there is no need for message passing or copying data.
iii. Suitable for scenarios requiring high-performance data sharing, such as parallel computing.

Disadvantages:

i. Requires synchronization mechanisms (e.g., semaphores, mutexes) to ensure data


consistency, which can introduce complexity and potential race conditions.
ii. Limited to communication between processes running on the same machine.
iii. Can be challenging to manage and debug due to shared memory access by multiple processes.

2. Message Passing:

Advantages:

i. Provides a higher level of abstraction, making it easier to reason about and control the flow of
communication.
ii. Supports both synchronous and asynchronous communication mechanisms.
iii. Suitable for distributed systems and parallel computing environments.
iv. Can be used for communication between processes running on the same machine or different
machines connected over a network.

Disadvantages:
i. Requires message passing primitives and overhead for sending and receiving messages.
ii. Message passing may incur additional latency compared to shared memory.
iii. Complex message structures and serialization/deserialization may be needed for passing non-
trivial data.

3. Remote Procedure Call (RPC):

Advantages:

i. Provides a transparent and convenient way to execute procedures or functions on remote


machines.
ii. Hides the complexities of low-level network communication protocols.
iii. Enables remote access to resources or services without exposing implementation details.
iv. Can be used for distributed computing and accessing remote services.

Disadvantages:

i. Requires network connectivity and may be affected by network latency and reliability.
ii. Introduces additional overhead due to serialization, network communication, and
marshaling/unmarshaling of data.
iii. May have limitations on data types and parameter passing compared to local function calls.

4. Sockets:

Advantages:

i. Offers a reliable, bidirectional, and stream-oriented communication channel between


processes over a network.
ii. Supports various network protocols (e.g., TCP, UDP) for different communication
requirements.
iii. Widely supported and available in most programming languages and operating systems.
iv. Enables communication between processes running on different machines.

Disadvantages:

i. Requires network connectivity and may be affected by network latency and reliability.
ii. Introduces overhead for establishing and maintaining network connections.
iii. Requires explicit handling of data packaging, sending, and receiving at the application level.

Q1. Difference Between Synchronous and Asynchronous Inter-Process Communication

S.
Synchronous Inter-Process Asynchronous Inter-Process
N
Communication communication
o
It is also known as blocking inter- It is also known as non-blocking inter-process
1 process communication in both communication in both send and receive
send and receive modes. modes.
Blocking send mode: The sending Non-block send mode: The message will be
process is blocked until the sent by the sending process and resumes the
2
message is received by the operation. It doesn’t matter whether the
receiving process. receiver exists or not.
Blocking receive mode: In this, the Non-blocking receive mode: The receiver
receiver can block the available doesn’t wait for the sender to send the
3 message and will not continue the message or data and continues the process. It
process until the sending process receives either a NULL message or a valid
exists. transmitted message by the sender.
In this communication, a process that receives
This communication occurs
asynchronous messages may or may not be
4 between various processes running
used by the process it is trying to send a
at the same time.
message to.

Q2. The following are the advantages of inter-process communication.

 It helps to share the same data or information between the multiple processes and perform various
tasks. In this, the process requires access to the remote process.
 The different processes can share the resources to provide communication between them.
 It increases the computational speed during communication between the processes.
 It enhances efficiency because the construction is divided into various modules. Where these
modules cooperate using IPS.
 Privilege separation.
 Comfort.
 It helps the processes and OS to communicate with each other with synchronization.
 The communication is bidirectional.
 Allows control of one application with another application.
 Enables data sharing without any interference.
Q3. The disadvantages of inter-process communication are,

 In message-passing IPC, a small amount of data is exchanged between the processes.


 The processes should not write to the same memory location while using a shared-memory
method.
 Synchronization issues.
 Data protection issues.
 Data accessing issues.
 It doesn’t work on multiple machines at the same time.

Q4. What are the operations performed in IPC?

There are 4 operations performed in IPC to exchange the data between the processes.

 Send
 Receive
 Connect
 Disconnect

You might also like