Introduction. Interprocess communication. Terminology. Shared Memory versus Message Passing

Similar documents
Other Interprocess communication (Chapter 2.3.8, Tanenbaum)

Interprocess Communication

Start of Lecture on January 20, Chapter 3: Processes

Operating Systems 2010/2011

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Workshop on Inter Process Communication Solutions

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

CSE 421: Introduction to Operating Systems

* What are the different states for a task in an OS?

Signals. Joseph Cordina

Process. Signal #8. Signals are software interrupts from unexpected events. a power failure. an alarm clock. the death of a child process

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

The Big Picture So Far. Chapter 4: Processes

Shell Execution of Programs. Process Groups, Session and Signals 1

The Big Picture So Far. Chapter 4: Processes

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Chapter 4: Processes. Process Concept

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Chapter 4: Processes

CS240: Programming in C

Diagram of Process State Process Control Block (PCB)

3.1 Introduction. Computers perform operations concurrently

Concurrent Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CSI Module 2: Processes

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Operating Systems 9/6/ SIGINT Terminate Interrupt from keyboard (ctl-c) 9 SIGKILL Terminate Kill program (cannot override or ignore)

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Chapter 4: Processes

KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 6

Part Two - Process Management. Chapter 3: Processes

Chapter 8: I/O functions & socket options

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Chapter 3: Processes. Operating System Concepts 8 th Edition,

! The Process Control Block (PCB) " is included in the context,

SMD149 - Operating Systems

Operating Systems. VI. Threads. Eurecom. Processes and Threads Multithreading Models

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Lecture 7: Signals and Events. CSC 469H1F Fall 2006 Angela Demke Brown

Chapter 3: Process Concept

Chapter 3: Processes

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

ECE 650 Systems Programming & Engineering. Spring 2018

Process Concept. Chapter 4: Processes. Diagram of Process State. Process State. Process Control Block (PCB) Process Control Block (PCB)

Chapter 4: Processes

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Lecture 2 Process Management

Prepared by Prof. Hui Jiang (COSC3221) 2/9/2007

Chapter 4: Processes. Process Concept

Multitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Signals, Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Process. Program Vs. process. During execution, the process may be in one of the following states

Chapter 3: Processes. Operating System Concepts 9 th Edition

Multitasking / Multithreading system Supports multiple tasks

Overview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Processes. Operating System Concepts 8 th Edition,

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

Princeton University. Computer Science 217: Introduction to Programming Systems. Signals

Process Concept Process Scheduling Operations On Process Inter-Process Communication Communication in Client-Server Systems

Chapter 3: Process Concept

Signal Example 1. Signal Example 2

Lecture 4: Process Management

Concurrency Principles

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider

System Programming. Signals I

Preview. Process Termination. wait and waitpid() System Call. wait and waitpid() System Call. waitpid() System Call 10/23/2018

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal.

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

CSC209H Lecture 8. Dan Zingaro. March 4, 2015

Chapter 3: Processes. Operating System Concepts 9 th Edition

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Chapter 4: Processes. Process Concept. Process State

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

Chapter 3: Processes. Operating System Concepts 8th Edition

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

Transcription:

Introduction Interprocess communication Cooperating processes need to exchange information, as well as synchronize with each other, to perform their collective task(s). The primitives discussed earlier can be used to synchronize the operation of cooperating processes, but they do not convey information between processes. Methods for effective sharing of information among cooperating processes are collectively known as interprocess communication (IPC). Two basic models are used: shared memory shared data are directly available to each process in their address spaces. message passing shared data are explicitly exchanged. Copyright 1998-2001 by Eskicioglu & Marsland IPC Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 Shared Memory versus Message Passing Terminology shared memory (e.g., UNIX pipes) message passing (e.g., UNIX sockets) process send process write read process B receive common approach in communication is where one process sends some information to another. The information exchanged among processes in this way is called a message. message can be a structured (language) object, specified by its type, or it is specified by its size: fixed length or variable length. There are two basic operations on messages: send() transmission of a message. receive() receipt of a message. The OS component which implements these operations (and more!) is called a message passing system. process B Copyright 1998-2001 by Eskicioglu & Marsland IPC 2 Copyright 1998-2001 by Eskicioglu & Marsland IPC 3

Fundamental questions Design Issues message passing system should answer such questions as: When a message is sent, does the sender wait until the message is received or can it continue executing? What happens if a process executes a receive(), but no message has been sent? Can a message be sent to one or to many processes? Does a receiver identify the sender of the message or can it accept messages from any sender? Where are messages kept while in transit? Capacity?... Implementation of message passing systems may differ in a number of details that affect the functioning of the send and receive operations and their parameters. The following are the most important issues in the design and implementation of a message passing system: Form of communication messages can be send directly to its recipient or indirectly through an intermediate named object. Buffering how and where the messages are stored. Error handling how to deal with exception conditions. Copyright 1998-2001 by Eskicioglu & Marsland IPC 4 Copyright 1998-2001 by Eskicioglu & Marsland IPC 5 Direct communication Direct communication continued The sender and receiver can communicate in either of the following forms: synchronous involved processes synchronize at every message. Both send and receive are blocking operations. This form is also known as a rendezvous. asynchronous the send operation is almost always non-blocking. The receive operation, however, can have blocking (waiting) or non-blocking (polling) variants. Processes must explicitly name the receiver or sender of a message (symmetric addressing). send (P, message). Send message to process P. receive (Q, message). Receive message from Q. In a client-server system, the server does not have to know the name of a specific client in order to receive a message. In this case, a variant of the receive operation can be used (asymmetric addressing). listen (ID, message). Receive a pending (posted) message from any process; when a message arrives, ID is set to the name of the sender. Copyright 1998-2001 by Eskicioglu & Marsland IPC 6 Copyright 1998-2001 by Eskicioglu & Marsland IPC 7

