Interprocess Communications

1

Interprocess Communications
-

-

-

Exchange of data between two or more separate, independent processes/threads. Operating systems provide facilities/resources for interprocess communications (IPC), such as message queues, semaphores, and shared memory. Distributed computing systems make use of these facilities/resources to provide application programming interface (API) which allows IPC to be programmed at a higher level of abstraction. (e.g., send and receive) Distributed computing requires information to be exchanged among independent processes.

2

IPC – unicast and multicast
In distributed computing, two or more processes engage in IPC using a protocol agreed upon by the processes. A process may be a sender at some points during a protocol, a receiver at other points. When communication is from one process to a single other process, the IPC is said to be a unicast, e.g., Socket communication. When communication is from one process to a group of processes, the IPC is said to be a multicast, e.g., Publish/Subscribe Message model, a topic that we will explore in a later chapter.

3

Multicast P2 P2 m P3 . m m P4 m P1 P1 unicast 4 multicast .Unicast vs...

Interprocess Communications in Distributed Computing Process 1 data Process 2 sender 5 receiver .

6 . for connection-oriented communication.Operations provided in an archetypal Interprocess Communications API • • • • Receive ( [sender]. message storage object) Connect (sender address. message) Disconnect (connection identifier). Send ( [receiver]. receiver address). for connection-oriented communication.

S2. C2.Interprocess Communication in basic HTTP Web server S1 a proce ss an ope ration data flow S2 HTTP re que st HTTP re sponse C1 C2 C3 C4 S3 S4 ope rations: S1: acce pt conne ction S2: re ce ive (re que st) S3: se nd (re sponse ) S3: disconne ct s4 C 1: make conne ction C 2: se nd (re que st) C 3: re ce ive (re sponse ) C 4: disconne ct Web browser 7 Processing order: C1. C4. S1. S3. C3. S4 .

In practice. then the other receives until all data has been sent and received. the synchronization requires system support. the send operation starts before the receive operation commences. 8 . Ideally.Event Synchronization Interprocess communication may require that the two processes synchronize their operations: one side sends.

Asynchronous Communication The IPC operations may provide the synchronization necessary using blocking. Alternatively. A blocking operation issued by a process will block further processing of the process until the operation is fulfilled. and may optionally be notified by the system when the operation is fulfilled. Instead.Synchronous vs. the process is free to proceed with its processing. IPC operations may be asynchronous or nonblocking. 9 . An asynchronous operation issued by a process will not block further processing of the process.

Synchronous send and receive process 1 running on host 1 process 2 running on host 2 Event Diagram blocking receive starts blocking send starts an operation execution flow blocking send returns acknowledgement of data received provided by the IPC facility blocking receive ends suspended period Synchronous Send and Receive Client Sender Server Receiver 10 .

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 Sender Server Receiver 11 .

1 Process 2 Process 1 blocking send issued nonblocking receive issued execution flow suspended period transparent acknowledgement provided by the IPC facility Synchronous Send and Asynchronous Receive Scenario A 12 Data from P1 was received by P2 before issuing a non-blocking receive op in P2 .Synchronous send and Async. Receive .

Synchronous send and Async. Receive .2 Process 2 Process 1 nonblocking receive issued and returned immediately blocking send issued indefinite blocking execution flow suspended period Process 2 Process 1 Synchronous Send and Asynchronous Receive Scenario B 13 Data from P1 arrived to P2 after P2 issued a non-blocking receive op .

3 Process 2 Process 1 nonblocking receive issued and returned immediately blocking send issued transparent acknowledgement provided by the IPC facility process is notified of the arrival of data execution flow suspended period Synchronous Send and Asynchronous Receive Scenario C 14 Data from P1 arrived to P2 before P2 issues a non-blocking receive op.Synchronous send and Async. P2 is notified of the arrival of data . Receive .

Asynchronous send and Asynchronous receive Process 2 Process 1 nonblocking receive issued and returned immediately blocking send issued process is notified of the arrival of data execution flow suspended period Asynchronous Send and Asynchronous Receive Scenario C 15 Does P1 need an acknowledgement from P2? .

Event diagram Process B Process A time request 1 response 1 request 2 interprocess communication execution flow process blocked response2 Event diagram for a protocol 16 Synchronous send and receive .

17 P1 is waiting for P2’s data. and timeouts Blocking operations issued in the wrong sequence can cause deadlocks. timeout can be used to detect deadlocks. P2 is waiting for P1’s data. Alternatively. Deadlocks should be avoided. .Blocking. 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. deadlock.

If only blocking operation is provided for send and/or receive. 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 18 .Using threads for asynchronous IPC When using an IPC programming interface. it is important to note whether the operations are synchronous or asynchronous. then it is the programmer’s responsibility to using child processes or threads if asynchronous operations are desired.

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

Indefinite blocking due to a deadlock Process 1 Process 2 "receive from process 2" issued. process 2 blocked pending data from process 1. . an ope ration proce ss e xe cuting proce ss blocke d "receive from process 1" issued. process 1 blocked pending data from process 2. 20 P1 is waiting for P2’s data. P2 is waiting for P1’s data.

Because different computers may have different internal storage format for the same data type.Data Representation Data transmitted on the network is a binary stream.1 (Abstract Syntax Notation One) XML (Extensible Markup Language) 21 . and (ii) converting the data to an external representation. Data marshalling is the process of (I) flattening a data structure. An interprocess communication system may provide the capability to allow data representation to be imposed on the raw data. Some well known external data representation schemes are: Sun XDR (External Data Representation) ASN. an external representation of data may be necessary—standard format.

