You are on page 1of 36

Interprocess Communications

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.

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.

Unicast vs. Multicast


P2 P2 m P3

...
m m

P4

P1

P1

unicast
4

multicast

Interprocess Communications in Distributed Computing

Process 1 data

Process 2

sender
5

receiver

Operations provided in an archetypal Interprocess Communications API


Receive ( [sender], message storage object) Connect (sender address, receiver address), for connection-oriented communication. Send ( [receiver], message) Disconnect (connection identifier), for connection-oriented communication.

Interprocess Communication in basic HTTP


Web server
S1 a proce ss an ope ration ata flow S2 HTTP re que st HTTP re sponse C1 C2 C3 C4 3 4 ope rations: S1: acce pt conne ction S2: re ce ive (re que st) S3: se n (re sponse ) S3: isconne ct s4 C 1: make conne ction C 2: se n (re que st) C 3: re ce ive (re sponse ) C 4: isconne ct

Web browser

Processing order: C1, S1, C2, S2, S3, C3, C4, S4

Event Synchronization


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

Synchronous vs. Asynchronous Communication




The IPC operations may provide the synchronization necessary using blocking. A blocking operation issued by a process ill block further processing of the process until the operation is fulfilled. Alternatively, IPC operations may be asynchronous or nonblocking. An asynchronous operation issued by a process ill not block further processing of the process. Instead, the process is free to proceed ith its processing, and may optionally be notified by the system hen the operation is fulfilled.

Synchronous send and receive


r o c e ss 1 r unni ng o n ho st 1 r o c e ss 2 r unni ng o n ho st 2

Event Diagram

bloc king rec eive s tarts

bloc king s end s tarts

an operation exec ution lo

bloc king s end returns

ac kno ledgem ent o data rec eived provided by the IP C ac ility bloc king rec eive ends

s us pended period

Sync hr o no us Se nd and

e c e i ve

Client Sender

Server Receiver

10

Asynchronous send and synchronous receive


P rocess 2 P rocess 1

Event Diagram
b lo c k in g r e c e iv e s ta r ts

n o n b lo c k in g s e n d o p e r a tio n e x e c u tio n f lo w s u s p e n d e d p e r io d b lo c k in g r e c e iv e r e tu r n s

As ync hr o no us Se nd and Sync hr o no us R e c e i ve

Client Sender

Server Receiver

11

Synchronous send and Async. Receive - 1


P ro cess 2 P ro cess 1

b lo c k in g s e n d is s u e d

tr a n s p a r e n t a c k n o w le d g e m e n t p r o v id e d b y th e I P C f a c ility

n o n b lo c k in g r e c e iv e is s u e d e x e c u tio n f lo w s u s p e n d e d p e r io d

Sync hr o no us Se nd and As ync hr o no us R e c e i ve


S c e n a r io A

12

Data from P1 was received by P2 before issuing a non-blocking receive op in P2

Synchronous send and Async. Receive - 2


P rocess 2 P rocess 1

n o n b lo c k in g r e c e iv e is s u e d a n d r e tu r n e d im m e d ia te ly b lo c k in g s e n d is s u e d

in d e in ite b lo c k in g

e x e c u tio n lo s u s p e n d e d p e r io d

P rocess 2 P rocess 1 Sync hr o no us Se nd and As ync hr o no us R e c e i ve


S c e n a r io B

13

Data rom P1 arrived to P2 after P2 issued a non-blocking receive op

Synchronous send and Async. Receive - 3


P ro cess 2 P ro cess 1

no n b loc k in g rec eive is s u ed an d retu rn ed im m ed iately b lo c kin g s end is s u ed tran s p aren t ac k no w led g em ent p rov id ed b y the IP C fac ility pro c es s is n o tified of th e arriv al of data

ex ec u tio n flo w s u s p en d ed p eriod

Sync hr o no us Se nd and As ync hr o no us R e c e i ve


S ce n a rio C

14

Data from P1 arrived to P2 before P2 issues a non-blocking receive op. P2 is notified of the arrival of data

