SlideShare a Scribd company logo
A. Frank - P. Weisberg
Operating Systems
Inter-Process
Communication (IPC)
2 A. Frank - P. Weisberg
Introduction to Concurrency
• Classical Problems of Concurrency
• Critical Regions
• Monitors
• Inter-Process Communication (IPC)
• Communications in Client-Server
Systems
3 A. Frank - P. Weisberg
Inter-Process Communication (IPC)
• Mechanism for processes to communicate and
to synchronize their actions.
• Message system – processes communicate with
each other without resorting to shared variables.
• We have at least two primitives:
– send(destination, message) or send(message)
– receive(source, message) or receive(message)
• Message size is fixed or variable.
4
Basic Message-passing Primitives
A. Frank - P. Weisberg
5 A. Frank - P. Weisberg
Message format
• Consists of header and
body of message.
• In Unix: no ID, only
message type.
• Control info:
– what to do if run out of
buffer space.
– sequence numbers.
– priority.
• Queuing discipline: usually
FIFO but can also include
priorities.
6 A. Frank - P. Weisberg
Messages and Pipes Compared
7 A. Frank - P. Weisberg
Message Passing
• Message passing is a general method used
for IPC:
– for processes inside the same computer.
– for processes in a networked/distributed
system.
• In both cases, the process may or may not
be blocked while sending a
message or attempting to
receive a message.
8 A. Frank - P. Weisberg
Synchronization in message passing (1)
• Message passing may be blocking or non-blocking.
• Blocking is considered synchronous
– Blocking send has the sender block until the message is
received
– Blocking receive has the receiver block until a message is
available
• Non-blocking is considered asynchronous
– Non-blocking send has the sender send the message and
continue
– Non-blocking receive has the receiver receive a valid
message or null
9 A. Frank - P. Weisberg
Synchronization in message passing (2)
• For the sender: it is more natural not to be
blocked after issuing send:
– can send several messages to multiple destinations.
– but sender usually expect acknowledgment of
message receipt (in case receiver fails).
• For the receiver: it is more natural to be
blocked after issuing receive:
– the receiver usually needs the information before
proceeding.
– but could be blocked indefinitely if sender process
fails before send.
10 A. Frank - P. Weisberg
Synchronization in message passing (3)
• Hence other possibilities are sometimes
offered.
• Example: blocking send, blocking receive:
– both are blocked until the message is
received.
– occurs when the communication link is
unbuffered (no message queue).
– provides tight synchronization (rendezvous).
11
• There are really 3 combinations here that
make sense:
1. Blocking send, Blocking receive
2. Nonblocking send, Nonblocking receive
3. Nonblocking send, Blocking receive – most
popular – example:
• Server process that provides services/resources
to other processes. It will need the expected
information before proceeding.
Synchronization in message passing (4)
12 A. Frank - P. Weisberg
IPC Requirements
• If P and Q wish to communicate, they
need to:
– establish communication link between them.
– exchange messages via send/receive.
• Implementation of communication link:
– physical (e.g., shared memory, hardware bus)
– logical (e.g., logical properties)
13 A. Frank - P. Weisberg
Implementation Questions
• 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?
14 A. Frank - P. Weisberg
Link Capacity – 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.
15 A. Frank - P. Weisberg
Direct/Indirect Communication
• Direct communication:
– when a specific process identifier is used for
source/destination.
– but it might be impossible to specify the source
ahead of time (e.g., a print server).
• Indirect communication (more convenient):
– messages are sent to a shared mailbox which
consists of a queue of messages.
– senders place messages in the mailbox, receivers
pick them up.
16 A. Frank - P. Weisberg
Direct Communication
• Processes must name each other explicitly:
– send(P, message) – send a message to process P
– receive(Q, message) – receive a message from 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.
17 A. Frank - P. Weisberg
Indirect Communication (1)
• 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.
18 A. Frank - P. Weisberg
Indirect Communication (2)
• Operations
– create a new mailbox
– 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.
19 A. Frank - P. Weisberg
Indirect Communication (3)
• Mailbox sharing
– P1, P2, and P3 share mailbox A.
– P1, sends; P2 and P3 receive.
– Who gets the message?
• Possible 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.
20
Mailboxes and Ports
• A mailbox can be private to one
sender/receiver pair.
• The same mailbox can be
shared among several senders
and receivers:
– the OS may then allow the
use of message types (for
selection).
• Port: is a mailbox associated
with one receiver and multiple
senders
– used for client/server
applications: the receiver is
the server.
21 A. Frank - P. Weisberg
Ownership of ports and mailboxes
• A port is usually own and created by the
receiving process.
• The port is destroyed when the receiver
terminates.
• The OS creates a mailbox on behalf of a
process (which becomes the owner).
• The mailbox is destroyed at the owner’s request
or when the owner terminates.
22 A. Frank - P. Weisberg
Mutual Exclusion – Message Passing
• create a mailbox mutex
shared by n processes.
• send() is non-blocking.
• receive() blocks when
mutex is empty.
• Initialization:
send(mutex, “go”);
• The first Pi who executes
receive() will enter CS.
Others will be blocked
until Pi resends msg.
Process Pi:
var msg: message;
repeat
receive(mutex,msg);
CS
send(mutex,msg);
RS
forever
23 A. Frank - P. Weisberg
Bounded-Buffer – Message Passing
• The producer place items (inside messages) in the
mailbox mayconsume.
• mayconsume acts as our buffer: consumer can
consume item when at least one message present.
• Mailbox mayproduce is filled initially with k null
messages (k= buffer size).
• The size of mayproduce shrinks with each
production and grows with each consumption.
• Solution can support multiple producers/consumers.
24 A. Frank - P. Weisberg
Bounded-Buffer – Message Passing
Producer:
var pmsg: message;
repeat
receive(mayproduce, pmsg);
pmsg := produce();
send(mayconsume, pmsg);
forever
Consumer:
var cmsg: message;
repeat
receive(mayconsume, cmsg);
consume(cmsg);
send(mayproduce, null);
forever
25 A. Frank - P. Weisberg
P/C Problem with Message Passing (1)
26 A. Frank - P. Weisberg
P/C Problem with Message Passing (2)
27 A. Frank - P. Weisberg
Examples of IPC Systems – POSIX
• POSIX Shared Memory example
• Process first creates shared memory segment
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR |
S_IWUSR);
• Process wanting access to that shared memory must attach to it
shared_memory = (char *) shmat(segment_id, NULL, 0);
• Now the process could write to the shared memory
sprintf(shared_memory, "Writing to shared memory");
• When done a process can detach the shared memory from its address space
shmdt(shared_memory);
• Now process can remove the shared memory segment
shmdt(shared_id, IPC_RMID, NULL);
28 A. Frank - P. Weisberg
Examples of IPC Systems – Mach
• Mach communication is message based:
– Even system calls are messages.
– Each task gets two mailboxes at creation:
Kernel and Notify.
– Only three system calls needed for message
transfer:
msg_send(), msg_receive(), msg_rpc()
– Mailboxes needed for communication, created via
port_allocate()
29 A. Frank - P. Weisberg
Examples of IPC Systems – Windows XP
• Message-passing centric via LPC facility:
– Only works between processes on the same system.
– Uses ports (like mailboxes) to establish and maintain
communication channels.
– Communication works as follows:
• The client opens a handle to the subsystem’s connection
port object.
• The client sends a connection request.
• The server creates two private communication ports and
returns the handle to one of them to the client.
• The client and server use the corresponding port handle
to send messages or callbacks and to listen for replies.
30 A. Frank - P. Weisberg
Local Procedure Calls in Windows XP
31 A. Frank - P. Weisberg
Communications in Client-Server Systems
• There are various mechanisms:
1. Pipes
2. Sockets (Internet)
3. Remote Procedure Calls (RPCs)
4. Remote Method Invocation (RMI, Java)
32
Pipes
• Acts as a conduit allowing two processes to
communicate.
• Some issues:
• Is communication unidirectional or bidirectional?
• In the case of two-way communication, is it half
or full-duplex?
• Must there exist a relationship (i.e., parent-child)
between the communicating processes?
• Can the pipes be used over a network?
33
Ordinary Pipes
• Ordinary Pipes allow communication in
standard producer-consumer style.
• Producer writes to one end (the write-end of
the pipe).
• Consumer reads from the other end (the read-
end of the pipe).
• Ordinary pipes are therefore unidirectional.
• Require parent-child relationship between
communicating processes.
34
Ordinary Pipes
35
Named Pipes
• Named Pipes are more powerful than ordinary
pipes.
• Communication is bidirectional.
• No parent-child relationship is necessary
between the communicating processes.
• Several processes can use the named pipe for
communication.
• Provided on both UNIX and Windows systems.
36 A. Frank - P. Weisberg
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.
37 A. Frank - P. Weisberg
Socket Communication
38 A. Frank - P. Weisberg
Remote Procedure Calls (RPCs)
• RPC abstracts a Local Procedure Call (LPC) between
processes on a networked system.
• Stubs – client-side proxy for the actual procedure
existing on the server.
• The client-side stub locates the server and marshals
the parameters.
• The server-side stub/skeleton receives this message,
unpacks the marshaled parameters, and performs the
procedure on the server.
• Vice versa happens on the opposite direction.
39
Remote Procedure Call Mechanism
A. Frank - P. Weisberg
40 A. Frank - P. Weisberg
Execution of RPC
41 A. Frank - P. Weisberg
Remote Method Invocation
• Remote Method Invocation (RMI) is a Java
mechanism similar to RPCs.
• RMI allows a Java program on one machine to
invoke a method on a remote object.
42 A. Frank - P. Weisberg
(
Un
)
Marshalling Parameters

