Introduction to Interprocess Communication Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 1
The rocess Text Data Heap Stack C AddNumbers: std clc pushf.top i = 3,14 e = 2,71 y = hi x = 5 SUB1 MAIN rocess Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 2
rocess Control Block Text Data Heap Stack C AddNumbers: std clc pushf.top i = 3,14 e = 2,71 y = hi x = 5 SUB1 MAIN rocess process state process number process counter REGISTERS memory limits pointers Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 3
Interprocess Communication rocess 2 sort (4,5,2,7) merge (2,4,5,7) rocess 1 sort (11,9,14) merge (9,11,14) rocess 3 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 4
Interprocess Communication rocess 2 Why do processes sort (4,5,2,7) rocess 1 communicate? Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 5
Interprocess Communication rocess 2 sort (4,5,2,7) rocess 1 Why do processes communicate? Information sharing - e.g., concurrent access to files; Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 5
Interprocess Communication rocess 2 sort (4,5,2,7) rocess 1 Why do processes communicate? Information sharing - e.g., concurrent access to files; Computation speed - same aim divided in multiple tasks; Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 5
Interprocess Communication rocess 2 sort (4,5,2,7) rocess 1 Why do processes communicate? Information sharing - e.g., concurrent access to files; Computation speed - same aim divided in multiple tasks; Modularity - reuse processes; Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 5
Interprocess Communication rocess 2 sort (4,5,2,7) rocess 1 Why do processes communicate? Information sharing - e.g., concurrent access to files; Computation speed - same aim divided in multiple tasks; Modularity - reuse processes; Convenience - multitasking. Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 5
Interprocess Communication rocess 2 How do processes sort (4,5,2,7) rocess 1 communicate? Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 6
Interprocess Communication rocess 2 sort (4,5,2,7) rocess 1 How do processes communicate? Shared Memory V Message assing Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 6
Shared Memory v Message assing Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 7
Shared Memory quick (and dirty); shared segment of memory; hack-ish, processes bypass memory protections of the OS. Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 8
Message assing model scales from local to remote processes; needs a communication link Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 9
Message assing: the communication link Two concerns of implementation: hysical Logical Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 10
Message assing: the communication link Two concerns of implementation: hysical Logical Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 10
Logical Implementation Direct communication send(, msg) receive(, msg) Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 11
Logical Implementation Direct communication send(, msg) receive(id, msg) (asymmetric) Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 12
Logical Implementation Indirect communication send(a, msg) A receive(a, msg) Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 13
Logical Implementation Indirect communication send(a, msg) receive(a, msg) R A receive(a, msg) send(a, msg) S Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 14
Logical Implementation Synchronous communication Blocking send 1 request 2 ack receive 3 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 15
Logical Implementation Synchronous communication Nonblocking send 1 send 2 2 receive Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 16
Logical Implementation Synchronous communication Blocking receive 1 send receive 2 3 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 17
Logical Implementation Synchronous communication Nonblocking receive 1 send receive 2 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 18
Logical Implementation Buffering Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Logical Implementation Zero Capacity Buffering 0 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Logical Implementation Zero Capacity Buffering Blocking 0 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Logical Implementation Buffering Zero Capacity Bounded Capacity Blocking 0 0 1 2 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Logical Implementation Buffering Zero Capacity Bounded Capacity Blocking Blocking 0 0 1 2 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Logical Implementation Buffering Zero Capacity Bounded Capacity Unbounded Capacity Blocking Blocking 0 0 1 2 0 1 Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 19
Remote Invocation Request-reply protocols send( sum,x=17,y=25 ); // wait receive( res ); Low-level e.g., sockets receive( req ); switch ( req[0, 3] ){ case sum : res = sum( req ); break; case sub : } res = sub( req ); break; send( res ); Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 20
Remote Invocation Sockets try { /* make connection to server socket */ Socket toserver = new Socket( 127.0.0.1, 6013 ); rintwriter pout = new rintwriter( toserver.getoutputstream(), true ); /* write the request to the server */ pout.println( sum,x=17,y=25 ); toserver.close(); /* accept response connection from server */ tome = new ServerSocket( 6012 ); tome.accept(); InputStream in = tome.getinputstream(); BufferedReader bin = new BufferedReader( new InputStreamReader( in ) ); /* read the data from the socket */ String response = bin.readline() /* close the socket connection */ tome.close(); } catch (IOException ioe) { System.err.println(ioe) }; Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 21
Remote Invocation Request-reply protocols low-level support for requesting the execution of a remote operation; support for RC and RMI, discussed below Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 22
Remote Invocation Request-reply protocols low-level support for requesting the execution of a remote operation (HTT, FT, etc. are Request-reply protocols); support for RC and RMI (next); Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 23
Remote Invocation Remote rocedure Calls Communication library Client Stub rocedure Server Stub rocedure res = sum@( 17, 25 ); Low-level e.g., Sockets ossibly over App. level rotocol sum( int x, int y ){ return x + y; } Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 24
Remote Invocation Remote rocedure Calls programming with interfaces (recall, an interface specifies the procedures and the variables available to others); Separation of concerns: interfaces remain the same but their implementation may change; High degree of heterogeneity. Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 25
Remote Invocation Remote Method Invocation Communication module Remote Reference Module Remote Reference Module proxy res =.sum( 17, 25 ); sum( int x, int y ){ return x + y; } Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 26
Remote Invocation Remote Method Invocation Full object-oriented paradigm for programming distributed systems; Strictly Java. Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 27
Remote Invocation Remote rocedure Calls Remote Method Invocation Request-reply rotocols Saverio Giallorenzo sgiallor@cs.unibo.it DISI@Unibo 28