Amrita
School
of
Engineering,
Bangalore
Ms. Harika Pudugosula
Teaching Assistant
Department of Electronics & Communication Engineering
2
 Operation on Procesess
 Process Creation
 Process Termination
 Interprocess Communication - Introduction
3
 Interprocess Communication
 Shared - Memory Systems
 Message - Passing Systems
• Naming
• Synchronization
• Buffering
4
Interprocess Communication
• Processes within a system may be independent or cooperating
• Independent process does not affect and does not get affected by other
process, they don’t share data
• Cooperating process can affect or be affected by other processes,
including sharing data
• Reasons and Advantages of process cooperation
• Information sharing - allow concurrent access of shared files
• Computation speedup - execution of process in parallel fashion
• Modularity - construct the system in a modular fashion
• Convenience - compilation of files in parallel
5
Interprocess Communication
• Cooperating processes need
interprocess communication
(IPC)
• Two models of IPC
• Shared memory systems
• Message passing systems
fig: Communications models. (a) Message passing. (b)
Shared memory
Interprocess Communication
7
Interprocess Communication
Shared - Memory Systems
• IPC using shared memory requires communicating processes to
establish a region of shared memory
• Shared-memory region lies in the address space of the process
creating the shared-memory segment
• What happens if other processes wishes to communicate ?
Producer-Consumer Problem
• Paradigm for cooperating processes, producer process produces
information that is consumed by a consumer process
• For example, a compiler may produce assembly code that is
consumed by an assembler, client–server paradigm, printer - printer
driver
• Producer - Consumer processes runs concurrently and must be
synchronized
• buffer will reside in a region of memory that is shared by the producer and
consumer processes
• Two types of buffer used in Producer - Consumer problems
• unbounded-buffer
• bounded-buffer
8
Producer-Consumer Problem
• unbounded-buffer
- no practical limit on the size of the buffer
- producer - always produces new item
- consumer - waits for new items
• bounded-buffer
- there is a fixed buffer size
- producer - consumer has to wait
producer - if buffer is full
consumer - if buffer is empty
9
Bounded-Buffer – Shared-Memory Solution
• Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0; /* points to next free position in the buffer */
int out = 0; /* points to first full position in the buffer */
• Solution is correct, but can only use BUFFER_SIZE-1 elements
10
Bounded-Buffer – Producer
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out) ;
/* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
11
Bounded Buffer – Consumer
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
/* consume the item in next consumed */
}
12
Interprocess 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.
• Synchronization is discussed in further classes
13
• Mechanism for processes to communicate and to synchronize their
actions
• Message system – processes communicate with each other without
resorting to shared variables or same shared address space
• For example, an Internet chat program
• IPC facility provides two operations:
• send(message)
• receive(message)
• The message size is either fixed or variable
14
Interprocess Communication – Message passing
• if the message size is fixed
• system-level implementation is straight - forward
• task of programming more difficult
• if the message size is variaable
• system-level implementation is complex
• task of programming simpler
15
Interprocess Communication – 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?
16
Interprocess Communication – Message passing
• Implementation of communication link
• Physical:
• Shared memory
• Hardware bus
• Network
• Logical:
• Direct or indirect
• Synchronous or asynchronous
• Automatic or explicit buffering
17
Interprocess Communication – Message passing
Direct Communication
• Processes must name each other explicitly the recipient or sender
of the communication
• 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
18
Direct Communication
• This scheme exhibits symmetry in addressing
• both the sender process and the receiver process must name the other
to communicate
• A variant of this scheme employs asymmetry in addressing
• only the sender names the recipient; the recipient is not required to
name the sender
• send (P, message)—Send a message to process P
• receive(id, message)—Receive a message from any process. The
variable id is set to the name of the process with which communication
has taken place
19
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
20
• Mailbox sharing
• P1, P2, and P3 share mailbox A
• P1, sends a message to A; P2 and P3 receives from A
• 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.
21
Indirect Communication
• If mailbox owned by Process
• Mailbox is part of the address space of the process
• Each mailbox has a unique owner
• Distinguish between the owner (which can only receive
messages through this mailbox) and the user (which can only
send messages to the mailbox)
• Mailbox terminates, then mailbox disappears
22
Indirect Communication
• If mailbox owned by an OS
• Provides a mechanism that allows a process to do
• Create a new mailbox
• Send and receive messages through the mailbox
• Delete a mailbox
• Can ownership and receiving privileges of mailbox be
passed to other mailbox ?
23
Indirect Communication
• Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
24
Indirect Communication
Synchronization
• Message passing may be either blocking or non-blocking
• Blocking is considered synchronous
• Blocking send -- the sender is blocked until the message is
received
• Blocking receive -- the receiver is blocked until a message is
available
• Non-blocking is considered asynchronous
• Non-blocking send -- the sender sends the message and continue
• Non-blocking receive -- the receiver receives:
- A valid message, or
- Null message
• Different combinations possible
• If both send and receive are blocking, we have a rendezvous
25
Producer-consumer becomes trivial - when we use blocking send() and
receive() statements
message next_produced;
while (true) {
/* produce an item in next produced*/
send(next_produced);
}
message next_consumed;
while (true) {
receive(next_consumed);
/* consume the item in next consumed */
}
26
Synchronization
Buffering
• Communicating processes reside in temporary queue
• Queue of messages attached to the link.
• Implemented in one of three ways
1. Zero capacity – max. length = 0, no messages are queued
Sender must wait for receiver (rendezvous) - with no buffering
2. Bounded capacity – finite length of n messages
Sender must wait if link full
3. Unbounded capacity – infinite length
Sender never waits
- automatic buffering
27
28
References
1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition,
John Wiley and Sons, 2012.
29
Thank you

