SlideShare una empresa de Scribd logo
1 de 47
Chapter 5: Process Scheduling
Chapter 5: Process Scheduling
 Basic Concepts
 Scheduling Criteria
 Scheduling Algorithms (6)
 Multiple-Processor Scheduling
 Thread Scheduling
 OS Examples
 Algorithm Evaluation
Basic Concepts
 In a multiprogramming system, multiple processes exist c
oncurrently in main memory.
 Each process alternates between using a processor and
waiting for some event to occur, such as the completion o
f an I/O operation.
 The processor is kept busy by executing one process whil
e the others wait.
 The key to multiprogramming is scheduling.
 Process Scheduling is
 the basis of multi-programmed operating system
 a fundamental function of operating-system.
Basic Concepts
 In a single-processor system
 Only one process can run at a time
 Any others must wait until the CPU is free and can be rescheduled.
 When the running process goes to the waiting state,
 the OS may select another process to assign CPU to improve
CPU utilization.
 Every time one process has to wait, another process can take over
use of the CPU
 Process scheduling is
 to select a process from the ready queue and assign the CPU
Diagram of Process State from ch.3
 It is important to realize that only one process can be running on any
processor at any instant.
 Many processes may be ready and waiting states.
Process Scheduling from ch.3
• The process selection is carried out by the short-term scheduler (or
CPU scheduler).
• The scheduler selects a process from the processes in memory that are
ready to execute and allocates the CPU to that process.
CPU - I/O burst Cycle
 Process execution consists of
 a cycle of CPU execution (CPU burst) and I/O wait (I/O burst)
 Process alternate between these two states
 Process execution begins with a CPU burst, which is followed by
an I/O burst, and so on.
 Eventually, the final CPU burst ends with an system call to
terminate execution.
 CPU burst distribution of a process
 varies greatly from process to process and from computer to
computer
Alternating Sequence of CPU & I/O Bursts
CPU burst time
I/O burst time
CPU burst time
CPU burst time
Histogram of CPU-burst Times
 CPU burst distribution is generally characterized
 as exponential or hyper-exponential
 with large number of short CPU burst and small number of long CPU burst
 I/O bound process has many short CPU bursts
 CPU bound process might have a few long CPU bursts.
Process Scheduler
 selects one of the processes in memory that are ready to
execute, and allocates the CPU to the selected process.
 CPU scheduling decisions may take place when a
process:
1. switches from running to waiting state: I/O request, invocation of
wait() for the termination of other process
2. switches from running to ready state: when interrupt occurs
3. switches from waiting to ready: at completion of I/O
4. terminates
Process Scheduler(cont.)
 Scheduling under 1 and 4 is non-preemptive
 Scheduling under 2 and 3 is preemptive
Non-preemptive vs. Preemptive
 Non-preemptive scheduling
 Once the CPU has been allocated to a process, the process keeps the
CPU until it releases the CPU
 either by terminating or by switching to the waiting state.
 used by Windows 3.x
 Preemptive scheduling
 Current running process can be switched with another at any time
 because interrupt can occur at any time
 Most of modern OS provides this scheme. (Windows XP, Max OS, UNIX)
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
CPU-scheduling function
? ?
Context Switch from ch. 3
Scheduling Criteria
 Based on the scheduling criteria, the performance of various scheduling
algorithm could be evaluated.
 Different scheduling algorithms have different properties.
 CPU utilization –keep the CPU as busy as possible. i.e., ratio (%) of the
amount of time while the CPU was busy per time unit.
 Throughput – # of processes that complete their execution per time unit.
 Turnaround time – the interval from the time of submission of a process
to the time of completion. Sum of the periods spent waiting to get into
memory, waiting in the ready queue, executing on the CPU, and doing
I/O
 Waiting time – Amount of time a process has been waiting in the ready
queue, which is affected by scheduling algorithm
 Response time – In an interactive system, amount of time it takes from
when a request was submitted until the first response is produced, not
output (for time-sharing environment)
Optimization Criteria
 It is desirable to maximize:
 The CPU utilization
 The throughput
 It is desirable to minimize:
 The turnaround time
 The waiting time
 The response time
 However in some circumstances, it is desirable to
optimize the minimum or maximum values rather than
the average.
 Interactive systems, it is more important to minimize the variance
in the response time than minimize the average response time.
Process Scheduling Algorithms
 First-Come, First-Served Scheduling (FCFS)
 Shortest-Job-First Scheduling (SJF)
 Priority Scheduling
 Round-Robin Scheduling
 Our measure of comparison is the average waiting time.
First-Come, First-Served (FCFS) Scheduling
 The process that request the CPU first is allocated the
CPU first.
Process Burst Time(ms)
P1 24
P2 3
P3 3
 Suppose that the processes arrive in the order: P1 , P2 ,
