chapter 9 message passing copyright © 2008. operating systems, by dhananjay dhamdhere copyright ©...
TRANSCRIPT
Chapter 9
Message PassingCopyright © 2008
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.2Operating Systems, by Dhananjay Dhamdhere 2
Introduction
• Overview of Message Passing• Implementing Message Passing• Mailboxes• Higher-Level Protocols Using Message Passing• Case Studies in Message Passing
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.3Operating Systems, by Dhananjay Dhamdhere 3
Overview of Message Passing
• Message passing is one way in which processes interact with one another
• Processes may exist in the same computer or in different computers connected to a network
• Uses of message passing:– Client-server paradigm
– Backbone of higher-level communication protocols
– Parallel and distributed programs
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.4Operating Systems, by Dhananjay Dhamdhere 4
Overview of Message Passing (continued)
• Two important issues in message passing are:– Naming of processes
• Names may be explicitly indicated or deduced by the kernel in some manner
– Delivery of messages• Whether sender should be blocked until delivery• What the order is in which messages are delivered to a
destination process• How exceptional conditions are handled
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.5Operating Systems, by Dhananjay Dhamdhere 5
Direct and Indirect Naming
• In direct naming, sender and receiver processes mention each other’s name
– In symmetric naming, both sender and receiver processes specify each other’s name
– In asymmetric naming, receiver does not name process from which it wishes to receive a message; kernel gives it a message sent to it by some process
• In indirect naming, processes do not mention each other’s name in send and receive statements
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.6Operating Systems, by Dhananjay Dhamdhere 6
Blocking and Nonblocking Sends
• A blocking send blocks sender process until message is delivered to destination process– Synchronous message passing
– Simplifies design of concurrent processes
• A nonblocking send call permits sender to continue its operation after send call– Asynchronous message passing
– Enhances concurrency between sender and receiver
• In both cases, receive is typically blocking• Kernel performs message buffering pending delivery
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.7Operating Systems, by Dhananjay Dhamdhere 7
Exceptional Conditions in Message Passing
• To facilitate handling exceptional conditions, send and receive take two additional parameters:– Flags indicate how exceptions should be handled
– status_area is for storing code concerning outcome
• Some exceptional conditions:1. Destination process mentioned in send doesn’t exist
2. Source process does not exist (symmetric naming)
3. send cannot be processed (out of buffer memory)
4. No message exists for process when it makes receive
5. A set of processes become deadlocked when one is blocked on a receive
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.8Operating Systems, by Dhananjay Dhamdhere 8
Implementing Message Passing
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.9Operating Systems, by Dhananjay Dhamdhere 9
Delivery of Interprocess Messages
• Remember that:– An event control block (ECB) has three fields:
• Description of the anticipated event• Id of the process that awaits the event• An ECB pointer for forming ECB lists
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.10Operating Systems, by Dhananjay Dhamdhere 10
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.11Operating Systems, by Dhananjay Dhamdhere 11
Mailboxes
• Mailbox: repository for interprocess messages– Has a unique name
– Owner is typically the process that created it
• Indirect naming– Only owner process can receive messages
– Any process that knows name of a mailbox can send messages to it
• Kernel may provide fixed set of mailbox names, or it may permit user processes to assign the names– Varying levels of confidentiality
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.12Operating Systems, by Dhananjay Dhamdhere 12
Mailboxes (continued)
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.13Operating Systems, by Dhananjay Dhamdhere 13
Mailboxes (continued)
• Kernel may require a process to explicitly “connect” to a mailbox before starting to use it, and to “disconnect” when it finishes using it– May permit owner to destroy it, transfer ownership, etc.
• Use of a mailbox has following advantages:– Anonymity of receiver
– Classification of messages • Through use of separate mailboxes for different classes
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.14Operating Systems, by Dhananjay Dhamdhere 14
Example: Use of Mailboxes
• An airline reservation system:– A set of booking processes
– Server wishes to process cancellations before bookings and queries after both of them
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.15Operating Systems, by Dhananjay Dhamdhere 15
Higher-Level Protocols Using Message Passing
• Several protocols use message passing paradigm to provide diverse services:– Simple mail transfer protocol (SMTP) delivers electronic
– Remote procedure call (RPC) is a programming language facility for distributed computing
• Invokes a part of a program that is located on a different computer
– Parallel virtual machine (PVM) and message passing interface (MPI) are message passing standards for parallel programming
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.16Operating Systems, by Dhananjay Dhamdhere 16
The Simple Mail Transfer Protocol (SMTP)
• SMTP is used to deliver electronic mail to one or more users reliably and efficiently– Uses asymmetric naming– Can deliver mail across a number of interprocess
communication environments (IPCEs )– It is an applications layer protocol: uses TCP / IP
• SMTP consists of several simple commands:– MAIL, RCPT, DATA
• Typically used with a protocol that provides a mailbox– Internet Message Access Protocol (IMAP)– Post Office Protocol (POP)
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.17Operating Systems, by Dhananjay Dhamdhere 17
Remote Procedure Calls
• Remote procedure call (RPC): used to invoke a part of a program located in a different computer– Semantics resemble those of a procedure call
• call <proc_id> (<message>);
– <message> is a list of parameters• Stubs perform marshaling of parameters and convert them
to/from machine independent representations
– SunRPC and OSF/DCE standards, Java RMI
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.18Operating Systems, by Dhananjay Dhamdhere 18
Message Passing Standards for Parallel Programming
• Parallel program: set of tasks that can be performed in parallel– Executed on a heterogeneous set of computers or on a
massively parallel processor (MPP)
• Parallel virtual machine (PVM) and message passing interface (MPI) are standards used in coding message passing libraries; provide:– Point-to-point communication between processes
– Barrier synchronization between processes
– Global operations for scattering (gathering) disjoint portions of data in a message to (from) different processes
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.19Operating Systems, by Dhananjay Dhamdhere 19
Case Studies in Message Passing
• Message Passing in Unix• Message Passing in Windows
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.20Operating Systems, by Dhananjay Dhamdhere 20
Message Passing in Unix
• Three interprocess communication facilities:– Pipe:
• Data transfer facility• Unnamed pipes can be used only by processes that belong
to the same process tree
– Message queue: analogous to a mailbox• Used by processes within “Unix system domain”• Access permissions indicate which processes can send or
receive messages
– Socket: one end of a communication path• Can be used for setting up communication paths between
processes within the Unix system domain and within certain Internet domains
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.21Operating Systems, by Dhananjay Dhamdhere 21
Message Passing in Unix (continued)
• One common feature: processes can communicate without knowing each other’s identities
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.22Operating Systems, by Dhananjay Dhamdhere 22
Message Passing in Unix: Pipes
• FIFO mechanism for data transfer between processes called reader and writer processes
• Usually implemented in file system– But, data put into a pipe can be read only once
• Removed from pipe when it is read by a process
• Two kinds of pipes: named and unnamed– Created through the system call pipe
– A named pipe has an entry in a directory
• Like a file, but size is limited and kernel treats it as a queue
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.23Operating Systems, by Dhananjay Dhamdhere 23
Message Passing in Unix: Message Queues
• Analogous to a mailbox• Created and owned by one process
– Creator specifies access permissions for send/receive
• Size specified at the time of its creation
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.24Operating Systems, by Dhananjay Dhamdhere 24
Message Passing in Unix: Sockets
• A socket is one end of a communication path– Can be used for interprocess communication within the
Unix system domain and in the Internet domain
• Server can set up communication paths with many clients simultaneously– Typically, after connect call, server forks a new process
to handle the new connection• Leaves original socket created by server process free to
accept more connections
• Indirect naming: address (domain) used instead of process ids
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.25Operating Systems, by Dhananjay Dhamdhere 25
Message Passing in Windows
• Named pipes: reliable bidirectional byte/message mode communication between server and clients– Implemented through the file system interface
– Synchronous and asynchronous message passing
• Local Procedure Call (LPC) facility performs message passing between processes in same host– Choice of three methods of message passing
• Windows socket (Winsock)– Integrated with Windows message passing
• RPC: Synchronous and asynchronous
Operating Systems, by Dhananjay Dhamdhere Copyright © 2008 9.26Operating Systems, by Dhananjay Dhamdhere 26
Summary
• Message passing paradigm realizes exchange of information among processes without using shared memory
• Useful in: microkernel-based OSs, client–server computing, higher-level communication protocols, and parallel or distributed programs
• Sender/receiver naming: symmetric, asymmetric, indirect (mailbox)
• Message passing is employed in higher-level protocols such as SMTP, RPC, PVM, and MPI