More Related Content

PDF
ITFT_Inter process communication
PPTX
PPTX
PPTX
Operating system 19 interacting processes and ipc
PDF
Lecture-4_Process Management.pdf
PDF
interprocess-communication.pdf
PPT
1 messagepassing-121015032028-phpapp01
PPTX
CSC 2205 OS Lecture 08 IPC P-2 on 14-10-2024 ONLINE.pptx
ITFT_Inter process communication
Operating system 19 interacting processes and ipc
Lecture-4_Process Management.pdf
interprocess-communication.pdf
1 messagepassing-121015032028-phpapp01
CSC 2205 OS Lecture 08 IPC P-2 on 14-10-2024 ONLINE.pptx

Similar to 41_P17CSC104_20201209054563635172951.ppt (20)

PPTX
Chapter 3 - InterProcess Communication.pptx
PPTX
Chapter 3b- Process Communication (1) (1)(1) (1).pptx
PDF
LECTURE 3,4 &5Communication.pdfDistributed systems for computer students both...
PDF
LECTURE 3,4 &5Communication.pdf distributed systems continued
PPT
PPSX
Task_Comm_part1_RTS_course_Masters_degree.ppsx
PPTX
Inter process communication
PDF
Towards Improved Data Dissemination of Publish-Subscribe Systems
PPT
Inter-Process communication in Operating System.ppt
PPT
11 group communication
PPTX
Kafka.pptx
PPT
Ch03 processes
PPTX
Message Broker System and RabbitMQ
PPTX
Message and Stream Oriented Communication
PPT
Transport ppt for students examination.ppt
PPT
05Transport.ppt
PPTX
distrbuted system show how distbuted system
PPTX
Kafka tutorial
PPT
Interprocess communication (IPC) IN O.S
PPTX
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Chapter 3 - InterProcess Communication.pptx
Chapter 3b- Process Communication (1) (1)(1) (1).pptx
LECTURE 3,4 &5Communication.pdfDistributed systems for computer students both...
LECTURE 3,4 &5Communication.pdf distributed systems continued
Task_Comm_part1_RTS_course_Masters_degree.ppsx
Inter process communication
Towards Improved Data Dissemination of Publish-Subscribe Systems
Inter-Process communication in Operating System.ppt
11 group communication
Kafka.pptx
Ch03 processes
Message Broker System and RabbitMQ
Message and Stream Oriented Communication
Transport ppt for students examination.ppt
05Transport.ppt
distrbuted system show how distbuted system
Kafka tutorial
Interprocess communication (IPC) IN O.S
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Ad