P3
The Gantt Chart for the schedule is:
 Waiting time for P1 = 0; P2 = 24; P3 = 27
 Average waiting time: (0 + 24 + 27)/3 = 17ms
P1 P2 P3
24 27 30
0
FCFS Scheduling
Suppose that the processes arrive in the order
P2 , P3 , P1
 The Gantt chart for the schedule is:
 Waiting time for P1 = 6; P2 = 0; P3 = 3
 Average waiting time: (6 + 0 + 3)/3 = 3
 Much better than previous case
P1
P3
P2
6
3 30
0
FCFS Scheduling
 FCFS scheduling algorithm is non-preemptive
 Once the CPU has been allocated to a process, that process keeps
the CPU until it releases the CPU, either by terminating or by
requesting I/O.
 is particularly troublesome for time-sharing systems (response
time ).
 Convoy effect (short process behind long process)occurs:
 When one CPU-bound process with long CPU burst and many
I/O-bound process which short CPU burst.
 All I/O bound process waits for the CPU-bound process to get off
the CPU while I/O is idle
 All I/O- and CPU- bound processes executes I/O operation while
CPU is idle.
 results in low CPU and device utilization
Shortest-Job-First (SJF) Scheduling
 SJF associates with each process the length of its next
CPU burst.
 use these lengths to schedule the process with the
shortest time
 Two schemes:
 non-preemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst
 preemptive – if a new process arrives with CPU burst length less
than remaining time of current executing process, preempt. This
scheme is known as the Shortest-Remaining-Time-First (SRTF)
 SJF is optimal – gives minimum average waiting time for a
given set of processes
Example of Non-Preemptive SJF
Process Burst Time
P1 6
P2 8
P3 7
P4 0 3
 SJF scheduling chart (non-preemptive)
 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
P4
P3
P1
3 16
0 9
P2
24
Example of Preemptive SJF (SRTF)
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (preemptive)
 Average waiting time = (9 + 1 + 0 +2)/4 = 3
P1 P3
P2
4
2 11
0
P4
5 7
P2 P1
16
How do we know the length of the next CPU
burst?
 by computing an approximation of the length of the next
CPU burst (estimate the length of the next CPU burst)
 can be done by using the length of previous CPU bursts,
using exponential averaging
 The value of tn contains our most recent information.
 n+1 stores the past history
 The parameter  controls the relative weight of recent and
past history in our prediction.
  .
1
:
Define
4.
1
0
number,
real
a
is
3.
burst
CPU
next
for the
value
predicted
2.
burst
CPU
of
lenght
actual
1.
1
1
n
n
n
n
th
n
t
n
t


















Prediction of the Length of the Next CPU Burst
 In this example, 0 = 10,  = ½ , t1=6
 1 =  x t0 + (1- ) x 0 = ½ x 6 + ½ x 10 = 8
 2 =  x t2 + (1- ) x 1 = ½ x 4 + ½ x 8 = 6
Examples of Exponential Averaging
  = 0
 n+1 = n = n-1 = n-2 . … = 0
 Recent history does not count
  = 1
 n+1 = tn
 Only the actual last CPU burst counts i.e., the most recent CPU
burst
 If we expand the formula, we get:
