Operating System Design

Similar documents
Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 3: Process Concept

Chapter 3: Process Concept

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Chapter 3: Processes

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

CS370 Operating Systems

Chapter 3: Process Concept

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

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

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

Chap 4, 5: Process. Dongkun Shin, SKKU

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

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

Chapter 4: Processes

Chapter 4: Processes. Process Concept

Diagram of Process State Process Control Block (PCB)

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,

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

Part Two - Process Management. Chapter 3: Processes

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

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

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

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

The Big Picture So Far. Chapter 4: Processes

The Big Picture So Far. Chapter 4: Processes

CS370 Operating Systems

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

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

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

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

Chapter 4: Processes. Process Concept

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

Chapter 4: Processes

Chapter 3: Process Concept

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

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

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

CS370 Operating Systems Midterm Review

Start of Lecture on January 17, Chapter 3: Processes

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

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

Chapter 4: Processes. Process Concept. Process State

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

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 4: Processes

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Processes COMPSCI 386

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Processes. Process Concept

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

Processes and Threads

CS307 Operating Systems Processes

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

Course: Operating Systems Instructor: M Umair. M Umair

CS Lecture 2! Processes! George Mason University! Fall 2010!

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

Operating Systems. Figure: Process States. 1 P a g e

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

UNIT - II PROCESS MANAGEMENT

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Operating System Concepts Ch. 3: Processes

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

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

CSC 539: Operating Systems Structure and Design. Spring 2006

Processes. Operating System Concepts 8 th Edition

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Operating Systems. Lecture 05

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

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

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

csci3411: Operating Systems

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

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

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

CS370 Operating Systems Midterm Review. Yashwant K Malaiya Spring 2019

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

W4118 Operating Systems. Junfeng Yang

3.1 Introduction. Computers perform operations concurrently

CSE 153 Design of Operating Systems Fall 2018

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

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

CS420: Operating Systems. Interprocess Communication

CHAPTER 2: PROCESS MANAGEMENT

Transcription:

Operating System Design Processes Operations Inter Process Communication (IPC) Neda Nasiriani Fall 2018 1

Process 2

Process Lifecycle 3

What information is needed? If you want to design a scheduler to divide your time resource between a bunch of different processes, what info would you need in order to schedule effectively and fairly Process state running, waiting, etc Program counter location of instruction to next execute CPU registers contents of all process-centric registers CPU scheduling information- priorities, scheduling queue pointers Memory-management information memory allocated to the process Accounting information CPU used, clock time elapsed since start, time limits I/O status information I/O devices allocated to process, list of open files 4

Where to keep that information? There is a data type called Process Control Block (PCB) that contains all this information about each process 5

CPU Switch between Processes Context Switch: When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch This time is pure overhead! 6

Process Creation: How? An existing process can create a new process by calling the fork() system call fork() runs once in the parent process but returns two times, 1) In the child process, with returning value of 0 2) In the parent process, with the value of the child process id Both the child and the parent process start executing with the instruction that follows the fork() system call The child process gets a copy of the parent s data space, heap and stack (It is a separate copy from the parent s) 7

Quiz 2 You can use your notes. 8

Process Creation Processes may be created or deleted dynamically in the system Examples of creating a process within a process? If you are designing a web server, you need to constantly listen to possible incoming requests Also there could be 1000 of request every second, how can you address them all in a timely fashion? You would like to run another program within your program Parent process creates children processes, which, in turn can create other processes, forming a tree of processes. 9

A Process Tree on Linux OS Kernel Pid=0 init pid = 1 login pid = 8415 kthreadd pid = 2 sshd pid = 3028 bash pid = 8416 khelper pid = 6 pdflush pid = 200 sshd pid = 3610 ps pid = 9298 emacs pid = 9204 tcsch pid = 4005 10

Process Creation Resource sharing: Parent and children share all resources, Children share subset of parent s resources, Parent and child share no resources. Execution: Parent and children execute concurrently, Parent may wait until children terminate. Address space: Child has duplicate of parent s address space, or Child can have a program loaded onto it. UNIX examples: fork system call creates new process and returns with a pid (0 in child, > 0 in the parent), 11

FYR: Linux fork() The new process created by fork is called the child process. This function is called once but returns twice. The only difference in the returns is that the return value in the child is 0, whereas the return value in the parent is the process ID of the new child. The reason the child s process ID is returned to the parent is that a process can have more than one child, and there is no function that allows a process to obtain the process IDs of its children. The reason fork returns 0 to the child is that a process can have only a single parent, and the child can always call getppid to obtain the process ID of its parent. (Process ID 0 is reserved for use by the kernel, so it s not possible for 0 to be the process ID of a child.) Both the child and the parent continue executing with the instruction that follows the call to fork. The child is a copy of the parent. For example, the child gets a copy of the parent s data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the child do share the text segment, however (Section 7.6). Modern implementations don t perform a complete copy of the parent s data, stack, and heap, since a fork is often followed by an exec. Instead, a technique called copy-on-write (COW) is used. These regions are shared by the parent and the child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a page in a virtual memory system. Section 9.2 of Bach [1986] and Sections 5.6 and 5.7 of McKusick et al. [1996] provide more detail on this feature. 12