More from farantouqeer8 (20)

PPTX
Tahreem_Kousar_EconomicsSSSSSSSS_file[1].pptx
PPT
academic_writingGGGGGGGGGGGGGGGGGGGG.ppt
PPTX
POM-.hffffffffffffffffiiiiiiiiiiiiiiiiiiiiipptx
PPTX
presentationnnnnnnnnnnnnnnnnnnnnnnnn.pptx
PPTX
Group no 5 (g;iufd;ifjldfrfyif;if;iyf1).pptx
PPTX
Group # 4hjlgdlgdldkhjfdldykyhdyirey.pptx
PPTX
TAHREEM KOUSAR Operating System ASSIGNMENT.pptx
PPTX
Bad News Messages.p yfthfdyyyhhuiuuugptx
PPTX
principle of manangement.p. ptx
PPTX
Group 07 ( Work Group ). pptx.
PPTX
OPERATING SYSTEM (1008)BY. .pptx.
PPTX
Assignment Operating System Rao Hamza.pptx
PPTX
wajeeha sajjad pptx 1013. .pptx
PPTX
coafinal1-copy-150430204758-conversion-gate01.pptx
PPT
clock. ppt
PPT
clock (1) .ppt
PPTX
sidra_ayoub[1] .pptx
PPTX
principle of manangement .pptx
PPTX
JAWERIA ZAKI ASSIGNMENT .pptx
PPTX
Faran Touqeer, Roll no 1042, Operating system Assignment.pptx
Tahreem_Kousar_EconomicsSSSSSSSS_file[1].pptx
academic_writingGGGGGGGGGGGGGGGGGGGG.ppt
POM-.hffffffffffffffffiiiiiiiiiiiiiiiiiiiiipptx
presentationnnnnnnnnnnnnnnnnnnnnnnnn.pptx
Group no 5 (g;iufd;ifjldfrfyif;if;iyf1).pptx
Group # 4hjlgdlgdldkhjfdldykyhdyirey.pptx
TAHREEM KOUSAR Operating System ASSIGNMENT.pptx
Bad News Messages.p yfthfdyyyhhuiuuugptx
principle of manangement.p. ptx
Group 07 ( Work Group ). pptx.
OPERATING SYSTEM (1008)BY. .pptx.
Assignment Operating System Rao Hamza.pptx
wajeeha sajjad pptx 1013. .pptx
coafinal1-copy-150430204758-conversion-gate01.pptx
clock. ppt
clock (1) .ppt
sidra_ayoub[1] .pptx
principle of manangement .pptx
JAWERIA ZAKI ASSIGNMENT .pptx
Faran Touqeer, Roll no 1042, Operating system Assignment.pptx
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Structure & Organelles in detailed.
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Types and Its function , kingdom of life
PDF
Pre independence Education in Inndia.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
human mycosis Human fungal infections are called human mycosis..pptx
RMMM.pdf make it easy to upload and study
Cell Structure & Organelles in detailed.
Module 4: Burden of Disease Tutorial Slides S2 2025
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Renaissance Architecture: A Journey from Faith to Humanism
TR - Agricultural Crops Production NC III.pdf
O7-L3 Supply Chain Operations - ICLT Program
Anesthesia in Laparoscopic Surgery in India
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
Pharma ospi slides which help in ospi learning
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