n+1 =  tn + (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
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
 Non-preemptive
Process Burst Time Priority arrival time
P1 10 3 0
P2 1 1 0
P3 2 4 0
P4 1 5 0
P5 5 2 0
 Priority Scheduling (non-preemptive)
 Average waiting time = (0 + 1 + 6 + 16 + 18)/5 = 8.2
Example 1 of Non-Preemptive Priority
P2 P1 P3
16
1
0
P4
18
P5
6 19
Example 2 of Non-Preemptive Priority
Process Ready queue arrive time CPU burst time Priority
P1 0 3 ms 5
P2 1 7 ms 3
P3 4 2 ms 4
P4 2 3 ms 3
P5 6 4 ms 1
P1 P5
P2 P3
P4
0 3 17
14
10 19
scheduling chart (non-preemptive)
Average waiting time= 31/5 = 6.2 ms
Total Waiting time = (0-0) + (3-1) +(17-4) + (14-2) + (10-6) = 0+2+13+12+4=31 ms
Total Turnaround time= (3-0) + (10-1) + (19-4) + (17-2) + (14- 6) = 50 ms
Average Turnaround time= 50/5 = 10ms
Example of Preemptive Priority
Process Ready queue arrive time Cpu burst time Priority
P1 0 3 ms 5
P2 1 7 ms 3
P3 4 2 ms 4
P4 2 3 ms 3
P5 6 4 ms 1
P3
P5
P2
P1 P4 P2 P1
0 6 13
1 17
10 15 19
scheduling chart (preemptive)
Average waiting time= 42/5= 8.4 ms
Total Waiting time = (0-0+17-1) + (1-1+13-6) +(15-4) + (10-2) + (6-6) =42ms
Total Turnaround time= (19-0) + (15-1) + (17-4) + (13-2) + (10-6) = 61ms
Average Turnaround time= 61/5 = 12.2ms
Process P1 preempted by p2 because p2 has higher priority
Priority Scheduling
 SJF is a priority scheduling where priority is the predicted
next CPU burst time
 Problem  Starvation – low priority processes may never
execute
 Solution  Aging – as time progresses, increase the priority
of the process
127
0
Round Robin (RR) Scheduling
 It is similar to FCFS scheduling, but preemption is
added to enable the system to switch between
process.
 Each process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds.
 After this time has elapsed, the process is
preempted and added to the end of the ready
queue.
 If CPU cycle (CPU burst time ) > time quantum
 Job is preempted and put at the end of the READY Q
 If CPU cycle < time quantum
 If job finished
 resources released
 If interrupted by I/O request
 Info saved in PCB
 Linked at end of appropriate I/O queue
 When I/O complete, job returns to READY Q
Example of RR with Time Quantum = 4
Process Burst Time Arrival Time
P1 24 0
P2 3 0
P3 3 0
 The Gantt chart is:
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Average waiting time= 17/3= 5.66 ms
Total Waiting time = (0-0+10-4) + (4-0) +(7-0) =17ms
Total Turnaround time= (30-0) + (7-0) + (10-0) = 47ms
Average Turnaround time= 47/5= 9.4 ms
Context switch ???
Example of RR with Time Quantum = 10
 The Gantt chart is:
Process Ready queue arrive time CPU burst time
P1 0 7 ms
P2 1 13 ms
P3 5 25 ms
P4 6 22 ms
P5 8 40 ms
0 17 74
7 27 37 47 50 60 64
P2 P2
P1 P3 P4 P5 P3 P4 P5
79
P3 P5
89
P5
99
Average waiting time= 180/5= 36 ms
Total Waiting time = (0-0) + (7-1 + 47-17 )+(17-5+ 50-27+ 74- 60)+(27-6+60-37)+
(37-8+64-47+79-64 ) = 180 ms
Total Turnaround time= (7-0) + (50-1) + (79-5)+(64-6)+(99-8) = 279ms
Average Turnaround time= 279/5= 55.8 ms
Round Robin (RR) Scheduling
 Performance depends on the size of the time
quantum.
 If the time quantum is extremely large, the RR policy is
the same as the same as the FCFS policy
 If the time quantum is extremely small (say 1 millisec) ,
the RR approach is called processor sharing i.e.,
provides high concurrency: each of n processes has its
own processor running at 1/n the speed of the real
processor
Time Quantum and Context Switch Time
In (a) the job finishes before the time quantum expires.
In (b) and (c), the time quantum expires first, interrupting the job
 The effect of context switching on the performance of RR
scheduling, for example one process of 10 time quantum.
 quantum = 12 time units, finished in less than 1 time quantum
 quantum = 6 time units, requires 2 quanta, 1 context switch
 quantum = 1 time units, requires 10 quanta, 9 context switch
a
b
c
Round Robin (RR) Scheduling
 The time quantum q must be large with respect to context
switch, otherwise overhead is too high
 If the context switching time is 10% of the time quantum,
then about 10% of the CPU time will be spent in context
switching
 Most modern OS have time quanta ranging from 10 to 100
milliseconds,
 The time required for a context switch is typically less than
10 microseconds; thus the context-switch time is a small
fraction of the time quantum.
Turnaround Time varies with the Time Quantum
 The turnaround time depends on the size of
the time quantum
 The average turnaround
time of a set of processes
dose not necessarily improve
as the time quantum size
Increased.
 The average turnaround
time can be improved
if most processes finish
their next CPU burst
in a single time quantum.
Scheduling Algorithm with multi-Queues
 Multi-level Queue Scheduling
 Multi-level Feedback Queue Scheduling
Multilevel Queue
 Ready queue is partitioned into separate queues:
foreground (interactive)
background (batch)
 The processes are permanently assigned to one queue, generally
based on some property, or process type.
 Each queue has its own scheduling algorithm
 foreground – RR
 background – FCFS
 Scheduling must be done between the queues
 Fixed priority scheduling - serve all from foreground then from
background, Possibility of starvation.
 Time slice scheduling – 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
Multilevel Queue Scheduling
 No process in the batch queue could run unless the queues with high
priority were all empty.
 If an interactive editing process entered the ready queue while a batch
process was running, the batch process would be preempted.
Multilevel Feedback Queue
 A process can move between the various queues; aging
can be implemented in this way
 Multilevel-feedback-queue scheduler defined by the
following parameters:
 number of queues
 scheduling algorithms for each queue
 method used to determine when to upgrade a process
 method used to determine when to demote a process
 method used to determine which queue a process will enter when
that process needs service
Example of Multilevel Feedback Queue
 Three queues:
 Q0 – RR with time quantum 8 milliseconds
 Q1 – RR time quantum 16 milliseconds
 Q2 – FCFS
 Scheduling
 A new job enters queue Q0 which is served RR. When it gains CPU,
job receives 8 milliseconds. If it does not finish in 8 milliseconds,
job is moved to queue Q1.
 At Q1 job is again served RR and receives 16 additional
milliseconds. If it still does not complete, it is preempted and
moved to queue Q2.
 The job is serverd based on FCFS in queue Q2
Multilevel Feedback Queues
Summary
 CPU scheduling is the task of selecting a waiting process from the
ready queue and allocating the CPU to it.
 The CPU is allocated to the selected process by the dispatcher.
 FCFS scheduling is simple, cause short processes to wait for long time
 SJF scheduling is provably optimal, providing the shortest averaging
waiting time. But predicting the length of the next CPU bursts is difficult.
 Priority scheduling allocates the CPU to the heights priority process.
 Both priority and SJF may suffer from starvation. Aging is a technique to
prevent starvation.
 RR scheduling is more appropriate for a time-shared system.
 Major problem of RR scheduling is the selection of the time quantum.
 FCFS is non-preemptive, RR is preemptive, SJF and Priority may be
preemptive and non-preemptive.
 Multilevel queue allows different scheduling algorithm for each queue.
 Multilevel feedback queue allow process to move from one queue to
another.
End of Chapter 5

Más contenido relacionado

La actualidad más candente

Penyebab, Penanggulangan, dan Dampak Banjir
Penyebab, Penanggulangan, dan Dampak BanjirPenyebab, Penanggulangan, dan Dampak Banjir
Penyebab, Penanggulangan, dan Dampak BanjirMahdif Indiarto
 
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah Daerah
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah DaerahMekanisme Penyusunan Rencana Pembangunan Jangka Menengah Daerah
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah DaerahDadang Solihin
 
Teknik perencanaan regional
Teknik perencanaan regionalTeknik perencanaan regional
Teknik perencanaan regionalRulli Saputra
 
INPUT - PROSES - OUTPUT
INPUT - PROSES - OUTPUTINPUT - PROSES - OUTPUT
INPUT - PROSES - OUTPUTCholifatur R
 
Materi perencanaan regional
Materi perencanaan regionalMateri perencanaan regional
Materi perencanaan regionalLocal Government
 
Makalah Komponen dalam Motherboard
Makalah Komponen dalam MotherboardMakalah Komponen dalam Motherboard
Makalah Komponen dalam MotherboardAwidiya Awidiya
 
Rekayasa Sungai
Rekayasa Sungai Rekayasa Sungai
Rekayasa Sungai Baladewa10
 
Mengenal logical framework
Mengenal logical frameworkMengenal logical framework
Mengenal logical frameworkDede Sutisna
 
Modul TKP M3KB3 - Sistem Jaringan Drainase
Modul TKP M3KB3 - Sistem Jaringan DrainaseModul TKP M3KB3 - Sistem Jaringan Drainase
Modul TKP M3KB3 - Sistem Jaringan DrainasePPGHybrid1
 
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...Fitri Indra Wardhono
 
Rencana induk pariwisata Kota Surabaya - Bappeko Surabaya 2007
Rencana induk pariwisata Kota Surabaya -  Bappeko Surabaya 2007Rencana induk pariwisata Kota Surabaya -  Bappeko Surabaya 2007
Rencana induk pariwisata Kota Surabaya - Bappeko Surabaya 2007Fitri Indra Wardhono
 
KONSEP PENGEMBANGAN EKONOMI LOKAL
KONSEPPENGEMBANGAN EKONOMI LOKALKONSEPPENGEMBANGAN EKONOMI LOKAL
KONSEP PENGEMBANGAN EKONOMI LOKALVisualBee.com
 
Kerangka Acuan Kerja Sistem Informasi Posko Keamanan
Kerangka Acuan Kerja Sistem Informasi Posko KeamananKerangka Acuan Kerja Sistem Informasi Posko Keamanan
Kerangka Acuan Kerja Sistem Informasi Posko KeamananPutriAprilliandini
 
Makalah tlus pemilihan lokasi tpa klp 2
Makalah tlus pemilihan lokasi tpa klp 2Makalah tlus pemilihan lokasi tpa klp 2
Makalah tlus pemilihan lokasi tpa klp 2Nailul Husni
 

La actualidad más candente (20)

Pedoman pengelolaan lab inovasi (final)
Pedoman pengelolaan lab inovasi (final)Pedoman pengelolaan lab inovasi (final)
Pedoman pengelolaan lab inovasi (final)
 
1.kuliah das
1.kuliah das 1.kuliah das
1.kuliah das
 
Penyebab, Penanggulangan, dan Dampak Banjir
Penyebab, Penanggulangan, dan Dampak BanjirPenyebab, Penanggulangan, dan Dampak Banjir
Penyebab, Penanggulangan, dan Dampak Banjir
 
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah Daerah
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah DaerahMekanisme Penyusunan Rencana Pembangunan Jangka Menengah Daerah
Mekanisme Penyusunan Rencana Pembangunan Jangka Menengah Daerah
 
Teknik perencanaan regional
Teknik perencanaan regionalTeknik perencanaan regional
Teknik perencanaan regional
 
INPUT - PROSES - OUTPUT
INPUT - PROSES - OUTPUTINPUT - PROSES - OUTPUT
INPUT - PROSES - OUTPUT
 
Materi perencanaan regional
Materi perencanaan regionalMateri perencanaan regional
Materi perencanaan regional
 
Makalah Komponen dalam Motherboard
Makalah Komponen dalam MotherboardMakalah Komponen dalam Motherboard
Makalah Komponen dalam Motherboard
 
Pedoman umum rtbl
Pedoman umum rtblPedoman umum rtbl
Pedoman umum rtbl
 
Rekayasa Sungai
Rekayasa Sungai Rekayasa Sungai
Rekayasa Sungai
 
Komponen Sistem Operasi
Komponen Sistem OperasiKomponen Sistem Operasi
Komponen Sistem Operasi
 
Mengenal logical framework
Mengenal logical frameworkMengenal logical framework
Mengenal logical framework
 
Pertemuan 10 memory
Pertemuan 10 memoryPertemuan 10 memory
Pertemuan 10 memory
 
Modul TKP M3KB3 - Sistem Jaringan Drainase
Modul TKP M3KB3 - Sistem Jaringan DrainaseModul TKP M3KB3 - Sistem Jaringan Drainase
Modul TKP M3KB3 - Sistem Jaringan Drainase
 
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...
Catatan tentang aerotropolis sebagai salah satu bentuk pengembangan kota, dal...
 
Rencana induk pariwisata Kota Surabaya - Bappeko Surabaya 2007
Rencana induk pariwisata Kota Surabaya -  Bappeko Surabaya 2007Rencana induk pariwisata Kota Surabaya -  Bappeko Surabaya 2007
Rencana induk pariwisata Kota Surabaya - Bappeko Surabaya 2007
 
KONSEP PENGEMBANGAN EKONOMI LOKAL
KONSEPPENGEMBANGAN EKONOMI LOKALKONSEPPENGEMBANGAN EKONOMI LOKAL
KONSEP PENGEMBANGAN EKONOMI LOKAL
 
Kerangka Acuan Kerja Sistem Informasi Posko Keamanan
Kerangka Acuan Kerja Sistem Informasi Posko KeamananKerangka Acuan Kerja Sistem Informasi Posko Keamanan
Kerangka Acuan Kerja Sistem Informasi Posko Keamanan
 
Koef runoff
Koef runoffKoef runoff
Koef runoff
 
Makalah tlus pemilihan lokasi tpa klp 2
Makalah tlus pemilihan lokasi tpa klp 2Makalah tlus pemilihan lokasi tpa klp 2
Makalah tlus pemilihan lokasi tpa klp 2
 

Similar a Preemptive process example.pptx

Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - EngineeringYogesh Santhan
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)Nagarajan
 
