Interprocess Communication

Similar documents
Other Interprocess communication (Chapter 2.3.8, Tanenbaum)

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

Diagram of Process State Process Control Block (PCB)

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

The Big Picture So Far. Chapter 4: Processes

The Big Picture So Far. Chapter 4: Processes

Chapter 3: Process Concept

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

Chapter 4: Processes

Part Two - Process Management. Chapter 3: Processes

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

Chapter 4: Processes. Process Concept

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

Chapter 3: Processes

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

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

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

Chapter 4: Processes. Process Concept

Chapter 4: Processes

Operating Systemss and Multicore Programming (1DT089)

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

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

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

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

Operating Systems 2010/2011

Chapter 3: Processes. Operating System Concepts 9 th Edition

CS420: Operating Systems. Interprocess Communication

Chapter 4: Processes. Process Concept. Process State

Operating Systemss and Multicore Programming (1DT089)

Chapter 3: Processes. Operating System Concepts 9 th Edition

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Process Concept

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

Chapter 4: Processes

System Calls & Signals. CS449 Spring 2016

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

Signals. Joseph Cordina

ECE 650 Systems Programming & Engineering. Spring 2018

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

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

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

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

CS370 Operating Systems

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

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition

System Programming. Signals I

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

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

Chapter 3: Processes

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

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

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

CSE 421: Introduction to Operating Systems

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

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

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

Chapter 3: Processes

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Concurrency Problems Signals & Synchronization Semaphore Mutual Exclusion Critical Section Monitors

Chapter 4 Multithreaded Programming

Dept. Of Computer Science, Colorado State University

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

Frequently asked questions from the previous class survey

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

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

Start of Lecture on January 20, Chapter 3: Processes

CS240: Programming in C

CSI Module 2: Processes

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

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

CS370 Operating Systems

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

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

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

Signals. Goals of this Lecture. Help you learn about: Sending signals Handling signals

Interprocess Communication

3.1 Introduction. Computers perform operations concurrently

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Operating Systems. Threads and Signals. Amir Ghavam Winter Winter Amir Ghavam

Operating System Design

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

Processes and Threads

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

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

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

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

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Inter Process Communication

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

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

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

Lecture 4 Threads. (chapter 4)

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

Transcription:

Interprocess Communication Reading: Silberschatz chapter 4 Additional Reading: Stallings chapter 6 EEL 358 1

Outline Introduction Shared memory systems POSIX shared memory Message passing systems Direct communication Indirect communication Buffering Exception conditions A Case Study for UNIX Signals Using keyboard Using command line Using system calls Client-Server communication Sockets Remote procedure calls Remote method invocation EEL 358 2

Process Cooperation Independent Process Cooperating Process Why Cooperation? Information Sharing Computation Speed-up Modularity Convenience What is IPC? Shared Memory Message Passing EEL 358 3

Interprocess Communication Cooperating process require IPC to exchange data and information. Two models: Shared Memory: Read and write data in shared region Maximum speed & convenience, within computer (e.g. UNIX pipes) Message Passing: Exchange messages between cooperating process Useful for exchanging small amount of data Implementation ease for intercomputer communication Vs SM (e.g. UNIX Sockets) EEL 358 4

Shared Memory Systems Memory speeds, Faster than message passing Permission: Normal case, one process cannot access others memory Shared memory region resides on address space of process creating shared memory region Communication process attach to this address space POSIX Shared Memory: Process creates shared memory segment Segment_id = shmget(ipc_pvt, size, S_IRUSR S_IWUSR) IPC_PVT Identifier to shared memory segment size in bytes mode, S_IRUSR/S_IWUSR Owner R/W Other process attach it their address apace Shared_memory = (char *) shmat (id, NULL, 0) id Integer identifier to shared memory segment Pointer location in memory to attach shared memory, NULL lets OS Flag 0, both read & write in shared region Usage sprintf(shared_memory, Learning POSIX Shared Memory Usage ) shmdt() detach, shmctl() -remove EEL 358 5

Shared Memory Systems Producer-Consumer problem: Common paradigm for cooperating process e.g. assembly code from compiler assembler html files & images client web browser Shared Memory Solution: Use a buffer in shared memory filled up by consumer, emptied by consumer, ensure sync Unbounded buffer No limit, producer can always produce, consumer may wait for new items Bounded buffer Fixed buffer size, consumer must wait if empty, producer must wait if full EEL 358 6

