OPERATING SYSTEMS: Lesson 4: Process Scheduling

Similar documents
CHAPTER 2: PROCESS MANAGEMENT

Chapter 5: CPU Scheduling

Lecture 2 Process Management

Scheduling of processes

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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)

Unit 3 : Process Management

Operating System Concepts Ch. 5: Scheduling

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

SMD149 - Operating Systems

CS370 Operating Systems

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

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

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

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

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

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

CS3733: Operating Systems

COSC243 Part 2: Operating Systems

Chap 4, 5: Process. Dongkun Shin, SKKU

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

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

Processes, PCB, Context Switch

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

CPU Scheduling Algorithms

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.

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

CS370 Operating Systems

Processes and Threads

CS370 Operating Systems

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

Operating Systems Process description and control

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

Operating Systems. Lecture 05

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Uniprocessor Scheduling

Ch 4 : CPU scheduling

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

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

Process- Concept &Process Scheduling OPERATING SYSTEMS

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

Uniprocessor Scheduling. Chapter 9

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Operating Systems ECE344. Ding Yuan

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Processes and Threads

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

8: Scheduling. Scheduling. Mark Handley

Course Syllabus. Operating Systems

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

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

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

Properties of Processes

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

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

Scheduling. The Basics

Chapter 5: CPU Scheduling

Chapter 9 Uniprocessor Scheduling

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

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

1.1 CPU I/O Burst Cycle

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Chapter 6: CPU Scheduling

Chapter 9. Uniprocessor Scheduling

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

CSC 539: Operating Systems Structure and Design. Spring 2006

LECTURE 3:CPU SCHEDULING

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

Department of Computer applications. [Part I: Medium Answer Type Questions]

Last Class: Processes

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

Frequently asked questions from the previous class survey

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

CSE 120 Principles of Operating Systems Spring 2017

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

MARUTHI SCHOOL OF BANKING (MSB)

Chapter 6: CPU Scheduling

Class average is Undergraduates are performing better. Working with low-level microcontroller timers

Chapter 5 CPU scheduling

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

(MCQZ-CS604 Operating Systems)

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

CPU Scheduling: Objectives

CS418 Operating Systems

Operating Systems. Process scheduling. Thomas Ropars.

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

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

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

Processes-Process Concept:

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

Operating Systems. Scheduling

Transcription:

OPERATING SYSTEMS: Lesson 4: Process Scheduling Jesús Carretero Pérez David Expósito Singh José Daniel García Sánchez Francisco Javier García Blas Florin Isaila 1

Content Process creation. Process termination. Process lifecycle. Kinds of scheduling. Scheduling algorithms. 2

Process creation OS provides mechanism to allow a process to create other processes System call. Process creation can be repeated recursively leading to a family structure Process tree. Resource allocation for new process: Directly obtained from the OS. Parent must give out its resources to the child process or share part of them with it. To avoid a system hang by indefinitely replicating the process resources. 3

Process hierarchy (pstree) 4

Process creation When a process is created: In terms of execution: Parent process runs in parallel with children. Parent process waits until some or all of its children have terminated. In terms of memory space: Child process is a clone of the parent process. Child process is converted into another program loaded in memory. 5

UNIX process creation Unix family makes distinction between process creation and new program execution. System call to create a new process is fork() This system call creates a copy almost identical of the parent process. Both processes, parent and child, continue execution in parallel. Parent gets as a result from the fork() call the child PID and child gets a 0. Some resources are not inherited (e.g.: pending signals). Process P pid H fork() Kernel Process H 0 6

Linux process creation fork: Copies parent process and gives new identity to child Get free entry in Process Table Copy PCB from parent Duplicate Memory Map from parent (including stacks) State ß ready PCB in ready queue Also clean up signals, events, Return PID to parent Return 0 to child 7

UNIX process creation Child process may invoke the exec*() system call. Changes its memory image with a different program. Parent may continue creating more children, or waiting until the created child finishes. wait() takes the process from the Ready queue until the child has terminated. sh Process H exec() Kernel Disk vi 8

Process creation in Linux exec: Change memory image from a process using as a new container a new one Free process memory image Read executable Create new image M à PCB Load.text and.data sections Create initial U stack Create S stack: dir. program start Init PCB: regs.; PC ß dir OS RETI 9