Process management in os
Process management in osProcess management in os
Process management in osMiong Lazaro
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Mukesh Chinta
 
Ch6
Ch6Ch6
Ch6C.U
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process SchedulingShipra Swati
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfRakibul Rakib
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling gopi7
 
Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System SchedulingVishnu Prasad
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)Harshit Jain
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formattingmarangburu42
 
Cpu scheduling final
Cpu scheduling finalCpu scheduling final
Cpu scheduling finalmarangburu42
 

Similar a Preemptive process example.pptx (20)

Unit 2 notes
Unit 2 notesUnit 2 notes
Unit 2 notes
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Ch6
Ch6Ch6
Ch6
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
Ch5
Ch5Ch5
Ch5
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formatting
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Cpu scheduling final
Cpu scheduling finalCpu scheduling final
Cpu scheduling final
 

Último

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Último (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Preemptive process example.pptx

  • 1. Chapter 5: Process Scheduling
  • 2. Chapter 5: Process Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms (6)  Multiple-Processor Scheduling  Thread Scheduling  OS Examples  Algorithm Evaluation
  • 3. Basic Concepts  In a multiprogramming system, multiple processes exist c oncurrently in main memory.  Each process alternates between using a processor and waiting for some event to occur, such as the completion o f an I/O operation.  The processor is kept busy by executing one process whil e the others wait.  The key to multiprogramming is scheduling.  Process Scheduling is  the basis of multi-programmed operating system  a fundamental function of operating-system.
  • 4. Basic Concepts  In a single-processor system  Only one process can run at a time  Any others must wait until the CPU is free and can be rescheduled.  When the running process goes to the waiting state,  the OS may select another process to assign CPU to improve CPU utilization.  Every time one process has to wait, another process can take over use of the CPU  Process scheduling is  to select a process from the ready queue and assign the CPU
  • 5. Diagram of Process State from ch.3  It is important to realize that only one process can be running on any processor at any instant.  Many processes may be ready and waiting states.
  • 6. Process Scheduling from ch.3 • The process selection is carried out by the short-term scheduler (or CPU scheduler). • The scheduler selects a process from the processes in memory that are ready to execute and allocates the CPU to that process.
  • 7. CPU - I/O burst Cycle  Process execution consists of  a cycle of CPU execution (CPU burst) and I/O wait (I/O burst)  Process alternate between these two states  Process execution begins with a CPU burst, which is followed by an I/O burst, and so on.  Eventually, the final CPU burst ends with an system call to terminate execution.  CPU burst distribution of a process  varies greatly from process to process and from computer to computer
  • 8. Alternating Sequence of CPU & I/O Bursts CPU burst time I/O burst time CPU burst time CPU burst time
  • 9. Histogram of CPU-burst Times  CPU burst distribution is generally characterized  as exponential or hyper-exponential  with large number of short CPU burst and small number of long CPU burst  I/O bound process has many short CPU bursts  CPU bound process might have a few long CPU bursts.
  • 10. Process Scheduler  selects one of the processes in memory that are ready to execute, and allocates the CPU to the selected process.  CPU scheduling decisions may take place when a process: 1. switches from running to waiting state: I/O request, invocation of wait() for the termination of other process 2. switches from running to ready state: when interrupt occurs 3. switches from waiting to ready: at completion of I/O 4. terminates
  • 11. Process Scheduler(cont.)  Scheduling under 1 and 4 is non-preemptive  Scheduling under 2 and 3 is preemptive
  • 12. Non-preemptive vs. Preemptive  Non-preemptive scheduling  Once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU  either by terminating or by switching to the waiting state.  used by Windows 3.x  Preemptive scheduling  Current running process can be switched with another at any time  because interrupt can occur at any time  Most of modern OS provides this scheme. (Windows XP, Max OS, UNIX)
  • 13. 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 CPU-scheduling function ? ?
  • 15. Scheduling Criteria  Based on the scheduling criteria, the performance of various scheduling algorithm could be evaluated.  Different scheduling algorithms have different properties.  CPU utilization –keep the CPU as busy as possible. i.e., ratio (%) of the amount of time while the CPU was busy per time unit.  Throughput – # of processes that complete their execution per time unit.  Turnaround time – the interval from the time of submission of a process to the time of completion. Sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O  Waiting time – Amount of time a process has been waiting in the ready queue, which is affected by scheduling algorithm  Response time – In an interactive system, amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
  • 16. Optimization Criteria  It is desirable to maximize:  The CPU utilization  The throughput  It is desirable to minimize:  The turnaround time  The waiting time  The response time  However in some circumstances, it is desirable to optimize the minimum or maximum values rather than the average.  Interactive systems, it is more important to minimize the variance in the response time than minimize the average response time.
  • 17. Process Scheduling Algorithms  First-Come, First-Served Scheduling (FCFS)  Shortest-Job-First Scheduling (SJF)  Priority Scheduling  Round-Robin Scheduling  Our measure of comparison is the average waiting time.
  • 18. First-Come, First-Served (FCFS) Scheduling  The process that request the CPU first is allocated the CPU first. Process Burst Time(ms) P1 24 P2 3 P3 3  Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is:  Waiting time for P1 = 0; P2 = 24; P3 = 27  Average waiting time: (0 + 24 + 27)/3 = 17ms P1 P2 P3 24 27 30 0
  • 19. FCFS Scheduling Suppose that the processes arrive in the order P2 , P3 , P1  The Gantt chart for the schedule is:  Waiting time for P1 = 6; P2 = 0; P3 = 3  Average waiting time: (6 + 0 + 3)/3 = 3  Much better than previous case P1 P3 P2 6 3 30 0
  • 20. FCFS Scheduling  FCFS scheduling algorithm is non-preemptive  Once the CPU has been allocated to a process, that process keeps the CPU until it releases the CPU, either by terminating or by requesting I/O.  is particularly troublesome for time-sharing systems (response time ).  Convoy effect (short process behind long process)occurs:  When one CPU-bound process with long CPU burst and many I/O-bound process which short CPU burst.  All I/O bound process waits for the CPU-bound process to get off the CPU while I/O is idle  All I/O- and CPU- bound processes executes I/O operation while CPU is idle.  results in low CPU and device utilization
  • 21. Shortest-Job-First (SJF) Scheduling  SJF associates with each process the length of its next CPU burst.  use these lengths to schedule the process with the shortest time  Two schemes:  non-preemptive – once CPU given to the process it cannot be preempted until completes its CPU burst  preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is known as the Shortest-Remaining-Time-First (SRTF)  SJF is optimal – gives minimum average waiting time for a given set of processes
  • 22. Example of Non-Preemptive SJF Process Burst Time P1 6 P2 8 P3 7 P4 0 3  SJF scheduling chart (non-preemptive)  Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P4 P3 P1 3 16 0 9 P2 24
  • 23. Example of Preemptive SJF (SRTF) Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (preemptive)  Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P3 P2 4 2 11 0 P4 5 7 P2 P1 16
  • 24. How do we know the length of the next CPU burst?  by computing an approximation of the length of the next CPU burst (estimate the length of the next CPU burst)  can be done by using the length of previous CPU bursts, using exponential averaging  The value of tn contains our most recent information.  n+1 stores the past history  The parameter  controls the relative weight of recent and past history in our prediction.   . 1 : Define 4. 1 0 number, real a is 3. burst CPU next for the value predicted 2. burst CPU of lenght actual 1. 1 1 n n n n th n t n t                  
  • 25. Prediction of the Length of the Next CPU Burst  In this example, 0 = 10,  = ½ , t1=6  1 =  x t0 + (1- ) x 0 = ½ x 6 + ½ x 10 = 8  2 =  x t2 + (1- ) x 1 = ½ x 4 + ½ x 8 = 6
  • 26. Examples of Exponential Averaging   = 0  n+1 = n = n-1 = n-2 . … = 0  Recent history does not count   = 1  n+1 = tn  Only the actual last CPU burst counts i.e., the most recent CPU burst  If we expand the formula, we get: n+1 =  tn + (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
  • 27. 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  Non-preemptive
  • 28. Process Burst Time Priority arrival time P1 10 3 0 P2 1 1 0 P3 2 4 0 P4 1 5 0 P5 5 2 0  Priority Scheduling (non-preemptive)  Average waiting time = (0 + 1 + 6 + 16 + 18)/5 = 8.2 Example 1 of Non-Preemptive Priority P2 P1 P3 16 1 0 P4 18 P5 6 19
  • 29. Example 2 of Non-Preemptive Priority Process Ready queue arrive time CPU burst time Priority P1 0 3 ms 5 P2 1 7 ms 3 P3 4 2 ms 4 P4 2 3 ms 3 P5 6 4 ms 1 P1 P5 P2 P3 P4 0 3 17 14 10 19 scheduling chart (non-preemptive) Average waiting time= 31/5 = 6.2 ms Total Waiting time = (0-0) + (3-1) +(17-4) + (14-2) + (10-6) = 0+2+13+12+4=31 ms Total Turnaround time= (3-0) + (10-1) + (19-4) + (17-2) + (14- 6) = 50 ms Average Turnaround time= 50/5 = 10ms
  • 30. Example of Preemptive Priority Process Ready queue arrive time Cpu burst time Priority P1 0 3 ms 5 P2 1 7 ms 3 P3 4 2 ms 4 P4 2 3 ms 3 P5 6 4 ms 1 P3 P5 P2 P1 P4 P2 P1 0 6 13 1 17 10 15 19 scheduling chart (preemptive) Average waiting time= 42/5= 8.4 ms Total Waiting time = (0-0+17-1) + (1-1+13-6) +(15-4) + (10-2) + (6-6) =42ms Total Turnaround time= (19-0) + (15-1) + (17-4) + (13-2) + (10-6) = 61ms Average Turnaround time= 61/5 = 12.2ms Process P1 preempted by p2 because p2 has higher priority
  • 31. Priority Scheduling  SJF is a priority scheduling where priority is the predicted next CPU burst time  Problem  Starvation – low priority processes may never execute  Solution  Aging – as time progresses, increase the priority of the process 127 0
  • 32. Round Robin (RR) Scheduling  It is similar to FCFS scheduling, but preemption is added to enable the system to switch between process.  Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds.  After this time has elapsed, the process is preempted and added to the end of the ready queue.
  • 33.  If CPU cycle (CPU burst time ) > time quantum  Job is preempted and put at the end of the READY Q  If CPU cycle < time quantum  If job finished  resources released  If interrupted by I/O request  Info saved in PCB  Linked at end of appropriate I/O queue  When I/O complete, job returns to READY Q
  • 34. Example of RR with Time Quantum = 4 Process Burst Time Arrival Time P1 24 0 P2 3 0 P3 3 0  The Gantt chart is: P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30 Average waiting time= 17/3= 5.66 ms Total Waiting time = (0-0+10-4) + (4-0) +(7-0) =17ms Total Turnaround time= (30-0) + (7-0) + (10-0) = 47ms Average Turnaround time= 47/5= 9.4 ms Context switch ???
  • 35. Example of RR with Time Quantum = 10  The Gantt chart is: Process Ready queue arrive time CPU burst time P1 0 7 ms P2 1 13 ms P3 5 25 ms P4 6 22 ms P5 8 40 ms 0 17 74 7 27 37 47 50 60 64 P2 P2 P1 P3 P4 P5 P3 P4 P5 79 P3 P5 89 P5 99 Average waiting time= 180/5= 36 ms Total Waiting time = (0-0) + (7-1 + 47-17 )+(17-5+ 50-27+ 74- 60)+(27-6+60-37)+ (37-8+64-47+79-64 ) = 180 ms Total Turnaround time= (7-0) + (50-1) + (79-5)+(64-6)+(99-8) = 279ms Average Turnaround time= 279/5= 55.8 ms
  • 36. Round Robin (RR) Scheduling  Performance depends on the size of the time quantum.  If the time quantum is extremely large, the RR policy is the same as the same as the FCFS policy  If the time quantum is extremely small (say 1 millisec) , the RR approach is called processor sharing i.e., provides high concurrency: each of n processes has its own processor running at 1/n the speed of the real processor
  • 37. Time Quantum and Context Switch Time In (a) the job finishes before the time quantum expires. In (b) and (c), the time quantum expires first, interrupting the job  The effect of context switching on the performance of RR scheduling, for example one process of 10 time quantum.  quantum = 12 time units, finished in less than 1 time quantum  quantum = 6 time units, requires 2 quanta, 1 context switch  quantum = 1 time units, requires 10 quanta, 9 context switch a b c
  • 38. Round Robin (RR) Scheduling  The time quantum q must be large with respect to context switch, otherwise overhead is too high  If the context switching time is 10% of the time quantum, then about 10% of the CPU time will be spent in context switching  Most modern OS have time quanta ranging from 10 to 100 milliseconds,  The time required for a context switch is typically less than 10 microseconds; thus the context-switch time is a small fraction of the time quantum.
  • 39. Turnaround Time varies with the Time Quantum  The turnaround time depends on the size of the time quantum  The average turnaround time of a set of processes dose not necessarily improve as the time quantum size Increased.  The average turnaround time can be improved if most processes finish their next CPU burst in a single time quantum.
  • 40. Scheduling Algorithm with multi-Queues  Multi-level Queue Scheduling  Multi-level Feedback Queue Scheduling
  • 41. Multilevel Queue  Ready queue is partitioned into separate queues: foreground (interactive) background (batch)  The processes are permanently assigned to one queue, generally based on some property, or process type.  Each queue has its own scheduling algorithm  foreground – RR  background – FCFS  Scheduling must be done between the queues  Fixed priority scheduling - serve all from foreground then from background, Possibility of starvation.  Time slice scheduling – 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
  • 42. Multilevel Queue Scheduling  No process in the batch queue could run unless the queues with high priority were all empty.  If an interactive editing process entered the ready queue while a batch process was running, the batch process would be preempted.
  • 43. Multilevel Feedback Queue  A process can move between the various queues; aging can be implemented in this way  Multilevel-feedback-queue scheduler defined by the following parameters:  number of queues  scheduling algorithms for each queue  method used to determine when to upgrade a process  method used to determine when to demote a process  method used to determine which queue a process will enter when that process needs service
  • 44. Example of Multilevel Feedback Queue  Three queues:  Q0 – RR with time quantum 8 milliseconds  Q1 – RR time quantum 16 milliseconds  Q2 – FCFS  Scheduling  A new job enters queue Q0 which is served RR. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.  At Q1 job is again served RR and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.  The job is serverd based on FCFS in queue Q2
  • 46. Summary  CPU scheduling is the task of selecting a waiting process from the ready queue and allocating the CPU to it.  The CPU is allocated to the selected process by the dispatcher.  FCFS scheduling is simple, cause short processes to wait for long time  SJF scheduling is provably optimal, providing the shortest averaging waiting time. But predicting the length of the next CPU bursts is difficult.  Priority scheduling allocates the CPU to the heights priority process.  Both priority and SJF may suffer from starvation. Aging is a technique to prevent starvation.  RR scheduling is more appropriate for a time-shared system.  Major problem of RR scheduling is the selection of the time quantum.  FCFS is non-preemptive, RR is preemptive, SJF and Priority may be preemptive and non-preemptive.  Multilevel queue allows different scheduling algorithm for each queue.  Multilevel feedback queue allow process to move from one queue to another.