Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Process scheduling and scheduling algorithms, Lecture notes of Operating Systems

Process scheduling topics covered 1.basic concepts 2.Scheduling criteria 3.Scheduling algorithms

Typology: Lecture notes

2019/2020

Uploaded on 11/10/2020

shubhan-saini
shubhan-saini 🇮🇳

1 document

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 5: Process
Scheduling
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Process scheduling and scheduling algorithms and more Lecture notes Operating Systems in PDF only on Docsity!

Chapter 5: Process

Scheduling

Outline

 (^) Basic Concepts  (^) Scheduling Criteria  (^) Scheduling Algorithms

Basic Concepts

 (^) 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

Histogram of CPU-burst Times

Large number of short bursts Small number of longer bursts

Preemptive and Nonpreemptive

Scheduling

 (^) When scheduling takes place only under circumstances 1 and 4, the scheduling scheme is nonpreemptive.  (^) Otherwise, it is preemptive.  (^) Under Nonpreemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases it either by terminating or by switching to the waiting state.  (^) Virtually all modern operating systems including Windows, MacOS, Linux, and UNIX use preemptive scheduling algorithms.

Preemptive Scheduling and Race

Conditions

 (^) Preemptive scheduling can result in race conditions when data are shared among several processes.  (^) Consider the case of two processes that share data. While one process is updating the data, it is preempted so that the second process can run. The second process then tries to read the data, which are in an inconsistent state.  (^) This issue will be explored in detail in Chapter 6.

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.

Scheduling Algorithm Optimization

Criteria

 (^) Max CPU utilization  (^) Max throughput  (^) Min turnaround time  (^) Min waiting time  (^) Min response time

FCFS Scheduling (Cont.)

Suppose that the processes arrive in the order: P 2 , P 3 , P 1  (^) The Gantt chart for the schedule is:  (^) Waiting time for P 1 = 6 ; P 2 = 0 ; P 3 = 3  (^) Average waiting time: (6 + 0 + 3)/3 = 3  (^) Much better than previous case  (^) Convoy effect - short process behind long process  (^) Consider one CPU-bound and many I/O-bound processes P (^1) 0 3 6 30 P 2 P (^3)

Shortest-Job-First (SJF) Scheduling  (^) Associate with each process the length of its next CPU burst  (^) Use these lengths to schedule the process with the shortest time  (^) 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  (^) Could ask the user

Example of SJF

ProcessArriva l Time Burst Time P 1 0.0 6 P 2 2.0 8 P 3 4.0 7 P 4 5.0 3  (^) SJF scheduling chart  (^) Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P (^3) 0 3 24 P 4 P (^1) 9 16 P (^2)

Determining Length of Next CPU Burst

 (^) 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  (^) Commonly, α set to ½

  1. Define :
  2. , 0 1
  3. predictedvalueforthenextCPU burst
  4. actual lengthof CPU burst         (^) n 1 th t n n

Examples of Exponential Averaging  (^)  =  (^)  n+1 =^ n  (^) Recent history does not count  (^)  =  (^)  n+1 =^ ^ t n  (^) Only the actual last CPU burst counts  (^) If we expand the formula, we get:  n +1 =  t n +(1 -)tn -1 + … +( 1 -  )j^  tn - j + … +( 1 -  )n^ +1^  0  (^) Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor

Example of Shortest-remaining-time- first  (^) Now we add the concepts of varying arrival times and preemption to the analysis ProcessA arri Arrival TimeT Burst Time P 1 0 8 P 2 1 4 P 3 2 9 P 4 3 5  (^) Preemptive SJF Gantt Chart  (^) Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6. P (^4) 0 1 26 P 1 P (^2) 10 P 1 P (^3) 5 17