Asynchronous send and Asynchronous receive


P ro cess 2 P ro cess 1

n o n b lo c k in g r ec eiv e is s u ed an d r etu r n ed im m ed iately b lo c k in g s en d is s u ed p r o c es s is n o tif ied o f th e ar r iv al o f d ata

ex ec u tio n f lo w s u s p en d ed p er io d

As yn c h r o n o u s S e n d an d As yn c h r o n o u s R e c e i ve
S ce n a rio C

15

Does P1 need an acknowledgement from P2?

Event diagram
Proce s s Proce s s A tim e

request 1

response 1

request 2 interproc ess c om m unic ation exec ution flow proc ess bloc ked response2

Event di ag ram fo r a pro to co l

16

Synchronous send and receive

Blocking, deadlock, and timeouts


 

Blocking operations issued in the rong se uence can cause deadlocks. Deadlocks should be avoided. Alternatively, timeout can be used to detect deadlocks. Process 1 Process 2
receive rom process 2 issued process 1 blocked pending data rom process 2. received rom process 1 issued process 2 blocked pending data rom process 1.

17

P1 is waiting or P2s data; P2 is waiting or P1s data.

Using threads for asynchronous IPC


 

When using an IPC programming interface, it is important to note hether the operations are synchronous or asynchronous. If only blocking operation is provided for send and/or receive, then it is the programmers responsibility to using child processes or threads if asynchronous operations are desired.
pr o c e s s
m a in t h r e a d

ne

t h r e a d is s u e s a b lo c k in g I P C o p e r a t io n

m a in t h r e a d c o n t in u e s o t h e r p r o c e s s in g

it h

t h r e a d is b lo c k e d

t h r e a d is u n b lo c k e d a t e r t h e o p e r a t io n is

u l ille d

18

Deadlocks and Timeouts




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

19

Indefinite blocking due to a deadlock


Process 1 Process 2

"receive from process 2" issued; process 1 blocked pending data from process 2.
an operation process executing process blocked

"receive from process 1" issued; process 2 blocked pending data from process 1.

20

P1 is waiting for P2s data; P2 is waiting for P1s data.

Data Representation
 

21

Data transmitted on the net ork is a binary stream. An interprocess communication system may provide the capability to allo data representation to be imposed on the ra data. Because different computers may have different internal storage format for the same data type, an external representation of data may be necessarystandard format. Data marshalling is the process of (I) flattening a data structure, and (ii) converting the data to an external representation. Some ell kno n external data representation schemes are: Sun XDR (External Data Representation) ASN.1 (Abstract Syntax Notation One) XML (Extensible Markup Language)

Data Encoding Protocols


lev o astr c n el f b atio

dtaenoin sc em a c d g h es a p tio spcificdtae coin la ga e plica n e a n d g nug gnra dtae coin la ga e e e l a n d g nug