Producer/Consumer Problem Several Consumers and producers, Code? Buffer hold the data which is not yet consumed Two logical pointers; in and out in (out) - next (first) free (full) position in the buffer in == out, Empty; ((in +1) % BUFFER_SIZE == out, Full Producer Process Consumer Process item nextproduced; item nextconsumed; while (1) { while ((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextproduced; in = (in + 1) % BUFFER_SIZE; } while (1) { while (in == out) ; /* do nothing */ nextconsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; } EEL 358 7

Message Passing Systems - Communicate & Sync actions without sharing the same address space - Useful in distributed environment, chat programs on www Fixed size Vs Variable size messages Basic operations send (message) transmission of message receive (message) receipt of a message Links Logical Implementation rather than its Physical Implementation Important design issues Form of communication Direct Vs Indirect Error handling How to deal with the exception conditions? Buffering How and where the messages are stored? Automatic or Explicit Buffering EEL 358 8

Direct Communication A communication link in direct communication has following properties A link is established automatically between every pair of process wishing to communicate, but the process need to know each others identity A unique link is associated with two process The link is usually bidirectional but it can be unidirectional EEL 358 9

Naming Direct Communication Process 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 Asymmetric Addressing Variant of above scheme, only sender names the receiver and receiver is does not have to know the name of specific send (P, message) Send message to process P receive (id, message) Receive a pending (posted) message from any process, when the message arrives, id is set to the name of process Disadvantage Limited modularity, process identifier EEL 358 10

Indirect Communication Communication Link Properties A link is established between two process only if they share a mailbox A link may be associated with more than two process Communication process may have different links between them, each corresponding to one mailbox The link is usually bidirectional but it can be unidirectional EEL 358 11

Indirect Communication Messages are sent to or received from mailboxes or ports. The send and receive primitives can take following forms: send (A, message) Send message to mailbox A receive (A, message) Receive message from mailbox A This form of communication decouples the sender and receiver, thus allowing greater flexibility Generally a mailbox is associated with many senders and receivers A mailbox may be owned either by a process or OS If mailbox is owned by a process Owner and user EEL 358 12

Synchronization Design options for implementing send and receive primitives: Synchronous synchronization required for communicating process both send and receive are blocking operations also known as rendezvous Asynchronous send operation is always almost non-blocking receive operation can have blocking (waiting) or non blocking (polling) variants EEL 358 13

Buffering Messages exchanged by communicating process resides in a temporary queue. Such queues can be implemented in three ways: Zero Capacity No messages waiting, used in synchronous communication Bounded Capacity When buffer is full, sender must wait Indefinite Capacity The sender never waits In non-zero capacity cases (asynchronous) the sender is unaware of the status of the message it sends. Hence additional mechanisms are needed to ensure the delivery and receipt of a message. EEL 358 14

Exception Conditions Single machine environment - usually shared memory messages Distributed environment messages are occasionally lost, duplicated, delayed, or delivered out of order. Some common exception/error conditions that require proper handling. Process Terminates Either a sender or a receiver may terminate before a message is processed Lost Messages A message may be lost in the communication link sue to hardware/line failure Scrambled Messages A message arrives in a state that cannot be processed Primitives not suitable for synchronization in distributed systems Semaphores require global memory Monitors require centralized control Message passing is a mechanism suitable not only for IPC, but also for synchronization, in both centralized and distributed environments. EEL 358 15

A case study UNIX signals A UNIX signal is a form of IPC used to notify a process of an event. - generated when event first occurs - delivered when the process takes an action on that signal - pending when generated but not yet delivered. Signals, also called software interrupts, generally occur asynchronously Signals Various notifications sent to a process to notify it of important event They interrupt whatever the process is doing at that time Unique integer number and symbolic name (/usr/include/signal.h) See the list of signals supported in your system <kill -l> Each signal may have a signal handler, function that gets called when process receives the signal Handling Signals Used by OS to notify the processes that some event has occurred Event notification mechanism for a specific application Sending Signals One process to another, including itself Kernel (OS) to process EEL 358 16

A case study UNIX signals Sending Signals Using Keyboard Ctrl-C System sends an INT signal (SIGINT) to running process By default Immediately terminates the running process Ctrl-Z System sends an TSTP signal (SIGSTP) to running process By default Suspends the execution of running process Sending Signals Using Command Line kill - <signal> <PID> Signal name or number, e.g. kill INT 1560, similar to Ctrl-C If no PID? fg Resume the execution of process suspended by Ctrl-Z by sending CONT signal raise <signal> Process sends signal to itself signal <signal, SIGARG func> System Call, A process may declare a function to serve a particular signal as above. When signal is received, Process is interrupted and func is called immediately, resumes once executed EEL 358 17

What to do with a signal? 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 upon the signal, the default action can be: exit perform all activities as if the exit system call is requested core first produce core image on the disk and then perform the exit activities stop suspend the process ignore disregard the signal EEL 358 18

A case study UNIX signals Core dump A core dump is an unstructured record of the contents of working memory at a specific time Generally used to debug a program that has terminated abnormally (crashed) In past, printout of the entire contents of working memory, debugging Generating Core dump of a running process To generate a core file named 'core' in for the process with a process id of 1230: <gcore 1230> EEL 358 19

A case study UNIX signals Sending Signals Using System Calls #include <unistd.h> /* standard UNIX functions, like getpid()*/ #include <sys/types.h> /* various type definitions, like pid_t */ #include <signal.h> /* signal name macros, and the kill() prototype */ /* first, find my own process ID */ pid_t my_pid = getpid(); /* now that i got my PID, send myself the STOP signal. */ kill(my_pid, SIGSTOP); EEL 358 20

A case study UNIX signals Using signal() system call #include <unistd.h> /* standard UNIX functions, like getpid()*/ #include <sys/types.h> /* various type definitions, like pid_t */ #include <signal.h> /* signal name macros, and the kill() prototype */ /* first, here is the signal handler */ void catch_int(int sig_num) { /* re-set the signal handler again to catch_int, for next time */ signal(sigint, catch_int); /* and print the message */ printf("don't do that"); fflush(stdout); }.. /* and somewhere later in the code... */. /* set the INT (Ctrl-C) signal handler to 'catch_int' */ signal(sigint, catch_int); /* now, lets get into an infinite loop of doing nothing. */ for ( ;; ) pause(); EEL 358 21

A case study UNIX signals Some possible signals, their #, and their default handling SIGNAL ID DEFAULT DESCRIPTION SIGHUP 1 Termin. Hang up; sent to process when kernel assumes that user of a process is not doing any useful work SIGINT 2 Termin. Interrupt. Generated when we enter CNRTL-C SIGQUIT 3 Core Generated when at terminal we enter CNRTL-\ SIGILL 4 Core Generated when we executed an illegal instruction SIGTRAP 5 Core Trace trap; triggers the execution of code for process tracking SIGABRT 6 Core Generated by the abort function SIGFPE 8 Core Floating Point error SIGKILL 9 Termin. Termination (can't catch, block, ignore) SIGBUS 10 Core Generated in case of hardware fault SIGSEGV 11 Core Generated in case of illegal address SIGSYS 12 Core Generated when we use a bad argument in a system service call SIGPIPE 13 Termin. Generated when writing to a pipe or a socket while no process is reading at other end...... Many more EEL 358 22

Client-Server Communication Shared memory, message passing Several other strategies for communication in client-server systems: Sockets Remote Procedure Calls Remote Method Invocation (Java) EEL 358 23

Sockets Endpoint for communication A socket IP address Concatenated with port number Sockets use client-server architecture The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 Process Communication Pair of sockets EEL 358 24

Socket Communication EEL 358 25

Remote Procedure Calls Remote procedure call (RPC) procedure calls between processes on networked systems Stubs client-side proxy for the actual procedure on the server The client-side stub locates the server and marshalls the parameters The server-side stub receives message, unpacks the marshalled parameters, performs the procedure on the server EEL 358 26

Execution of RPC EEL 358 27

Remote Method Invocation Remote Method Invocation (RMI) is a Java mechanism similar to RPCs RMI = RPC + Object-Orientation RMI allows a Java program on one machine to invoke a method on a remote object EEL 358 28

RMI and RPCs Fundamental differences Procedural programming Vs object based RMI supports invocation of methods on remote objects RPCs parameters ordinary data structures, RMI pass objects as parameters (Distributed Java applications) EEL 358 29

Marshalling Parameters EEL 358 30