1(Abstract Syntax Notation) Sun XDR(External Data Representation) network data encoding standard 22 .Data Encoding Protocols level of abstraction data encoding schemes application specific data encoding language general data encoding language Sample Standards XML:(Extensible Markup Language) ASN.

com</from> <from> </from> <subject>XML Is Really Cool</subject> <subject> </subject> <text> How many ways is XML cool? Let me count the ways. rather than how to display it.com</to> </to> <to> <from>me@myAddress.Sample XML file http://java. XML tags tell you what the data means.. Example: <message> <to>you@yourAddress. means.com/xml/docs/tutorial/overview/1_xml. 23 </message> .. Unlike HTML. HTML. </text> textXML is a text-based markup language that is fast becoming the standard for data interchange on the Web.sun.html#intro XML has syntax analogous to HTML.

5 1. unmarshalling "This is a test.3 -1. .." host A 1.2 24 host B ..5 7.3 1. External to internal representation and vice versa is not required . -1..2 7." 1. rebuild data structures.Data Marshalling "This is a test.if the two sides are of the same host type. converting data to external (network) representation marshalling 110011 ..if the two sides negotiates at connection. 10000100 . flattening of structured data items 2. convert data to internal representation 2.

The OSI (Open System Interconnection ) Sevenlayer network architecture application layer application layer presentation layer presentation layer session layer Message session layer transport layer Segment Datagram Frame 0/1 transport layer network layer network layer data link layer data link layer physical layer physical layer 25 .

Such text-based. are text-based. exchanged is a stream of characters. Exchanging data in text has the additional advantage that the data can be easily parsed in a program and displayed for human perusal. 26 . HTTP. text.Text-based protocols Data marshalling is at its simplest when the data characters. Many popular network protocols. Transfer Protocol). Hence it is a popular practice for protocols to exchange requests and character-strings. responses in the form of character-strings. protocols are said to be text-based. or text. and SMTP (Simple Mail text-based. Transfer Protocol). including FTP (File HTTP.

Event diagram Process 2 Process 1 time request 1 response 1 request 2 interprocess communication execution flow process blocked response2 Event diagram for a protocol 27 .

an optional header . .<command> <document adddress> <HTTP version> .Event Diagram for a HTTP session web server web browser request request is a message in 3 parts: .optional data for CGI data using post method response is a message consisting of 3 parts: .header information.the document itself. which may span several lines.a status line of the format <protocol><status code><description> . response 28 .

Sequence Diagram Process A Process B request 1 response 1 request 2 interprocess communication response 2 29 .

Sequence diagram for a HTTP session Process A Process B request 1 response 1 request 2 interprocess communication response 2 30 .

The specification of a protocol should include (i) the sequence of data exchange. which can be described using a time event diagram. two processes perform interprocess communication in a mutually agreed upon protocol.Protocol In a distributed application. 31 . (ii) the format of the data exchange at each step.

which replies with a response. 32 .HTTP: A sample protocol The HyperText Transfer Protocol is a protocol for a process (the browser) to obtain a document from a web server process. It is a request/response protocol: a browser sends a request to a web server process.

We will explore HTTP in details later this quarter.optional data for CGI data using post method response is a message consisting of 3 parts: . response 33 .a status line of the format <protocol><status code><description> .the document itself.<command> <document adddress> <HTTP version> .The Basic HTTP protocol web server web browser request request is a message in 3 parts: .an optional header . . which may span several lines.header information.

edu 80 Trying 129.csc.241.65. Escape character is '^]'.0 HTTP/1. 10 Oct 2000 16:51:54 GMT ETag: "1dd1e-e27-39e3492a" Accept-Ranges: bytes Content-Length: 3623 Connection: close Content-Type: text/html <HTML> <HEAD> <TITLE> Mei-Ling L. GET /~mliu/ HTTP/1.calpoly.3.1 200 OK Date: Wed. Liu's Home Page </TITLE> </HEAD> <BODY bgcolor=#ffffff> … Request HTTP R equest HTTP response status line HTTP response header document content 34 .9 (Unix) ApacheJServ/1.csc..A sample HTTP session Script started on Tue Oct 10 21:49:28 2000 9:49pm telnet www. Connected to tiedye2-srv.20.0 Last-Modified: Tue. 11 Oct 2000 04:51:18 GMT Server: Apache/1.edu..calpoly.

gmu.HTTP Session 1.gmu. Type in a GET HTTP request: GET /~yhwang1/ HTTP/1. you send this minimal but complete GET request to HTTP server 3.1 Host: ise. Telnet to your favorite Web server: unix> telnet ise. See what you have in response message sent by HTTP server! 35 .gmu.edu Type above commands and hit carriage return twice.edu 80 Opens a TCP connection to port 80 at ise.edu. (default HTTP server port) 2.

Winsock serial/parallel communication 36 UNIX Socket: http://www.ecst.html . Java RMI Unix socket API.IPC paradigms and implementations Paradigms of IPC of different levels of abstraction have evolved. level of abstraction IPC paradigms remote procedure/method socket API data transmission Example IPC Implementations Remote Procedure Call (RPC).csuchico.edu/~beej/guide/ipc/usock. with corresponding implementations.

Sign up to vote on this title
UsefulNot useful