41_P17CSC104_20201209054563635172951.ppt

  • 1. A. Frank - P. Weisberg Operating Systems Inter-Process Communication (IPC)
  • 2. 2 A. Frank - P. Weisberg Introduction to Concurrency • Classical Problems of Concurrency • Critical Regions • Monitors • Inter-Process Communication (IPC) • Communications in Client-Server Systems
  • 3. 3 A. Frank - P. Weisberg Inter-Process Communication (IPC) • Mechanism for processes to communicate and to synchronize their actions. • Message system – processes communicate with each other without resorting to shared variables. • We have at least two primitives: – send(destination, message) or send(message) – receive(source, message) or receive(message) • Message size is fixed or variable.
  • 5. 5 A. Frank - P. Weisberg Message format • Consists of header and body of message. • In Unix: no ID, only message type. • Control info: – what to do if run out of buffer space. – sequence numbers. – priority. • Queuing discipline: usually FIFO but can also include priorities.
  • 6. 6 A. Frank - P. Weisberg Messages and Pipes Compared
  • 7. 7 A. Frank - P. Weisberg Message Passing • Message passing is a general method used for IPC: – for processes inside the same computer. – for processes in a networked/distributed system. • In both cases, the process may or may not be blocked while sending a message or attempting to receive a message.
  • 8. 8 A. Frank - P. Weisberg Synchronization in message passing (1) • Message passing may be blocking or non-blocking. • Blocking is considered synchronous – Blocking send has the sender block until the message is received – Blocking receive has the receiver block until a message is available • Non-blocking is considered asynchronous – Non-blocking send has the sender send the message and continue – Non-blocking receive has the receiver receive a valid message or null
  • 9. 9 A. Frank - P. Weisberg Synchronization in message passing (2) • For the sender: it is more natural not to be blocked after issuing send: – can send several messages to multiple destinations. – but sender usually expect acknowledgment of message receipt (in case receiver fails). • For the receiver: it is more natural to be blocked after issuing receive: – the receiver usually needs the information before proceeding. – but could be blocked indefinitely if sender process fails before send.
  • 10. 10 A. Frank - P. Weisberg Synchronization in message passing (3) • Hence other possibilities are sometimes offered. • Example: blocking send, blocking receive: – both are blocked until the message is received. – occurs when the communication link is unbuffered (no message queue). – provides tight synchronization (rendezvous).
  • 11. 11 • There are really 3 combinations here that make sense: 1. Blocking send, Blocking receive 2. Nonblocking send, Nonblocking receive 3. Nonblocking send, Blocking receive – most popular – example: • Server process that provides services/resources to other processes. It will need the expected information before proceeding. Synchronization in message passing (4)
  • 12. 12 A. Frank - P. Weisberg IPC Requirements • If P and Q wish to communicate, they need to: – establish communication link between them. – exchange messages via send/receive. • Implementation of communication link: – physical (e.g., shared memory, hardware bus) – logical (e.g., logical properties)
  • 13. 13 A. Frank - P. Weisberg Implementation Questions • 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?
  • 14. 14 A. Frank - P. Weisberg Link Capacity – 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.
  • 15. 15 A. Frank - P. Weisberg Direct/Indirect Communication • Direct communication: – when a specific process identifier is used for source/destination. – but it might be impossible to specify the source ahead of time (e.g., a print server). • Indirect communication (more convenient): – messages are sent to a shared mailbox which consists of a queue of messages. – senders place messages in the mailbox, receivers pick them up.
  • 16. 16 A. Frank - P. Weisberg Direct Communication • Processes must name each other explicitly: – send(P, message) – send a message to process P – receive(Q, message) – receive a message from 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.
  • 17. 17 A. Frank - P. Weisberg Indirect Communication (1) • 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.
  • 18. 18 A. Frank - P. Weisberg Indirect Communication (2) • Operations – create a new mailbox – 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.
  • 19. 19 A. Frank - P. Weisberg Indirect Communication (3) • Mailbox sharing – P1, P2, and P3 share mailbox A. – P1, sends; P2 and P3 receive. – Who gets the message? • Possible 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.
  • 20. 20 Mailboxes and Ports • A mailbox can be private to one sender/receiver pair. • The same mailbox can be shared among several senders and receivers: – the OS may then allow the use of message types (for selection). • Port: is a mailbox associated with one receiver and multiple senders – used for client/server applications: the receiver is the server.
  • 21. 21 A. Frank - P. Weisberg Ownership of ports and mailboxes • A port is usually own and created by the receiving process. • The port is destroyed when the receiver terminates. • The OS creates a mailbox on behalf of a process (which becomes the owner). • The mailbox is destroyed at the owner’s request or when the owner terminates.
  • 22. 22 A. Frank - P. Weisberg Mutual Exclusion – Message Passing • create a mailbox mutex shared by n processes. • send() is non-blocking. • receive() blocks when mutex is empty. • Initialization: send(mutex, “go”); • The first Pi who executes receive() will enter CS. Others will be blocked until Pi resends msg. Process Pi: var msg: message; repeat receive(mutex,msg); CS send(mutex,msg); RS forever
  • 23. 23 A. Frank - P. Weisberg Bounded-Buffer – Message Passing • The producer place items (inside messages) in the mailbox mayconsume. • mayconsume acts as our buffer: consumer can consume item when at least one message present. • Mailbox mayproduce is filled initially with k null messages (k= buffer size). • The size of mayproduce shrinks with each production and grows with each consumption. • Solution can support multiple producers/consumers.
  • 24. 24 A. Frank - P. Weisberg Bounded-Buffer – Message Passing Producer: var pmsg: message; repeat receive(mayproduce, pmsg); pmsg := produce(); send(mayconsume, pmsg); forever Consumer: var cmsg: message; repeat receive(mayconsume, cmsg); consume(cmsg); send(mayproduce, null); forever
  • 25. 25 A. Frank - P. Weisberg P/C Problem with Message Passing (1)
  • 26. 26 A. Frank - P. Weisberg P/C Problem with Message Passing (2)
  • 27. 27 A. Frank - P. Weisberg Examples of IPC Systems – POSIX • POSIX Shared Memory example • Process first creates shared memory segment segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR); • Process wanting access to that shared memory must attach to it shared_memory = (char *) shmat(segment_id, NULL, 0); • Now the process could write to the shared memory sprintf(shared_memory, "Writing to shared memory"); • When done a process can detach the shared memory from its address space shmdt(shared_memory); • Now process can remove the shared memory segment shmdt(shared_id, IPC_RMID, NULL);
  • 28. 28 A. Frank - P. Weisberg Examples of IPC Systems – Mach • Mach communication is message based: – Even system calls are messages. – Each task gets two mailboxes at creation: Kernel and Notify. – Only three system calls needed for message transfer: msg_send(), msg_receive(), msg_rpc() – Mailboxes needed for communication, created via port_allocate()
  • 29. 29 A. Frank - P. Weisberg Examples of IPC Systems – Windows XP • Message-passing centric via LPC facility: – Only works between processes on the same system. – Uses ports (like mailboxes) to establish and maintain communication channels. – Communication works as follows: • The client opens a handle to the subsystem’s connection port object. • The client sends a connection request. • The server creates two private communication ports and returns the handle to one of them to the client. • The client and server use the corresponding port handle to send messages or callbacks and to listen for replies.
  • 30. 30 A. Frank - P. Weisberg Local Procedure Calls in Windows XP
  • 31. 31 A. Frank - P. Weisberg Communications in Client-Server Systems • There are various mechanisms: 1. Pipes 2. Sockets (Internet) 3. Remote Procedure Calls (RPCs) 4. Remote Method Invocation (RMI, Java)
  • 32. 32 Pipes • Acts as a conduit allowing two processes to communicate. • Some issues: • Is communication unidirectional or bidirectional? • In the case of two-way communication, is it half or full-duplex? • Must there exist a relationship (i.e., parent-child) between the communicating processes? • Can the pipes be used over a network?
  • 33. 33 Ordinary Pipes • Ordinary Pipes allow communication in standard producer-consumer style. • Producer writes to one end (the write-end of the pipe). • Consumer reads from the other end (the read- end of the pipe). • Ordinary pipes are therefore unidirectional. • Require parent-child relationship between communicating processes.
  • 35. 35 Named Pipes • Named Pipes are more powerful than ordinary pipes. • Communication is bidirectional. • No parent-child relationship is necessary between the communicating processes. • Several processes can use the named pipe for communication. • Provided on both UNIX and Windows systems.
  • 36. 36 A. Frank - P. Weisberg 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.
  • 37. 37 A. Frank - P. Weisberg Socket Communication
  • 38. 38 A. Frank - P. Weisberg Remote Procedure Calls (RPCs) • RPC abstracts a Local Procedure Call (LPC) between processes on a networked system. • Stubs – client-side proxy for the actual procedure existing on the server. • The client-side stub locates the server and marshals the parameters. • The server-side stub/skeleton receives this message, unpacks the marshaled parameters, and performs the procedure on the server. • Vice versa happens on the opposite direction.
  • 39. 39 Remote Procedure Call Mechanism A. Frank - P. Weisberg
  • 40. 40 A. Frank - P. Weisberg Execution of RPC
  • 41. 41 A. Frank - P. Weisberg Remote Method Invocation • Remote Method Invocation (RMI) is a Java mechanism similar to RPCs. • RMI allows a Java program on one machine to invoke a method on a remote object.
  • 42. 42 A. Frank - P. Weisberg ( Un ) Marshalling Parameters