Copy on Write (COW) Inefficiencies of the fork() model: A lot of data is copied, but data could be shared instead. If finally another memory image is loaded, is even worse as all copies are discarded PCB parent PCB child Many UNIX systems use COW: Copy-on-Write is a technique to delay or avoid copying data when performing a fork. Data pages are shared and marked as COW so that if a modification is applied, then a copy is done the process (parent and child). Now fork() only copies the page table from parent (but not the pages) and creates a new PCB for child. Page table in parent process Memory pages of Parent process Page table in child process Sharing go avoid duplication 10

Content Process creation. Process termination. Process lifecycle. Kinds of scheduling. Scheduling algorithms. 11

Process termination When a process frees all its allocated resources. Memory, open files, entries in tables, and the kernel notifies that to parent process. A process may terminate in 2 ways: Voluntarily: exit() system call. Involuntarily: Exceptions: divide by zero, segment violation, Aborted by user (ctrl-c) or other process (kill)» i.e.: signals that cannot be handled or ignored. 12

Process termination When a process terminates two outcomes are possible: Its children are not affected. All children also terminate cascade termination (e.g. VMS operating system) In Unix, Terminated child processes are now children of the init process. Terminated process changes to zombie state until parent process gets its termination code. 13

When is PCB eliminated? Process termination and PCB elimination are two different tasks: When parent gets information from child, data structures can be removed. wait() system call: Blocks process until a child terminates. Returns PID of the terminated child. Code1.c 14

Content Process creation. Process termination. Process lifecycle. Kinds of scheduling. Scheduling algorithms. 15

Process basic lifecycle Dispatching Running As many as processors Termination Ready End of slice Blocked Wait for event New Processes End of blocking by event 16

Process Control Block (PCB) Information associated with each process Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information PCBs are stored in a global process table 17

Ready Queue And Various I/O Device Queues 18

Spawning to disk (swap) When there are many process in execution, performance may degrade due to excessive memory paging. Solution: Operating System may need to send a process to the swap area in disk. New process states. Blocked and suspended. Ready and suspended. 19

Process lifecycle New Processes Dispaching Running As many as processors Termination Wait for event Ready End of slice Blocked End of blocking by event Suspension Recovery Suspension Ready and Suspended End of blocking by event Blocked and Suspended 20

Content Process creation. Process termination. Process lifecycle. Kinds of scheduling. Scheduling algorithms. 21

Basic Concepts Maximum CPU utilization obtained with multiprogramming Having when possible at any time the CPU used by a process CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait CPU burst distribution 22

Alternating Sequence of CPU And I/O Bursts 23

Scheduling levels Short term scheduling: Selects next process to execute. Medium term scheduling: Select process to be added or retired (suspended to swap) from main memory. Long term scheduling: Perform admission control of processes. Very used in batch systems. 24

Kinds of scheduling Non-preemptive. Process in execution keeps running on CPU while it is able to use the CPU. Preemptive: Operating System may acquire the CPU, evict the process and change the execution to another process. 25

Scheduling decision points Points in time when OS may perform process scheduling: When a process blocks waiting for an event. Perform a system call. I/O request Wait() invocation When an interrupt happens. Clock interrupt. I/O interrupt. When a process switches from waiting state to ready state I/O completion When a process ends. Nonpreemptivescheduling: 1 and 4. Windows95, MacOS before 8. Preemptive scheduling: 1, 2, 3, and 4. 26

Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency time it takes for the dispatcher to stop one process and start another running 27

Process queues Ready processes are kept in a queue. Alternatives: Single queue. Queues by types of processes. Priority queues. 28

Content Process creation. Process termination. Process lifecycle. Kinds of scheduling. Scheduling algorithms. 29

Scheduling: metrics CPU utilization: Percentage of time CPU is used. Goal: Maximize. Throughput: Number of jobs finished by unit of time. Goal: Maximize. Turnaround time (T q ) Overall time a process is in system. T q = T f T i T f : Finalization time. T i : Initiation time. Goal: Minimize. 30

Scheduling: Metrics Service time(t s ): Time devoted to productive tasks(cpu, I/O). T s = T cpu + T I/O Waiting time (T w ): Time a process spends in waiting queues. T w = T q T s Normalized Turnaround time (T n ): Ratio between Turnaround time and service time. T n = T q /T s Indication of experienced delay. 31

