You are on page 1of 22

Task Communication

Introduction
• In multi tasking system, multiple tasks/processes executed
concurrently and they may or may not communication with
each other.
• Based on communication, the processes are classified as
1. Co – operating processes
2. Competing processes.
• Co – operating processes: in this one process requires the
inputs from other processes to complete its execution.
• Competing Processes: This processes do not share any
thing among them but share system resources.
Introduction Cont….
• Co – operating processes exchanges information and
communication through following methods.
– 1. Co – operation through sharing: exchange data
through shared resources.
– 2. Co – operation through communication: No data is
shared but communicate for synchronization.
• Inter process communication (IPC) is a mechanism
which allows processes to communicate each other
and synchronize their actions.
• IPC is essential for process coordination.
Inter Process Communication Mechanisms
• There are various IPC mechanisms used by process depends
on OS.
• The various mechanisms are:
1. Shared memory
– Pipes
– Memory mapped objects
2. Message passing
– Message Queue
– Mail Box
– Signaling
3. Remote procedure call (RPC) and sockets.
Shared Memory
• Shared memory is simplest way of inter process
communication.
• Shared memory IPCs refer to sharing a physical memory
location where multiple processes read and write to.
• It is same as the real world example where Notice Board
• The only exception is; only corporate have the right to modify
the information published on the Notice board and
employees are given ‘Read’ only access, meaning it is only a
one way channel
Shared Memory Cont….

Process P1 is writing to file “my-file” which is currently opened in shared memory


and in the meantime process P2 wants to read data from the same file by accessing
that shared memory, then, as a result, P2 may read more or less written data from
the file.
Pipes
• ‘Pipe’ is a section of the shared memory used by
processes for communicating.
• Pipes follow the client-server architecture.
• A process which creates a pipe is known as a pipe
server and a process which connects to a pipe is
known as pipe client.
• A Pipe can be unidirectional and Bidirectional
Pipes Cont….
• A unidirectional pipe allows the process connecting
at one end of the pipe to write to the pipe and the
process connected at the other end of the pipe to
read the data.
• Bi-directional pipe allows both reading and writing at
one end.
• The implementation of ‘Pipes’ is also OS dependent
Types of Pipes
• Microsoft Windows Desktop Operating
Systems support two types of ‘Pipes’ for Inter
Process Communication. They are:
• Anonymous Pipes: The anonymous pipes are
unnamed, unidirectional pipes used for data
transfer between two processes.
• Anonymous pipe is unnamed pipe. It provides
one-way communication or simplex.
Types of Pipes Cont….
• Named Pipes: Named pipe is a named, unidirectional or
bi-directional pipe for data exchange between processes.
• The process which creates the named pipe is known as
pipe server.
• A process which connects to the named pipe is known as
pipe client.
• With named pipes, any process can act as both client and
server allowing point-to-point communication.
• Under VxWorks kernel, pipe is a special implementation
of message queues
Message Passing
• In this method, processes communicate with each other without using any
kind of shared memory.
• If two processes p1 and p2 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, destination) or send(message)
– receive(message, host) or receive(message)
• The major difference between shared memory and message passing
technique is that, through shared memory lots of data can be shared
whereas only limited amount of info/data is passed through message
passing.
• But it is faster than shared memory.
Message Passing Cont….
Message Queue

• Usually the process which wants to talk to another


process posts the message to a First-In-First-Out
(FIFO) queue called ‘Message queue’, which stores
the messages temporarily in a system defined
memory object, to pass it to the desired process.
• It temporarily stores the message from a sender until
the intended receiver is ready to read them.
• The messages are exchanged through a message
queue.
Message Queue Cont….

• The implementation of the message


queue, send and receive methods are OS
kernel dependent.

Messaging mechanism can be used for task-


to task and task to Interrupt Service Routine
(ISR) communication
Mailbox
• Mailbox is an alternate form of ‘Message queues’ and it is used in
certain Real- Time Operating Systems for IPC.
• Mailbox technique for IPC in RTOS is usually used for one way
messaging.
• The task/thread which wants to send a message to other tasks/threads
creates a mailbox for posting the messages.
• The threads which are interested in receiving the messages posted to
the mailbox by the mailbox creator thread can subscribe to the mailbox.
• The thread which creates the mailbox is known as ‘mailbox server’ and
the threads which subscribe to the mailbox are known as ‘mailbox
clients’.
• Mailbox and message queues are same in functionality. The only
difference is in the number of messages supported by them.
Mailbox Cont….

Mailbox is used for exchanging a single


message between two tasks or between an
Interrupt Service Routine (ISR) and a task.
Signaling
• Signals are simple indications from one task to
another task to indicate the occurrence of an event.
• These indications may be used to trigger some task,
or indicate the availability of a resource etc.
• The various functions required to implement the
signals are listed below:
• Create or install a signal handler
• Delete or remove the signal handler
• Send a signal from one task to another task
• Ignore the received signal
Remote Procedure Call(RPC)
• A remote procedure call is an inter process communication
technique that is used for client-server based applications.
• It is also known as a subroutine call or a function call.
• A process to call a procedure of another process running on
the same CPU or on a different CPU which is interconnected in
a network.
• In the object oriented language terminology RPC is also
known as Remote Invocation or Remote Method Invocation
(RMI).
• RPC it is possible to communicate over a heterogeneous
network (i.e. Network where Client and server applications
are running on different Operating systems).
Remote Procedure Call(RPC) Cont…
• The CPU/process containing the procedure which needs to be
invoked remotely is known as server. The CPU/process which
initiates an RPC request is known as client.
• Interface Definition Language (IDL) defines the interfaces for RPC
• Microsoft Interface Definition Language (MIDL) is the IDL
implementation from Microsoft for all Microsoft platforms.
• The RPC communication can be either Synchronous (Blocking) or
Asynchronous (Non-blocking).
• In the Synchronous communication, the process which calls the
remote procedure is blocked until it receives a response back from
the other process.
• In asynchronous RPC calls, the calling process continues its execution
while the remote process performs the execution of the procedure.
Remote Procedure Call(RPC) Cont…

Authentication mechanisms
like IDs, public key
cryptography (like DES,
3DES), etc. are used by the
client for authentication.
Sockets
• Sockets are one of the most widely used communication APIs.
• A socket is an object from which messages and are sent and
received.
• A socket is a network communication endpoint.
• Socket is a logical endpoint in a two-way communication link
between two applications running on a network .
• Sockets are of different types i e ., Internet sockets (INET),
UNIX sockets, etc.
• The INET socket works on internet communication protocol
TCP/IP, UDP, etc. are the communication protocols used by
INET sockets.
Sockets Cont…
• INET sockets are classified into:
• 1. Stream sockets
• 2. Datagram sockets
• Connection Oriented:
• TCP (Transmission Control Protocol) is a connection-based
protocol that provides a reliable flow of data between two computers.
Stream sockets are connection oriented
• Connectionless:
UDP (User Datagram Protocol) is a protocol that sends independent
packets of data, called datagram's, from one computer to another
with no guarantees about arrival. UDP is not connection-based like TCP.

You might also like