Chapter 7 - Interprocess Communication Patterns

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
3.5 Interprocess Communication
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
IPC and Classical Synchronization Problems
Process Concept n An operating system executes a variety of programs: –Batch system – jobs –Time-shared systems – user programs or tasks n Textbook uses.
1 Concurrency: Deadlock and Starvation Chapter 6.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operation on Processes.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 4 Process Slide 1 Chapter 4 Process.
Chapter 71 Deadlock Detection revisited. Chapter 72 Message Passing (see Section 4.5 in Processes Chapter)  A general method used for interprocess communication.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating Systems Lecture Notes Processes Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Termination Process executes last statement and asks the operating.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Gokul Kishan CS8 1 Inter-Process Communication (IPC)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating System Concepts
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Interprocess Communication Patterns
Applied Operating System Concepts
Concurrency: Mutual Exclusion and Synchronization
Chapter 4: Processes Process Concept Process Scheduling
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6 Synchronization Principles
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
CSE 542: Operating Systems
Chapter 3: Process Management
Presentation transcript:

Chapter 7 - Interprocess Communication Patterns Why study IPC? Not typical programming style, but growing. Typical for operating system internals, though. Typical for many network-based services. Will take a process level view of IPC (Figure 7.1).

Recall three methods used for IPC Message passing File I/O (via pipes) Shared memory Processes either compete (e.g., for CPU cycles, printers, etc.) or cooperate (e.g., a pipeline) as they run. Competing processes can lead to incorrect data. Example: multiple simultaneous edits on the same file by different users Each user loads up a copy of the file Last user to write() “wins” the competition

Figure 7.2 & table on page 234 demonstrate how the ordering of the read() and write() events between the users can potentially cause the loss of one of the user’s editing sessions. This is called the mutual exclusion problem - either one of the two can edit, but not both at the same time (think of Exclusive OR Boolean operator). Critical section - sequence of actions that must be done one at a time. Serially reusable resource - a resource that can only be used by one process as a time.

Race condition - when the order of process completion makes a difference in the outcome (like in the two edit problem; it’s a race to see who comes in last!). Potential for race condition exists if two or more processes are allowed to run in parallel; serializing their execution prevents race condition (but is infeasible). Figure 7.4 demonstrates a race condition at the “atomic” instruction level -- two processes incrementing a shared memory counter. Race condition can be prevented by use of critical sections.

Figure 7.5 -- create a critical section for each process. The critical section represents a code segment that must be serialized (that is, only allow one process at a time to be in the critical section). It’s better to serialize just one segment than the execution of the entire process! How to enforce a critical section? One solution uses a hardware ExchangeWord() mechanism introduced in chapter 6, which we aren’t going to consider now. A more likely solution is to use the operating system as the serializer enforcer.

So, we will look at different ways to solve the mutual exclusion problem. First technique: use SOS messages! First, though, let’s create two new system calls that allow us to name the queues, rather than relying on the parent passing qIDs to children. int AttachMessageQueue(char *msg_q_name) - look up the message queue name in the file name space; create it if it doesn’t exist and set it’s attach count == 1 (one process has it attached). If it already exists, increment the attach count (one more process has it attached). Return the qID for later SendMessage()/ReceiveMessage() calls (or -1).

int DetachMessageQueue(int msg_q_id) - Decrement the attach count by one; if the attach count reaches zero then delete the message queue file from the file system. Return -1 if msg_q_id is invalid. Extend Exit() so that any attached queues are automatically detached when the process ends, to keep things straight (just like auto-closing of any opened files). We will surround the critical section of code with a ReceiveMessage() call, which will block the calling process until a message is actually in the queue. The SendMessage() call will be used after the critical section to signal the other waiting process.

Two-process Mutual Exclusion using a Message Queue (page 239 & Figure 7.6) Note that the message content is not used. One process has to start the ball rolling (“seed” the first ReceiveMessage() to not block). The messages are like a ticket or token that permits the ticket holder to access the file. Notice that the sender and receiver can be the same, depending on which process gets scheduled by the O/S. This algorithm works for more than 2 processes, due to the serial nature of the message queue (FIFO). This algorithm also nicely avoids busy waiting, since the waiting processes are blocked.

IPC as a signal (Figure 7.7) We want a way to synchronize code between two processes. Use ReceiveMessage() to wait for the signal and SendMessage() to send the signal. An example: The Wait() call of a parent will block until a “signal” is received from the Exit() of a child. Rendezvous Want a way to know that two processes are synchronized so they can begin a common task at roughly the same time. Use a two-way symmetric signaling method with SendMessage()/ReceiveMessage() pairs (Figure 7.8)

Producer-Consumer IPC pattern Most basic pattern of IPC; combines signaling with data exchange. Easily visualized as a pipeline (Figure 7.10) xlsfonts | grep adobe Note that the producer can “get ahead” of the consumer by generating more output than the consumer can consume (vice versa); the O/S must perform buffering. The O/S does not have access to infinite disk and/or memory, so buffering is limited; the producer- consumer code should be written with this in mind. This also helps keep “slack on the line” if process scheduling is “bursty”.

The Producer-Consumer pattern with limited buffering (page 248-249) Makes use of two message queues; one for the data being produced/consumed and another to throttle the producer. This is a symmetric signaling example. The consumer “fills” the throttle queue with (in this case) 20 messages -- in other words, the producer has 20 signals already queued up and can then send up to 20 messages before receiving another “throttle up” signal. Note if the buffer limit is set to one this algorithm is equivalent to the rendezvous (except we continuously rendezvous while producing/consuming). The Producer-Consumer model is versatile; many variations (Figures 7.12 & 7.13)

Client-Server IPC pattern Many resources lend themselves well to having a single centralized server that responds to requests from multiple clients. Examples abound - print server, file server, web server, telnet server, email server, etc. Server will wait on a “public” message queue, waiting for requests and servicing them as they arrive. Example: “Squaring” server (page 251) -- yes, this is the same rendezvous/consumer-producer code that pairs up SendMessage()/ReceiveMessage(). The difference is in the client vs server relationship.

Client-Server IPC pattern Another difference - servers are usually always running, waiting for requests; clients “get in and get out”. Usually servers provide multiple services and are written to handle such; Figure 7.14 is an example of a file server’s algorithm. Multiple Servers/Client & Database Access/Update: (Individually review 7.11 & 7.12). One interesting tidbit: readers & writers problem. Can have parallel readers but only one writer accessing database at at time.

Nice summary of the IPC Patterns on page 262-265: Mutual Exclusion (mutex) Signaling Rendezvous Producer-Consumer Client-Server Multiple Servers & Clients Database Access & Update