Other IPC Mechanism
Introduction
Monitors. Pipes. Message Buffers. Shared Memory.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Monitors
Introduction
One of the shortcoming of semaphores is it allows to perform a restricted set of operations i.e. wait and signal. Monitors are intended to remove this shortcoming. A monitor consists of the shared data, one or more functions to operate on data. Two kinds of methods are there fist kind ensuring the mutual exclusion and other accessing the non-shared data. Each monitor maintains a queue of waiting threads. Monitors support methods like wait, notify, notifyall. Two kinds of monitors Hoare monitor and Java-style monitor.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Unix Pipes
Introduction
Mechanisms like signal, semaphores, monitors are intended to avoid busy waiting or ensure mutual exclusion for competing processes. They don’t allow to transfer data among processes. The Unix Pipe is one of the mechanism to transfer the messages. Interface of unix pipes include methods like pipe, read, write. Open call returns two file descriptors one for reading and other for writing. Pipes allows communication between parent and child process. Named pipes or FIFO for data communication among peer processes. Synchronized semantics of pipes.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Pipes
Pipes in Java : An Example Program
p u b l i c c l a s s T e x t G e n e r a t o r e x t e n d s Thread { p r i v a t e Writer out ; p u b l i c TextGenerator ( Writer o ){ t h i s . out = o ; } p u b l i c void run (){ try { try { f o r ( c h a r c = ’ a ’ ; c<= ’ z ’ ; c++) out . w r i t e ( c ) ; }finally{ out . c l o s e ( ) ; } } catch ( IOException e ){}
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Pipes
Pipes in Java : An Example Program
p u b l i c c l a s s Pipe { p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) t h r o w s I O E x c e p t i o n P i p e d W r i t e r o u t = new P i p e d W r i t e r ( ) ; P i p e d R e a d e r i n = new P i p e d R e a d e r ( o u t ) ; T e x t G e n e r a t o r d a t a = new T e x t G e n e r a t o r ( o u t ) ; data . s t a r t ( ) ; i n t ch ; w h i l e ( ( ch = i n . r e a d ( ) ) ! = 1 ) System . o u t . p r i n t l n ( ( c h a r ) ch ) ; System . o u t . p r i n t l n ( ) ; } }
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Unix Pipes
Limitations
The maximum size of a pipe tends to kept small. Data is unstructured. It is not possible to test whether pipe is empty or full. Pipes cannot be used for broadcast communication.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Message Passing
Introduction
Two types of message transfers. Synchronous vs Asynchronous. Design Issues
1. Message Size 2. Scope of Message Buffer
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Message Queues
Benefits
Process Identity is not required.. No waiting. Selective Retrieval.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Message Queues
Design
<>
msqid_ds
+msg_perm: ipc_perm +msg_first: msg +msg_last: msg +wwait: wait_queue +rwait: wait_queue +msg_qnum: short +msgget() +msgsend() +msgrecv() +msgctl()
<>
msg
+msg_next: msg +msg_type: long +msg_spot: char +msg_stime: time +msgtx_size: short
Message based programming in Java (JMS, Javaspaces)
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
Applications of IPC mechanisms in Problem Solving
Examples
Producer and Consumer Reader Writer Deadlock Handling. Some Distributed Problems Election algorithm. Few other mechanisms Shared Memory, Sequencer, Event Count and Active Objects, Condition Variables.
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System
IPC
Compulsary Readings
Implementing RPC Paradigms of Process Interactions VP Operations
Arvind W. Kiwelekar Assistant Professor, Department of Computer Engineering, DBTU-Lonere, 402103 Raigad awk@netone.in Advanced Operating System