FCFS First to Come First to Serve. Non-preemptive. Penalizes short processes: Convoy effect short process behind long process Proces s Arrival A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 Service A A A B B B B B B C C C C D D D D D E E 32

FCFS: Normalized Turnaround Time Proces s Arrival Service Init End Turnar ound Wait A 0 3 0 3 3 0 3/3=1 Normalized Turnaround B 2 6 3 9 7 1 7/6=1.16 C 4 4 9 13 9 5 9/4=1.25 D 6 5 13 18 12 7 12/5=2.4 E 8 2 18 20 12 10 12/2=6 Average Turnaround time: 4.6 Average normalized Turnaround time : 2.5 33

SJF Shortest Job First. Non-preemptive algorithm. Selects shortest job. It can only be applied if duration of each job is known beforehand. SJF is optimal gives minimum average waiting time for a given set of processes The difficulty is knowing the length of the next CPU request Starvation possibility: If short jobs are continuously arriving, longer jobs never are in position to be executed. 34

SJF Proces s Arrival Service Init End Turnar ound Wait A 0 3 0 3 3 0 3/3=1 Normalized Turnaround B 2 6 3 9 7 1 7/6=1.16 C 4 4 11 15 11 7 11/4=2.75 D 6 5 15 20 14 9 14/5=2.8 E 8 2 9 11 3 1 3/2=1.5 A A A 3.6 1.84 B B B B B B C C C C D D D D D E E 35

Cyclic or Round-Robin Keeps a FIFO queue with processes ready to run. A process is allocated into a processor for a time slice. 10-100 milliseconds A process goes back to the ready queue when: Its time slice expires. An event that took it to the blocked queue happens. A process goes to the blocked queue when: Starts waiting for an event. It is a preemptive algorithm. It is important to remind that every context switch leads to a delay: Time slice >> Context switch time Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high 36

Round-Robin (q=1) Proces s Arrival Service Init End Turnar ound Wait Normalized Turnaround A 0 3 0 4 4 1 4/3=1.33 B 2 6 2 18 16 10 16/6=2.66 C 4 4 5 17 13 9 13/4=3.25 D 6 5 7 20 14 9 14/5=2.8 E 8 2 10 15 7 5 7/2=3.5 A A A 6.8 2.71 B B B B B B C C C C D D D D D E E 37

Round-Robin (q=2) Proces s Arrival Service Init End Turnar ound Wait Normalized Turnaround A 0 3 0 5 4 1 4/3=1.33 B 2 6 2 17 16 10 16/6=2.66 C 4 4 5 13 13 9 13/4=3.25 D 6 5 9 20 14 9 14/5=2.8 E 8 2 13 15 7 5 7/2=3.5 A A A 6 2.54 B B B B B B C C C C D D D D D E E 38

Round-Robin (q=4) Proces s Arrival Service Init End Turnar ound Wait A 0 3 0 3 3 0 3/3=1 Normalized Turnaround B 2 6 3 17 15 9 15/6=2.5 C 4 4 7 11 7 3 7/4=1.75 D 6 5 11 20 14 9 14/5=2.8 E 8 2 17 19 11 9 11/2=5.5 6 2.71 A A A B B B B C C C C D D D D B B E E D 39

Priority Scheduling Each process has a priority assigned to it. Select first processes with higher priority. Preemptive nonpreemptive Alternatives: Fixed priorities à starvation problem low priority processes may never execute. Solution: aging mechanisms as time progresses increase the priority of the process 40

Scheduling in Windows Main characteristics: Priority based Uses time slices. Preemptive scheduling. Scheduling with processor affinity. Scheduling at thread level (not process level). A thread may loose the processor if another with higher priority becomes ready. Scheduling decisions: New threads à Ready. Blocked threads receiving its event à Ready. Thread leaves processor if time slice expires, it terminates or becomes blocked. 41

Summary Process creation implies memory image and PCB creation. A process transitions through different states during its execution. Operating system is responsible for process scheduling. Scheduling may be preemptive or non-preemptive. Different process scheduling algorithms may favor a certain type of processes. Modern Operating systems use preemptive scheduling. 42

OPERATING SYSTEMS: Lesson 4: Process Scheduling Jesús Carretero Pérez David Expósito Singh José Daniel García Sánchez Francisco Javier García Blas Florin Isaila 43