Académique Documents
Professionnel Documents
Culture Documents
02.04 Lesson 6
Operating Systems
02.04 Communication between processes
emanuele lattanzi
Operating Systems
1/23
02.04 Lesson 6
Cooperating Processes
Independent process cannot affect or be
affected by the execution of another process
Cooperating process can affect or be affected by
the execution of another process
Advantages of process cooperation
Information sharing
Computation speed-up
Convenience
emanuele lattanzi
2/23
Operating Systems
02.04 Lesson 6
Message passing
emanuele lattanzi
Operating Systems
3/23
02.04 Lesson 6
Communications Models
emanuele lattanzi
4/23
Operating Systems
02.04 Lesson 6
Producer-Consumer Problem
Paradigm for cooperating processes,
producer process produces information
that is consumed by a consumer process
unbounded-buffer places no practical limit
on the size of the buffer
bounded-buffer assumes that there is a
fixed buffer size
emanuele lattanzi
Operating Systems
5/23
02.04 Lesson 6
Bounded-Buffer Shared-Memory
Solution
Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
6/23
Operating Systems
02.04 Lesson 6
Bounded-Buffer Insert()
Method
while (true) {
/* Produce an item */
while ((in + 1) % BUFFER_SIZE) == out)
;
/* do nothing -- no free buffers */
buffer[in] = item;
in = (in + 1) % BUFFER_SIZE;
}
emanuele lattanzi
Operating Systems
7/23
02.04 Lesson 6
emanuele lattanzi
8/23
Operating Systems
02.04 Lesson 6
emanuele lattanzi
Operating Systems
02.04 Lesson 6
9/23
Message passing
emanuele lattanzi
10/23
Operating Systems
02.04 Lesson 6
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
Operating Systems
11/23
02.04 Lesson 6
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
12/23
Operating Systems
02.04 Lesson 6
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.
emanuele lattanzi
Operating Systems
13/23
02.04 Lesson 6
Indirect Communication
Operations
create a new mailbox
send and receive messages through mailbox
destroy a mailbox
emanuele lattanzi
14/23
Operating Systems
02.04 Lesson 6
Synchronization
Message passing may be either blocking or
non-blocking
Blocking is considered synchronous
Blocking send: the sender blocks until the message
is received
Blocking receive: the receiver blocks until a
message is available (rendezvous)
Operating Systems
15/23
02.04 Lesson 6
Buffering
Queue of messages attached to the link;
implemented in one of three ways
1. Zero capacity 0 messages
Sender must wait for receiver (rendezvous)
2. Bounded capacity finite length of n
messages
Sender must wait if link full
3. Unbounded capacity infinite length
Sender never waits
emanuele lattanzi
16/23
Operating Systems
02.04 Lesson 6
Client-Server Communication
Sockets
Remote Procedure Calls
Remote Method Invocation (Java)
emanuele lattanzi
Operating Systems
17/23
02.04 Lesson 6
Sockets
A socket is defined as an endpoint for
communication
Concatenation of IP address and port
The socket 161.25.19.8:1625 refers to port
1625 on host 161.25.19.8
Communication consists between a pair of
sockets
emanuele lattanzi
18/23
Operating Systems
02.04 Lesson 6
Socket Communication
emanuele lattanzi
Operating Systems
02.04 Lesson 6
emanuele lattanzi
19/23
20/23
10
Operating Systems
02.04 Lesson 6
emanuele lattanzi
Operating Systems
21/23
02.04 Lesson 6
22/23
11
Operating Systems
02.04 Lesson 6
emanuele lattanzi
23/23
12