0% found this document useful (0 votes)
29 views22 pages

BCS Module 2 - Cpu Scheduling

This document discusses inter-process communication (IPC) in operating systems. It covers two common IPC models - shared memory and message passing. With shared memory, processes communicate by accessing shared areas of memory. With message passing, processes communicate by exchanging messages using send and receive operations. The document describes direct and indirect message passing, synchronous vs asynchronous communication, and how indefinite blocking and deadlocks can be avoided using timeouts.

Uploaded by

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

BCS Module 2 - Cpu Scheduling

This document discusses inter-process communication (IPC) in operating systems. It covers two common IPC models - shared memory and message passing. With shared memory, processes communicate by accessing shared areas of memory. With message passing, processes communicate by exchanging messages using send and receive operations. The document describes direct and indirect message passing, synchronous vs asynchronous communication, and how indefinite blocking and deadlocks can be avoided using timeouts.

Uploaded by

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

KAMPALA INTERNATIONAL UNIVERISITY

IN TANZANIA

Program: BCS 3.1


Course: OPERATING SYSTEMS II
Instructor: Mrs. Eunice Jengo
Recap from Operating System 1

• Basics of OPERATING SYSTEM


• Process & Threads
• CPU/Process Scheduling
• Memory management
• File systems and management
Course Outline: Operating System II

• CPU/Process Scheduling
• Inter-Process Communication
• Memory management & Virtual Memory
• I/O management
• File systems and management
Interprocess Communication

• Processes within a system may be independent or


cooperating
• Cooperating process can affect or be affected by other
processes, including sharing data
• Reasons for cooperating processes:
• Information sharing
• Computation speedup
• Modularity
• Convenience
• Cooperating processes need inter-process communication
(IPC)
• Two models of IPC
• Shared memory
• Message passing
Communications Models

(a) Message passing. (b) shared memory.


Inter-process Communication – 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.
Inter-process Communication – 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)
• receive(message)

• The message size is either fixed or variable


Message Passing (Cont.)

• 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?
Message Passing (Cont.)

• Implementation of communication link


• Physical:
• Shared memory
• Hardware bus
• Network
• Logical:
• Direct or indirect
• Synchronous or asynchronous
• Automatic or explicit buffering
Direct Communication
• 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.
Event Synchronization
• Inter-process communication may require that the
two processes synchronize their operations: one
side sends, then the other receives until all data
has been sent and received.
• Ideally, the send operation starts before the receive
operation commences.
Synchronous vs. Asynchronous
Communication

• The IPC operations may provide the synchronization


necessary using blocking. A blocking operation issued by a
process will block further processing of the process until the
operation is fulfilled.
• Alternatively, IPC operations may be asynchronous or non-
blocking. An asynchronous operation issued by a process will
not block further processing of the process. Instead, the
process is free to proceed with its processing, and may
optionally be notified by the system when the operation is
fulfilled.
Synchronous send and receive

process 1 process 2
running on host 1 running on host 2 Event Diagram

blocking receive starts

blocking send starts an operation

execution flow
acknowledgement of data received suspended period
blocking send returns provided by the IPC facility blocking receive ends

Synchronous Send and Receive

Client Server
Sender Receiver
17

Event diagram

Process B
Process A

time
request 1

response 1

request 2
interprocess communication
execution flow
response2
process blocked

Event diagram for a protocol


Synchronous send and receive
Asynchronous send and
synchronous receive
Process 2
Process 1 Event Diagram

blocking receive starts

nonblocking send

operation
execution flow
suspended period
blocking receive returns

Asynchronous Send and


Synchronous Receive

Client Server
Sender Receiver
Blocking, deadlock, and timeouts

• Blocking operations issued in the wrong sequence can cause


deadlocks.
• Deadlocks should be avoided. Alternatively, timeout can be used to
detect deadlocks.

Process 1 Process 2

receive from process 2 issued


process 1 blocked pending data
from process 2.
received from process 1 issued
process 2 blocked pending data
from process 1.

P1 is waiting for P2’s data; P2 is waiting for P1’s data.


Using threads for asynchronous IPC

• When using an IPC programming interface, it is important to note


whether the operations are synchronous or asynchronous.
• If only blocking operation is provided for send and/or receive,
then it is the programmer’s responsibility to using child processes
or threads if asynchronous operations are desired.
process

main thread

new thread issues a blocking IPC operation

thread is blocked
main thread continues with
other processing
thread is unblocked after the operation is fulfilled
Deadlocks and Timeouts

• Connect and receive operations can result in indefinite


blocking
• For example, a blocking connect request can result in the
requesting process to be suspended indefinitely if the
connection is unfulfilled or cannot be fulfilled, perhaps as a
result of a breakdown in the network .
• It is generally unacceptable for a requesting process to “hang”
indefinitely. Indefinite blocking can be avoided by using
timeout.
• Indefinite blocking may also be caused by a deadlock
Indefinite blocking due to a deadlock

Process 1 Process 2

"receive from process 2" issued;


process 1 blocked pending data
from process 2.
"receive from process 1" issued;
process 2 blocked pending data
an ope ration
from process 1.
proce ss
e xe cuting
proce ss
blocke d

P1 is waiting for P2’s data; P2 is waiting for P1’s data.

You might also like