A brief introduction to task communication in real time operating system.It covers Inter-process communication like concepts of shared memory , message passing, remoteprocedure call .Interprocess communication (IPC) refers specifically to the mechanisms an operating system provides to allow the processes to manage shared data. Typically, applications can use IPC, categorized as clients and servers, where the client requests data and the server responds to client requests.Many applications are both clients and servers, as commonly seen in distributed computing.
2. WHAT IS A TASK ?
It is defined as a program in execution and has an
order of priority , schedule or timeline for
execution.
Also called a “job” .
A program / part of task / job in execution is called
a process.
4. TASK COMMUNICATION
Task communication comprises all mechanisms serving to exchange
information among tasks.
In a multitasking system multiple task/ process run concurrently (in
pseudo parallelism ) & each process may / may not interact .
Based on degree of interaction , processes running on OS are classified
as :
Cooperating process
Competing process
5. Cooperating Process
Cooperating processes are those that can affect or
are affected by other processes running on the
system. Cooperating processes may share data with
each other.
Exchange of information & communication by:
Cooperation by sharing
Cooperation by communication
6. Cooperation by sharing
The cooperating processes can cooperate
with each other using shared data such as
memory, variables, files, databases etc.
Critical section is used to provide data
integrity and writing is mutually exclusive to
prevent inconsistent data.
7. Cooperation by communication
No data is shared between processes . They
communicate for synchronization . The cooperating
processes can cooperate with each other using
messages. This may lead to deadlock if each
process is waiting for a message from the other to
perform a operation. Starvation is also possible if a
process never receives a message.
8. Competing Process
The processes do not share anything among themselves but they
share system resources . These type of processes compete for
system resources like file, display devices etc.
PROCESS 1 PROCESS 2 PROCESS 3
SHARED RESOURCES
(Critical Section)
9. INTER PROCESS COMMUNICATION (IPC)
The mechanism by which process or task communicate.
Essential for process coordination
IPC Mechanisms:
Shared Memory
Message Passing
Remote Procedure Call & Sockets
10. Shared Memory
Information to be communicated is written to shared
memory. Process that require this information can read it
from there.
It’s implementation is kernel dependant.
Mechanisms for implementing shared memory for IPC :
Pipes
Memory mapped objects
11. PIPES
A section of shared memory used by processes for
communicating .
Process that create a pipe – Pipe Server
Process that connect a pipe – Pipe Client
There are two types of pipe for IPC :
Anonymous pipes
Named pipes WRITE ()
READ()
PROCESS
P[0]
P[1]
12. Anonymous pipe:
Unnamed, unidirectional for data transfer between two processes.
Named pipe:
Named , unidirectional / bidirectional for data exchange between
two processes.
Any process can act as both client and server allowing
point to point communication.
13. Memory Mapped Objects
A shared memory technique adopted by RTOS for allocating
shared block of memory that can be accessed by multiple
process simultaneously.
Any process which want to share data with other process can
map physical memory area of mapped object to it’s virtual
memory space and use it for sharing data.
15. MESSAGE PASSING
Operations
Send(message)
Receive(message)
Methods to implement link b/w two processes
Direct or indirect communication
Synchronous or asynchronous communication
16. Direct communication
Each process must explicitly name the recipient or sender of
communication.
send(P, message) – send a message to process P
receive(Q, message) – receive a message from process Q
Communication link has the following properties
Link is automatically established. Process must only know the
identity of other process.
Link is associated with exactly two processes
B/w each pair of processes, exists exactly one link
19. Indirect communication
Messages are sent and received through mailboxes or ports.
Send(A, message) – send a message to mailbox
Receive (A, message) – receive a message from mailbox A
Link properties
Link is established between a pair of processes only if both
members of the pair have a shared mailbox.
Link may be associated with more than two processes.
Between each pair of communicating processes,
there may be a number of different links, with each
link corresponding to one mailbox.
21. Type of Communication
link by Mail Box:
One to One Link.
Many to One Link.
One to Many Link.
Many to Many link.
22. Difference between Shared
memory and Message passing
Shared memory
1. Processes exchange
information by reading
or writing into the
shared region.
2. Used for exchanging
large amount of data.
3. Faster than message
passing (system calls
required only to
establish shared
region and rest all
access are treated as
normal memory
access)
Message passing
1. Direct exchange of
messages.
2. Used for exchanging
small amounts of
data.
3. Slower than shared
memory because it is
implemented using
system calls , which
involves kernel
intervention.
23. REMOTE PROCEDURE CALL (RPC)
Is a protocol that one program can use to request a service from a
program located in another computer in a network without having to
understand network details.
A procedure call is also sometimes known as a function call or a
subroutine call.
The requesting program is a client and the service- providing
program is the server.
When program statements that use RPC are compiled into an
executable program, a stub is included in the compiled code
that acts as the representative of the remote procedure code.
the server includes a runtime program and stub that
interface with the remote procedure itself.
24. RPC allows programs to call procedures located on other machines.
When a process on machine A calls' a
procedure on machine B, the calling process
on A is suspended, and execution of the
called procedure takes place on B.
Information can be transported from the
caller to the callee in the parameters and
can come back in the procedure result.
25. STUBS
When the calling process calls a procedure, the action performed by that procedure will
not be the actual code as written, but code that begins network communication.
It has to connect to the remote machine, send all the parameters down to it, wait for
replies, do the right thing to the stack and return. This is the client side stub.
The server side stub has to wait for messages asking for
a procedure to run.
It has to read the parameters, and present them in a suitable form to execute the
procedure locally. After execution, it has to send the results back to the calling process.
26. HOW RPC WORKS?
An RPC is analogous to a function call. Like a
function call, when an RPC is made, the
calling arguments are passed to the remote
procedure and the caller waits for a response
to be returned from the remote procedure.
The client makes a procedure call that sends a
request to the server and waits.
When the request arrives, the server calls a
dispatch routine that performs the requested
service, and sends the reply to the client.
After the RPC call is completed, the client
program continues. RPC specifically
supports network applications.
27.
28. RPC APPLICATION DEVELOPMENT
To develop an RPC application the following steps are needed:
Specify the protocol for client server communication
Develop the client program
Develop the server program
The programs will be compiled separately.
The communication protocol is achieved by generated stubs
and these stubs and RPC (and other libraries) will need to
be linked in.
29. STUB
The client calls the local stub procedure. The stub packages up the
parameters into a network message. This is called marshaling.
Networking functions in the O/S kernel are called by the stub to send the
message.
The kernel sends the message(s) to the remote system. This maybe
connection-oriented or connectionless.
A server stub unmarshals the arguments from the network message.
The server stub executes a local procedure call.
The procedure completes, returning execution to the server stub.
The server stub marshals the return values into a networkmessage.
The return messages are sent back.
The client stub reads the messages using the network functions.
The message is unmarshalled. And the return values are set on the
stack for the local process.