Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Similar documents
Chapter 3: Processes. Operating System Concepts 9 th Edit9on

CHAPTER 2: PROCESS MANAGEMENT

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Chapter 3: Processes

Chapter 5: CPU Scheduling

Lecture 2 Process Management

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 3: Processes

CPU Scheduling Algorithms

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

Operating System Concepts Ch. 5: Scheduling

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

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

Chapter 3: Process Concept

Chapter 6: CPU Scheduling

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

CS370 Operating Systems

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Processes. Operating System Concepts 9 th Edition

Properties of Processes

Chapter 3: Process Concept

Chapter 3: Process Concept

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

CPU Scheduling: Objectives

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

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

CS370 Operating Systems

CS3733: Operating Systems

Killing Zombies, Working, Sleeping, and Spawning Children

LECTURE 3:CPU SCHEDULING

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

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

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

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

CS370 Operating Systems

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

CS370 Operating Systems

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

COSC243 Part 2: Operating Systems

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Processes and Threads

Chapter 6: CPU Scheduling

Chap 4, 5: Process. Dongkun Shin, SKKU

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

Chapter 5: CPU Scheduling

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

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

UNIT - II PROCESS MANAGEMENT

Chapter 5 CPU scheduling

Job Scheduling. CS170 Fall 2018

Process- Concept &Process Scheduling OPERATING SYSTEMS

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

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

3. CPU Scheduling. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Chapter 5: CPU Scheduling

Advanced Operating Systems (CS 202) Scheduling (1)

Chapter 3: Processes

Ch 4 : CPU scheduling

Chapter 4: Processes. Process Concept

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Chapter 3: Process Concept

Chapter 4: Processes

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Course Syllabus. Operating Systems

CSE 4/521 Introduction to Operating Systems

Operating Systems. Lecture 05

Frequently asked questions from the previous class survey

CS307: Operating Systems

Last Class: Processes

OPERATING SYSTEMS: Lesson 4: Process Scheduling

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

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Operating Systems ECE344. Ding Yuan

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

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

CS370 Operating Systems Midterm Review

Scheduling of processes

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

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

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

CSC 539: Operating Systems Structure and Design. Spring 2006

Scheduling Mar. 19, 2018

SMD149 - Operating Systems

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

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

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Unit 3 : Process Management

Chapter 5: Process Scheduling

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

Transcription:

Processes CS 475, Spring 2018 Concurrent & Distributed Systems

Review: Abstractions 2

Review: Concurrency & Parallelism 4 different things: T1 T2 T3 T4 Concurrency: (1 processor) Time T1 T2 T3 T4 T1 T1 T3 T4 T2 T1 T3 Parallelism: (2 processors) T1 T2 T3 T4 T1 T1 T1 T3 T4 T2 T1 T3 Time 3

Review: Processes vs Threads code heap data files code heap data files stack stack stack stack Single-Threaded Process Multi-Threaded Process 4

Review: Processes vs Threads Context Switching Processor context: The minimal collection of values stored in the registers of a processor used for the execution of a series of instructions (e.g., stack pointer, addressing registers, program counter). When switching processes, all of that data needs to get flushed out (by the OS) Threads share the same address space: no need to do this switch 5

Today How does the OS manage concurrency? Processes! A little bit of OS Basic concepts Linux internals Context switching Discuss HW1 Additional readings: OS TEP Ch 4, 6 OS TEP Ch 5 might be useful for HW1 Slide acknowledgements: OS Concepts 9th Ed, Silberschatz, Galvin & Gagne 6

Process as a concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Process a program in execution; process execution must progress in sequential fashion Multiple parts The program code, also called text section Current activity including program counter, processor registers Stack containing temporary data Function parameters, return addresses, local variables Data section containing global variables Heap containing memory dynamically allocated during run time 7

Process as a concept Program is passive entity stored on disk (executable file), process is active Program becomes process when executable file loaded into memory Execution of program started via GUI mouse clicks, command line entry of its name, etc One program can be several processes Consider multiple users executing the same program 8

Process State As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a processor terminated: The process has finished execution 9

Process Representation A process has some mapping into the physical machine (machine state) Provide two key abstractions to programs: Logical control flow Each program seems to have exclusive use of the CPU Provided by kernel mechanism called context switching Private address space Each program seems to have exclusive use of main memory. Provided by kernel mechanism called virtual memory Memory Stack Heap Data Code CPU Registers 10

Process Control Block (PCB) The OS has one big data structure that stores all of the information about each process, including: 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 Memory Stack Heap Data Code CPU Registers 11

Virtual View of Multiprocessing Memory Memory Memory Memory Stack Heap Data Code Stack Heap Data Code Stack Heap Data Code Stack Heap Data Code CPU CPU CPU CPU Registers Registers Registers Registers Goal: make it look like all processes are running at once, with infinite processors 12

Actual View of Multiprocessing Memory Stack Stack Stack Heap Data Heap Data Heap Data Code Code Code Saved registers Saved registers Saved registers CPU CPU Registers Registers Single (or several) processor(s) execute multiple processes concurrently Executions are interleaved (multitasking) Address spaces for each process managed by virtual memory system (see OS) Registers for non-executing processes saved in memory 13

CPU Switching from Process to Process Memory Stack Stack Stack Heap Data Heap Data Heap Data Code Code Code Saved registers Saved registers Saved registers CPU Registers 14

Context Switching 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 Context of a process represented in the PCB Context-switch time is overhead; the system does no useful work while switching The more complex the OS and the PCB the longer the context switch Time dependent on hardware support Some hardware provides multiple sets of registers per CPU multiple contexts loaded at once 15

Context Switching Process 1 Operating System Process 2 executing interrupted or yields Save state into PCB1 idle Load PCB2 resumes executing idle Save state into PCB2 interrupted or yields resumes Load PCB1 idle executing 16