Process Creation: How? An existing process can create a new process by calling the fork() system call fork() runs once in the parent process but returns two times, 1) In the child process, with returning value of 0 2) In the parent process, with the value of the child process id Both the child and the parent process start executing with the instruction that follows the fork() system call The child process gets a copy of the parent s data space, heap and stack (It is a separate copy from the parent s) 13

Process Creation: sharing resources The child process gets its own copy of the data section, stack and heap of the parent process The child process get a duplicate of all open file descriptors in its parent process The parent and the child share a file table entry for every open descriptor The parent and the child share the same file offset If a child process is writing to standard output when the parent process is executing it can append to the end of standard output Does changes in the child variables change the parent variables? No 14

Process Creation: example 15

Process Creation Diagram The parent can wait on the child process by system calls pid_t wait (int * status); pid_t waitpid (pid_t pid, int * status, int options); Both these return process id on successful return or -1 in case of an error Otherwise the parent process might terminate before the child process terminates!!! 16

Process Execution A child process can execute 1) A segment of its parent code (as we saw before) 2) Another program that is loaded to its memory using exec() system call When a process calls one of the exec functions, that process is completely replaced by the new program, and the new program starts executing at its main function 17

Process Execution: example 18

FYR: exec system call 19

Process Termination Process executes last statement and then asks the operating system to delete it using the exit() system call. Returns status data from child to parent (via wait(&status)) Process resources are deallocated by operating system The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status); If parent has not called wait()yet but the child is terminated, the info of child is still kept in the process table. This child process is a zombie If parent terminated without invoking wait, process is an orphan, which is adopted by init process 20

Demo! 21

Interprocess Communication (IPC) 22

Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes: Information sharing Computation speedup Modularity Convenience Example: Chrome browser 23

Chrome Browser Many web browsers ran as single process (some still do) If one web site causes trouble, entire browser can hang or crash Google Chrome Browser is multiprocess with 3 different types of processes: Browser process manages user interface, disk and network I/O Renderer process renders web pages, deals with HTML, Javascript. A new renderer created for each website opened Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits Plug-in process for each type of plug-in 24

Chrome Browser Many web browsers ran as single process (some still do) If one web site causes trouble, entire browser can hang or crash Google Chrome Browser is multiprocess with 3 different types of processes: Renderer needs to communicate with the browser And plug-in process needs to talk to Browser process manages user interface, disk and network I/O Renderer process renders web pages, deals with HTML, Javascript. A new the renderer Browser created if a tab for is using each a website plug-in opened Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits Plug-in process for each type of plug-in 25

Interprocess Communication Example: Chrome browser Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing 26

Communication Models 27 (a) Message passing. (b) shared memory.

Shared Memory: Producer Consumer Example Assume process A is producing items and put them into a buffer of size N Process B is reading from the buffer Example Compiler sends assembly code to the assembler B: Consumer Code: A:Producer Code: Produce item in item = buffer [out] out = (out + 1)%N Consume the item buffer [in] = item in = (in + 1)%N 0 1 2 3 N-2 N-1 28 buffer out

Producer Consumer Example What are the things that can go wrong here? The buffer could be empty (nothing to be read by the consumer) The buffer could be full (no items can be added by the producer) What if they try to access the buffer at the same time? Initially in = out = 0 B: Consumer Code: A:Producer Code: Produce item in item = buffer [out] out = (out + 1)%N Consume the item buffer [in] = item in = (in + 1)%N 0 1 2 3 N-2 N-1 29 buffer out

Producer-Consumer Example item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % N) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % N; } item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % N; 30 } /* consume the item in next consumed */

Message Passing Mechanism for processes to communicate and to synchronize their actions Message system processes communicate with each other without resorting to shared variables IPC facility provides two operations: send(message) receive(message) The message size is either fixed or variable 31

Message Passing If processes P and Q wish to communicate, they need to: Establish a communication link between them Exchange messages via send/receive Implementation issues: How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional? 32

Message Passing Implementation of communication link Physical: Shared memory Hardware bus Network Logical: Direct or indirect Synchronous or asynchronous Automatic or explicit buffering 33

Pipes 34

Pipes Acts as a conduit allowing two processes to communicate Issues: Is communication unidirectional or bidirectional? In the case of two-way communication, is it half or full-duplex? Must there exist a relationship (i.e., parent-child) between the communicating processes? Can the pipes be used over a network? Ordinary pipes cannot be accessed from outside the process that created it. Typically, a parent process creates a pipe and uses it to communicate with a child process that it created. Named pipes can be accessed without a parent-child relationship. 35

Ordinary Pipes Ordinary Pipes allow communication in standard producer-consumer style Producer writes to one end (the write-end of the pipe) Consumer reads from the other end (the read-end of the pipe) Ordinary pipes are therefore unidirectional Require parent-child relationship between communicating processes Windows calls these anonymous pipes 36