CSET209 OPERATING
SYSTEM
Lecture 9 Inter-process Communication
Deepika Vatsa
OUTLINE
Inter process communication
Shared Memory Method
Message passing method and its types
INTER PROCESS COMMUNICATION (IPC)
Processes within a system may be independent or cooperating
Cooperating process can affect or be affected by other processes, including sharing data
IPC is a mechanism where one process communicates with another process
Communication: Exchange of data
Example:
In linux, ls command lists the filenames of files in a directory
And lpr command prints the input using printer
So, ls | lpr will print the filenames of files in a directory
Here, pipe (|) acts as an IPC between two processes ls and lpr
WHY IPC?
Information sharing
Resource sharing
Computation speedup
Synchronization
Modularity
Convenience
2 MODELS OF IPC MECHANISMS
Message Passing: Message is
passed using a queue
Shared memory
IMG
SRC: https://www.os-book.com/OS9/slide-dir/PPT-dir/ch3.ppt
IPC: SHARED MEMORY
An area of memory shared among the processes that wish to communicate
The communication is under the control of the users processes not the operating system.
Major issues is to provide mechanism that will allow the user processes to synchronize
their actions when they access shared memory.
IPC: MESSAGE PASSING
Mechanism for processes to communicate and to synchronize their actions
Message system – processes communicate with each other without resorting to shared
variables
IPC facility provides two operations: send(message) and receive(message)
The message size is either fixed or variable
IPC: MESSAGE PASSING
If processes P and Q wish to communicate, they need to:
Establish a communication link between them
Exchange messages via send/receive
Implementation issues:
How are links established?
Can a link be associated with more than two processes?
How many links can there be between every pair of communicating processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate fixed or variable?
Is a link unidirectional or bi-directional?
IPC: MESSAGE PASSING
Implementation of communication link
● Physical:
Shared memory
Hardware bus
Network
● Logical:
Direct or indirect
Synchronous or asynchronous
Automatic or explicit buffering
IPC: MESSAGE PASSING
Processes must name each other explicitly:
● send (P, message) – send a message to process P
● receive(Q, message) – receive a message from process Q
Properties of communication link
● Links are established automatically
● A link is associated with exactly one pair of communicating processes
● Between each pair there exists exactly one link
● The link may be unidirectional, but is usually bi-directional
INDIRECT COMMUNICATION
Messages are directed and received from
mailboxes (also referred to as ports)
● Each mailbox has a unique id
● Processes can communicate only if they
share a mailbox
Properties of communication link
● Link established only if processes share a
common mailbox
● A link may be associated with many
processes
● Each pair of processes may share several
communication links
● Link may be unidirectional or bi-
directional
INDIRECT COMMUNICATION
Operations
● create a new mailbox (port)
● send and receive messages through mailbox
● destroy a mailbox
Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
INDIRECT COMMUNICATION
Mailbox sharing
● P1, P2, and P3 share mailbox A
● P1, sends; P2 and P3 receive
● Who gets the message?
Solutions
● Allow a link to be associated with at most two processes
● Allow only one process at a time to execute a receive operation
● Allow the system to select arbitrarily the receiver.
● Sender is notified who the receiver was.
Thank
You