Creating Processes Parent process create children processes, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier (pid) Resource sharing options Parent and children share all resources Children share subset of parent s resources Parent and child share no resources Execution options Parent and children execute concurrently Parent waits until children terminate 17

Process Tree 18

Creating Processes Address space Child duplicate of parent Child has a program loaded into it UNIX examples fork() system call creates new process exec() system call used after a fork() to replace the process memory space with a new program 19

Fork int fork(void) creates a new process (child process) that is identical to the calling process (parent process) returns 0 to the child process returns child s pid to the parent process if (fork() == 0) { printf("hello from child\n"); } else { printf("hello from parent\n"); } Fork is interesting (and often confusing) because it is called once but returns twice 20

Fork Under the hood: is NOT actually copying everything Fork'ed memory is "copy-on-write" protected Memory is not copied up front If fork'ed process reads, then OK If fork'ed process writes, then make copy Possible from OS implementation of virtual memory (but that s another course) 21

Copy on write HEAP A=1 Read Write HEAP A=2 Original Process Forked Process 22

Exec int exec(...) Never returns (unless an error) Loads the code from some executable (passed as a parameter) Re-initializes all of memory of that process to be clean 23

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()) Process resources are deallocated by operating system Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so: Child has exceeded allocated resources Task assigned to child is no longer required The parent is exiting and the operating systems does not allow a child to continue if its parent terminates 24

Process Termination Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated. cascading termination. All children, grandchildren, etc. are terminated. The termination is initiated by the 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 no parent waiting (did not invoke wait()) process is a zombie If parent terminated without invoking wait, process is an orphan 25

Process Scheduling Key for concurrency Maximize CPU use, quickly switch processes onto CPU for time sharing Process scheduler selects among available processes for next execution on CPU Maintains scheduling queues of processes Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues 26

Checkpoint Go to socrative.com and select Student Login (works well on laptop, tablet or phone) Room Name: CS475 ID is your @gmu.edu email Remember: this is a checkpoint for you, it is only graded for attendance 27

Schedulers Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU Sometimes the only scheduler in a system Short-term scheduler is invoked frequently (milliseconds) (must be fast) Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue Long-term scheduler is invoked infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming 28

Different Kinds of Processes Processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts Long-term scheduler strives for good process mix This will come up for distributed systems too! 29

Sidebar: I/O Speeds CPU 1 thread0() 7ns CPU 1 Cache 100ns 150,000ns (just to read 4KB) SSD CPU 2 Main Memory 10,000,000ns (just to seek!) thread1() CPU 2 Cache Magnetic HD Takeaway: it s REALLY important to have other stuff to do while I/O happens 30

Scheduling Maximum CPU utilization obtained with multiprogramming CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait CPU burst followed by I/O burst CPU burst distribution is of main concern 31

Basic CPU Scheduler Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: Switches from running to waiting state Terminates Switches from running to ready state Switches from waiting to ready 32

Preemption In the "old days" (before me), there were nonpreemptive schedulers Run job from start to end (or until process yields) Virtually all schedulers are, in fact, preemptive These schedulers can force a process to yield and perform a context switch 33

Scheduling Criteria CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) Ideally we want to minimize on these criteria 34

FCFS Scheduling What if they arrive in this order? P1, P2, P3 Waiting time for P1: 0; P2=24; P3=27 Process Actual Burst Time P1 24 P2 3 P3 3 Average waiting time: 17 What if they arrive P2, P3, P1? Waiting time for P2: 0, P3: 3, P1: 6 Average waiting time: 3 Convoy effect - short processes get stuck behind long processes and have to wait 35

Obvious fix: Shortest Job First IF we know how long everything will take, we can optimize on waiting time by running the short jobs first (the second case from FCFS) Process Actual Burst Time P1 24 P2 3 P3 3 This would be optimal But: how do we know how long each process will take? 36

Estimating CPU time Can only estimate the length should be similar to the previous one Then pick process with shortest predicted next CPU burst Can be done by using the length of previous CPU bursts, using exponential averaging 1. 2. 3. 4. t n = actual length of n τ n+ 1 α, 0 α Define : = predicted value for 1 Commonly, α set to ½ CPU burst the next CPU burst Preemptive version called shortest-remaining-time-first th ( 1 α). τ n = α t + τ = 1 n n 37

Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority) Preemptive Nonpreemptive Shortest Job First is priority scheduling where priority is the inverse of predicted next CPU burst time Problem Starvation low priority processes may never execute Solution Aging as time progresses increase the priority of the process 38

Round Robin Scheduling Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Timer interrupts every quantum to schedule next process Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high Good on response time (each process starts quick), bad on turnaround time 39

Multilevel Queue Combine Round Robin + priority scheduling Ready queue is partitioned into separate queues, eg: foreground (interactive) background (batch) Process permanently in a given queue Each queue has its own scheduling algorithm: foreground RR background FCFS Scheduling must be done between the queues: Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR, 20% to background in FCFS 40

Multilevel Queue 41

Multitasking in Mobile Systems Some mobile systems (e.g., early version of ios) allow only one process to run, others suspended Due to screen real estate, user interface limits ios provides for a Single foreground process- controlled via user interface Multiple background processes in memory, running, but not on the display, and with limits Limits include single, short task, receiving notification of events, specific long-running tasks like audio playback Android runs foreground and background, with fewer limits Background process uses a service to perform tasks Service can keep running even if background process is suspended Service has no user interface, small memory use 42

Assignment 1 Discussion http://www.jonbell.net/gmu-cs-475-spring-2018/ homework-1/ https://autolab.cs.gmu.edu/courses/cstest/ assessments 43

Roadmap Next week: How can we get multiple processes to work together? Threads 44