SmleS nad a p ta dr s X L x n leM u Lnug) M:(Ete sib a p a ga e rk

AN (Astra Sn xNta n S .1 b ct yta o tio) SnXR x rnlDtaRp se ta n u D(Ete a a e re n tio)

ntwrkdtae coin sta drd e o a n d g na

22

Sample XML file


http://java.sun.com/xml/docs/tutorial/overvie /1_xml.html#intro


  

XML is a text-based markup language that is fast becoming the standard for data interchange on the Web. XML has syntax analogous to HTML. Unlike HTML, XML tags tell you what the data means, rather than how to display it. Example:
<message>
<to>you@yourAddress.com</to> <from>me@myAddress.com</from> <subject>XML Is Really Cool</subject> <text> How many ways is XML cool? Let me count the ways... </text>

23

</message>

Data Marshalling
"This is a test." host 1.2 7.3 -1.5 1. lattening o structured data items 2. converting data to external (net ork) representation

mars alli g

110011 ... 10000100 ...

mars alli g "This is a test."

1. convert data to internal representation 2. rebuild data structures. External to internal representation and vice versa is not required - i the t o sides are o the same host type; - i the t o sides negotiates at connection.

-1.5 7.3 1.2

24

host B

The OSI (Open System Interconnection ) Sevenlayer net ork architecture


application layer application layer

presentation layer

presentation layer

session layer

Message
session layer

transport layer

Segment Datagram Frame 0/1

transport layer

net ork layer

net ork layer

data link layer

data link layer

physical layer

physical layer

25

Text-based protocols
 

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

26

Event diagram
Proce s s 2 Proce s s 1 tim e reques t 1

res pons e 1

reques t 2 interproc es s c om m unic ation exec ution lo proc es s bloc ked res pons e2

Eve nt di ag r am fo r a r o to c o l

27

Event Diagram for a HTTP session


web server web browser

request

request is a m essage in 3 parts: - <com and> <docum adddress> <H version> m ent TTP - an optional header - optional data or CGI data using post m ethod

response

response is a m essage consisting o 3 parts: - a status line o the orm <protocol><status code><description> at ation, which m span several lines; ay - header in orm - the docum itsel . ent

28

Se uence Diagram
Process Process B

request 1

response 1

request 2 interprocess communication response 2

29

Se uence diagram for a HTTP session


Process Process B

request 1

response 1

request 2 interprocess communication response 2

30

Protocol


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

31

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, which replies with a response.

32

The Basic HTTP protocol


web server web browser

request

request is a message in 3 parts: - command> document adddress> TTP version> - an optional header - optional data for CGI data using post method

response

response is a message consisting of 3 parts: - a status line of the format protocol> status code> description> - header information, which may span several lines; - the document itself. We will explore TTP in details later this quarter.

33

A sample HTTP session


S crip t sta rte d on Tu e O ct 1 0 2 1 : 4 9 : 2 8 2 0 0 0 9 : 4 9 p m te ln e t w w w . csc. ca lp oly. e d u 8 0 Tryin g 1 2 9 . 6 5 . 2 4 1 . 2 0 . . . C on n e cte d to tie d ye 2 -srv. csc. ca lp oly. e d u . E sca p e ch a ra cte r is '^]'. G E T /~ m liu / H TTP/1 . 0 H TTP/1 . 1 2 0 0 O K D a te : W e d , 1 1 O ct 2 0 0 0 0 4 : 5 1 : 1 8 G M T S e rve r: Ap a ch e /1 . 3 . 9 (U n ix) Ap a ch e JS e rv/1 . 0 La st-M od ifie d : Tu e , 1 0 O ct 2 0 0 0 1 6 : 5 1 : 5 4 G M T E Ta g : "1 d d 1 e -e 2 7 -3 9 e 3 4 9 2 a " Acce p t-R a n g e s: b yte s C on te n t-Le n g th : 3 6 2 3 C on n e ction : close C on te n t-Typ e : te xt/h tm l < H TM L> < H E AD > < TITLE > M e i-Lin g L. Liu 's H om e Pa g e < /TITLE > < /H E AD > < BO D Y b g color= # ffffff>

H TTP R equest H T T P re s p o n s e s ta tu s lin e H T T P re s p o n s e h e a d e r

d o cu m e n t co n te n t

34

HTTP Session
1. Telnet to your favorite Web server:
unix> telnet ise.gmu.edu 80 Opens a TCP connection to port 80 at ise.gmu.edu. (default HTTP server port)

2. Type in a GET TTP request:


GET /~yhwang1/ HTTP/1.1 Host: ise.gmu.edu

Type above commands and hit carriage return twice, you send this minimal but complete GET request to HTTP server

3. See what you have in response message sent by TTP server!

35

IPC paradigms and implementations


Paradigms of IPC of different levels of abstraction have evolved, ith corresponding implementations.

level of a stractio

IP ara igm C s rem procedure/m ote ethod socketA I P datatransm ission

amleIP Imlem tatio s C e em Procedure C ( PC Java I ote all ), U socket PI, W nix insock serial/parallel com unication m

36

UNIX Socket: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html

You might also like