Direct communication continued Indirect communication In this form of communication the interconnection between the sender and receiver has the following characteristics: link is established automatically, but the processes need to know each other s identity. In case of indirect communication, messages are sent to mailboxes, which are special repositories. message can then be retrieved from this repository. send (, message). Send a message to mailbox. receive (, message). Receive a message from mailbox. unique link is associated with the two processes. Each pair of processes has only one link between them. This form of communication decouples the sender and receiver, thus allowing greater flexibility. The link is usually bi-directional, but it can be unidirectional. Generally, a mailbox is associated with many senders and receivers. In some systems, only one receiver is (statically) associated with a particular mailbox; such a mailbox is often called a port. Copyright 1998-2001 by Eskicioglu & Marsland IPC 8 Copyright 1998-2001 by Eskicioglu & Marsland IPC 9 Indirect communication continued Message passing by picture process that creates a mailbox is the owner (sender). Mailboxes are usually managed by the system. The interconnection between the sender and receiver has the following characteristics: Direct communication to B from B link is established between two processes only if they share a mailbox. link may be associated with more than two processes. to M B to P B Communicating processes may have different links between them, each corresponding to one mailbox. The link is usually bi-directional, but it can be unidirectional. from M C M mailbox D port Indirect communication P C from P Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 0 Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 1

Buffering Error handling Depending on the capacity of the link between the communicating processes, three types of messaging can be implemented: Zero capacity used by synchronous communication. Bounded capacity when the buffer is full, the sender must wait. In distributed systems, message passing mechanisms extend inter-process communication beyond the machine boundaries. Consequently, messages are occasionally lost, duplicated, delayed, or delivered out of order. The following are the most common error conditions which requires proper handling: Indefinite capacity the sender never waits. Note that, however, in the non-zero capacity cases (asynchronous), the sender is unaware of the status of the message it sends. Hence, additional mechanisms are needed to guarantee the delivery and receipt of a message. Process terminates either a sender or a receiver may terminate before a message is processed. Lost or delayed messages a message may be lost (or delayed) in the communications network. Scrambled messages a message arrives in an unprocessible state. Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 2 Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 3 Synchronization with messages n example The primitives discussed earlier are not suitable for synchronization in distributed systems. For example, semaphores require global memory, whereas monitors require centralized control. pplication of such centralized mechanisms to distributed environments is not usually practical. However, message passing is a mechanism suitable not only for inter-process communication, but also for synchronization, in both centralized and distributed environments. typedef message... const capacity =... ; message dummy = ; int main() int i; create_mailbox( mayconsume ); create_mailbox( mayproduce ); for ( i = 0; i < capacity; i++ ) send( mayproduce, dummy ); producer(); consumer(); Note: In this example, both send() and receive() are blocking operations. producer() message pmsg; while ( true ) receive( mayproduce, pmsg ); < produce > send( mayconsume, pmsg ); consumer() message cmsg; while ( true ) receive( mayconsume, cmsg ); < consume > send( mayproduce, cmsg ); Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 4 Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 5

Other IPC mechanisms case study UNIX signals The following are IPC mechanisms found in various flavors of UNIX: Pipes FIFOs (named pipes) Streams and Messages System V IPC Message Queues Semaphores Shared Memory Sockets (BSD) Transport Level Interface (System V) UNIX signal, a rudimentary form of IPC, is used to notify a process of an event. signal is generated when the event first occurs and delivered when the process takes an action on that signal. signal is pending when generated but not yet delivered. Signals, also called software interrupts, generally occur asynchronously. signal can be sent: by one process to another, including itself (in the latter case it is synchronous) by the kernel to a process Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 6 Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 7 Sending a signal What to do with a signal? kill(int pid, int sig); sends a signal sig to the process pid. process sends a signal to itself with raise(int sig); There is no operation to receive a signal. However, a process may declare a function to service a particular signal as: signal(int sig, SIGRG func); Whenever the specified signal sig is received, the process is interrupted and func is called immediately. In other words, the process catches the signal when it is delivered. On return from func, the process resumes its execution from where it was interrupted. Using the signal() system call, a process can: Ignore the signal only two signals, SIGKILL (kill -9 PID) and SIGSTOP (Ctrl-Z) cannot be ignored. Catch the signal tell the kernel to call a function whenever the signal occurs. Let the default action apply depending on the signal, the default action can be: exit perform all activities as if the exit system call is requested. core first produce a core image on disk and then perform the exit activities. stop suspend the process. ignore disregard the signal. Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 8 Copyright 1998-2001 by Eskicioglu & Marsland IPC 1 9

UNIX signals an example #include < stdio.h > #include < signal.h > #include < unistd.h > #include < stdlib.h > int main ( void ) int i ; void catch_signal( int ) ; if ( signal( SIGINT, catch_signal ) == SIG_ERR ) perror( SIGINT failed ) ; exit ( 1 ); if ( signal( SIGQUIT, catch_signal ) == SIG_ERR ) perror( SIGQUIT failed ) ; exit( 1 ) ; for ( i = 0; ; i++ ) /* loop forever */ printf( %d\n, i ) ; sleep( 1 ) ; output % a.out 0 1 2 ^C Signal 2 received. 3 ^C Signal 2 received. 4 5 6 ^\ Signal 3 received. Exiting... % void catch_signal( int the_signal ) signal( the_signal, catch_signal ) ; /* catch again */ printf( \nsignal %d received.\n, the_signal ) ; if ( the_signal == SIGQUIT ) printf( Exiting...\n ) ; exit( 3 ); Copyright 1998-2001 by Eskicioglu & Marsland IPC 2 0