Lecture-4_Process Management.pdf

  • 1.
    Amrita School of Engineering, Bangalore Ms. Harika Pudugosula TeachingAssistant Department of Electronics & Communication Engineering
  • 2.
    2  Operation onProcesess  Process Creation  Process Termination  Interprocess Communication - Introduction
  • 3.
    3  Interprocess Communication Shared - Memory Systems  Message - Passing Systems • Naming • Synchronization • Buffering
  • 4.
    4 Interprocess Communication • Processeswithin a system may be independent or cooperating • Independent process does not affect and does not get affected by other process, they don’t share data • Cooperating process can affect or be affected by other processes, including sharing data • Reasons and Advantages of process cooperation • Information sharing - allow concurrent access of shared files • Computation speedup - execution of process in parallel fashion • Modularity - construct the system in a modular fashion • Convenience - compilation of files in parallel
  • 5.
    5 Interprocess Communication • Cooperatingprocesses need interprocess communication (IPC) • Two models of IPC • Shared memory systems • Message passing systems fig: Communications models. (a) Message passing. (b) Shared memory
  • 6.
  • 7.
    7 Interprocess Communication Shared -Memory Systems • IPC using shared memory requires communicating processes to establish a region of shared memory • Shared-memory region lies in the address space of the process creating the shared-memory segment • What happens if other processes wishes to communicate ?
  • 8.
    Producer-Consumer Problem • Paradigmfor cooperating processes, producer process produces information that is consumed by a consumer process • For example, a compiler may produce assembly code that is consumed by an assembler, client–server paradigm, printer - printer driver • Producer - Consumer processes runs concurrently and must be synchronized • buffer will reside in a region of memory that is shared by the producer and consumer processes • Two types of buffer used in Producer - Consumer problems • unbounded-buffer • bounded-buffer 8
  • 9.
    Producer-Consumer Problem • unbounded-buffer -no practical limit on the size of the buffer - producer - always produces new item - consumer - waits for new items • bounded-buffer - there is a fixed buffer size - producer - consumer has to wait producer - if buffer is full consumer - if buffer is empty 9
  • 10.
    Bounded-Buffer – Shared-MemorySolution • Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; /* points to next free position in the buffer */ int out = 0; /* points to first full position in the buffer */ • Solution is correct, but can only use BUFFER_SIZE-1 elements 10
  • 11.
    Bounded-Buffer – Producer itemnext_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; } 11
  • 12.
    Bounded Buffer –Consumer item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ } 12
  • 13.
    Interprocess 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. • Synchronization is discussed in further classes 13
  • 14.
    • Mechanism forprocesses to communicate and to synchronize their actions • Message system – processes communicate with each other without resorting to shared variables or same shared address space • For example, an Internet chat program • IPC facility provides two operations: • send(message) • receive(message) • The message size is either fixed or variable 14 Interprocess Communication – Message passing
  • 15.
    • if themessage size is fixed • system-level implementation is straight - forward • task of programming more difficult • if the message size is variaable • system-level implementation is complex • task of programming simpler 15 Interprocess Communication – Message passing
  • 16.
    • If processesP 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? 16 Interprocess Communication – Message passing
  • 17.
    • Implementation ofcommunication link • Physical: • Shared memory • Hardware bus • Network • Logical: • Direct or indirect • Synchronous or asynchronous • Automatic or explicit buffering 17 Interprocess Communication – Message passing
  • 18.
    Direct Communication • Processesmust name each other explicitly the recipient or sender of the communication • 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 18
  • 19.
    Direct Communication • Thisscheme exhibits symmetry in addressing • both the sender process and the receiver process must name the other to communicate • A variant of this scheme employs asymmetry in addressing • only the sender names the recipient; the recipient is not required to name the sender • send (P, message)—Send a message to process P • receive(id, message)—Receive a message from any process. The variable id is set to the name of the process with which communication has taken place 19
  • 20.
    Indirect Communication • Messagesare 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 20
  • 21.
    • Mailbox sharing •P1, P2, and P3 share mailbox A • P1, sends a message to A; P2 and P3 receives from A • 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. 21 Indirect Communication
  • 22.
    • If mailboxowned by Process • Mailbox is part of the address space of the process • Each mailbox has a unique owner • Distinguish between the owner (which can only receive messages through this mailbox) and the user (which can only send messages to the mailbox) • Mailbox terminates, then mailbox disappears 22 Indirect Communication
  • 23.
    • If mailboxowned by an OS • Provides a mechanism that allows a process to do • Create a new mailbox • Send and receive messages through the mailbox • Delete a mailbox • Can ownership and receiving privileges of mailbox be passed to other mailbox ? 23 Indirect Communication
  • 24.
    • Primitives aredefined as: send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A 24 Indirect Communication
  • 25.
    Synchronization • Message passingmay be either blocking or non-blocking • Blocking is considered synchronous • Blocking send -- the sender is blocked until the message is received • Blocking receive -- the receiver is blocked until a message is available • Non-blocking is considered asynchronous • Non-blocking send -- the sender sends the message and continue • Non-blocking receive -- the receiver receives: - A valid message, or - Null message • Different combinations possible • If both send and receive are blocking, we have a rendezvous 25
  • 26.
    Producer-consumer becomes trivial- when we use blocking send() and receive() statements message next_produced; while (true) { /* produce an item in next produced*/ send(next_produced); } message next_consumed; while (true) { receive(next_consumed); /* consume the item in next consumed */ } 26 Synchronization
  • 27.
    Buffering • Communicating processesreside in temporary queue • Queue of messages attached to the link. • Implemented in one of three ways 1. Zero capacity – max. length = 0, no messages are queued Sender must wait for receiver (rendezvous) - with no buffering 2. Bounded capacity – finite length of n messages Sender must wait if link full 3. Unbounded capacity – infinite length Sender never waits - automatic buffering 27
  • 28.
    28 References 1. Silberscatnz andGalvin, “Operating System Concepts,” Ninth Edition, John Wiley and Sons, 2012.
  • 29.