SlideShare a Scribd company logo
1 of 3
Download to read offline
Priority Scheduling
Priority scheduling is one of the most common scheduling algorithms in batch systems. Each
process is assigned a priority. Process with the highest priority is to be executed first and so on.
Processes with the same priority are executed on first come first served basis. Priority can be
decided based on memory requirements, time requirements or any other resource requirement.
Implementation:
1. First input the processes with their burst time and priority.
2. Sort the processes, burst time and priority according to the
priority.
3. Now simply apply FCFS algorithm.
Example
Consider the following processes and their CPU burst time and find out average waiting time and
average turnaround time using priority scheduling algorithm (Lower number represents higher
priority).
 According to priority scheme, process having highest priority will get the CPU first. In our
example, process P3 has the highest priority (lower number) so P3 will be selected first for
execution so waiting time for P3 will be zero. It will execute for five milliseconds after that
next highest priority process is P4 so it will get the CPU next and waiting time for P4 will
be five milliseconds i.e. the completion time of P3.
 Next turn is for process P2 after the completion of both process P3 and P4 so waiting time
for process P2 will be 5 + 7(burst time of P3 and P4 ) = 12 milliseconds. Next comes
process P5 with priority number 4 and having burst time of 3 milliseconds. Waiting time
for P5 will be 5 + 7 + 4 = 16.
 Finally process P1 will get the CPU after waiting for 19 milliseconds (5 + 7 + 4 + 3). It
will execute for 9 milliseconds so all process will be completed in total 28 milliseconds
(i.e. 5 + 7 + 4 + 3 + 9 = 28 ).
It can be represented in gantt chart as follow:
Process Burst Time Priority
Waiting
Time
Completion
Time
Turnaround
Time
P1 9 5 19 – 0 = 19 28 9 + 19 = 28
P2 4 3 12 - 0 = 12 16 4 + 12 = 16
P3 5 1 0 - 0 = 0 5 5 + 0 = 5
P4 7 2 5 - 0 = 5 12 7 + 5 = 12
P5 3 4 16 - 0 = 16 19 3 + 16 = 19
Total 52 80 80
Average 10.4 16 16
Round-Robin Scheduling
Round Robin(RR) scheduling algorithm is mainly designed for time-sharing systems. This
algorithm is similar to FCFS scheduling, but in Round Robin(RR) scheduling, preemption is added
which enables the system to switch between processes.
1. A fixed time is allotted to each process, called a quantum, for execution.
2. Once a process is executed for the given time period that process is preempted and another
process executes for the given time period.
3. Context switching is used to save states of preempted processes.
4. This algorithm is simple and easy to implement and the most important is thing is this
algorithm is starvation-free as all processes get a fair share of CPU.
5. It is important to note here that the length of time quantum is generally from 10 to 100
milliseconds in length.
Steps to find waiting times of all processes:
1. Create an array rem_bt[] to keep track of remaining burst
time of processes. This array is initially a copy of bt[]
(burst times array)
2. Create another array wt[] to store waiting times of
processes. Initialize this array as 0.
3. Initialize time : t = 0
4. Keep traversing the all processes while all processes are
not done. Do following for i'th process if it is not done
yet.
a. If rem_bt[i] > quantum
(i) t = t + quantum
bt_rem[i] -= quantum;
b. Else // Last cycle for this process
t = t + bt_rem[i];
wt[i] = t - bt[i]
bt_rem[i] = 0; // This process is over
Once we have waiting times, we can compute turn around time tat[i]
of a process as sum of waiting and burst times, i.e., wt[i] +
bt[i]
Example
Process Burst Time
P1 5
P2 4
P3 1
P4 6
Time Slice=2ms
P1 P2 P3 P4 P1 P2 P4 P1 P4
0 2 4 5 7 9 11 13 14 16
Process Burst Time Waiting Time
Completion
Time
Turnaround
Time
P1 5
(0 - 0) + (7 - 2) +
(13 - 9) = 9
14 14
P2 4
(2 - 0) + (9 - 4) =
7
11 11
P3 1 (4 - 0) = 4 5 5
P4 6
(5 - 0) + (11 - 7)
+ (14 - 13) = 10
16 16
Total 30 46 46
Average 7.5 11.5 11.5

More Related Content

What's hot

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 

What's hot (20)

Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Operating system
Operating systemOperating system
Operating system
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
 
9 cm402.19
9 cm402.199 cm402.19
9 cm402.19
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
first come first serve scheduling in os
first come first serve scheduling in os first come first serve scheduling in os
first come first serve scheduling in os
 
Comparision of different Round Robin Scheduling Algorithm using Dynamic Time ...
Comparision of different Round Robin Scheduling Algorithm using Dynamic Time ...Comparision of different Round Robin Scheduling Algorithm using Dynamic Time ...
Comparision of different Round Robin Scheduling Algorithm using Dynamic Time ...
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
Round-ribon algorithm presntation
Round-ribon algorithm presntationRound-ribon algorithm presntation
Round-ribon algorithm presntation
 
shortest job first
shortest job firstshortest job first
shortest job first
 
Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
cpu scheduling OS
 cpu scheduling OS cpu scheduling OS
cpu scheduling OS
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Os module 2 ba
Os module 2 baOs module 2 ba
Os module 2 ba
 

Similar to RR and priority scheduling

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
Yogesh Santhan
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
tech2click
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
gopi7
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
Nagarajan
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
pri534
 

Similar to RR and priority scheduling (20)

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
 
Ch5 answers
Ch5 answersCh5 answers
Ch5 answers
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
 
Os..
Os..Os..
Os..
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Unit 2 notes
Unit 2 notesUnit 2 notes
Unit 2 notes
 
Ch5
Ch5Ch5
Ch5
 
Cpu_sheduling.pptx
Cpu_sheduling.pptxCpu_sheduling.pptx
Cpu_sheduling.pptx
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
 

More from A. S. M. Shafi

More from A. S. M. Shafi (20)

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Projection
ProjectionProjection
Projection
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
 
Fragmentation
FragmentationFragmentation
Fragmentation
 
File organization
File organizationFile organization
File organization
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
1D Array
1D Array1D Array
1D Array
 
2D array
2D array2D array
2D array
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Queue
QueueQueue
Queue
 
Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
 
Quick sort
Quick sortQuick sort
Quick sort
 
N queens problem
N queens problemN queens problem
N queens problem
 
MST
MSTMST
MST
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

RR and priority scheduling

  • 1. Priority Scheduling Priority scheduling is one of the most common scheduling algorithms in batch systems. Each process is assigned a priority. Process with the highest priority is to be executed first and so on. Processes with the same priority are executed on first come first served basis. Priority can be decided based on memory requirements, time requirements or any other resource requirement. Implementation: 1. First input the processes with their burst time and priority. 2. Sort the processes, burst time and priority according to the priority. 3. Now simply apply FCFS algorithm. Example Consider the following processes and their CPU burst time and find out average waiting time and average turnaround time using priority scheduling algorithm (Lower number represents higher priority).  According to priority scheme, process having highest priority will get the CPU first. In our example, process P3 has the highest priority (lower number) so P3 will be selected first for execution so waiting time for P3 will be zero. It will execute for five milliseconds after that next highest priority process is P4 so it will get the CPU next and waiting time for P4 will be five milliseconds i.e. the completion time of P3.  Next turn is for process P2 after the completion of both process P3 and P4 so waiting time for process P2 will be 5 + 7(burst time of P3 and P4 ) = 12 milliseconds. Next comes process P5 with priority number 4 and having burst time of 3 milliseconds. Waiting time for P5 will be 5 + 7 + 4 = 16.  Finally process P1 will get the CPU after waiting for 19 milliseconds (5 + 7 + 4 + 3). It will execute for 9 milliseconds so all process will be completed in total 28 milliseconds (i.e. 5 + 7 + 4 + 3 + 9 = 28 ).
  • 2. It can be represented in gantt chart as follow: Process Burst Time Priority Waiting Time Completion Time Turnaround Time P1 9 5 19 – 0 = 19 28 9 + 19 = 28 P2 4 3 12 - 0 = 12 16 4 + 12 = 16 P3 5 1 0 - 0 = 0 5 5 + 0 = 5 P4 7 2 5 - 0 = 5 12 7 + 5 = 12 P5 3 4 16 - 0 = 16 19 3 + 16 = 19 Total 52 80 80 Average 10.4 16 16 Round-Robin Scheduling Round Robin(RR) scheduling algorithm is mainly designed for time-sharing systems. This algorithm is similar to FCFS scheduling, but in Round Robin(RR) scheduling, preemption is added which enables the system to switch between processes. 1. A fixed time is allotted to each process, called a quantum, for execution. 2. Once a process is executed for the given time period that process is preempted and another process executes for the given time period. 3. Context switching is used to save states of preempted processes. 4. This algorithm is simple and easy to implement and the most important is thing is this algorithm is starvation-free as all processes get a fair share of CPU. 5. It is important to note here that the length of time quantum is generally from 10 to 100 milliseconds in length. Steps to find waiting times of all processes: 1. Create an array rem_bt[] to keep track of remaining burst time of processes. This array is initially a copy of bt[] (burst times array) 2. Create another array wt[] to store waiting times of processes. Initialize this array as 0. 3. Initialize time : t = 0 4. Keep traversing the all processes while all processes are not done. Do following for i'th process if it is not done yet. a. If rem_bt[i] > quantum (i) t = t + quantum bt_rem[i] -= quantum;
  • 3. b. Else // Last cycle for this process t = t + bt_rem[i]; wt[i] = t - bt[i] bt_rem[i] = 0; // This process is over Once we have waiting times, we can compute turn around time tat[i] of a process as sum of waiting and burst times, i.e., wt[i] + bt[i] Example Process Burst Time P1 5 P2 4 P3 1 P4 6 Time Slice=2ms P1 P2 P3 P4 P1 P2 P4 P1 P4 0 2 4 5 7 9 11 13 14 16 Process Burst Time Waiting Time Completion Time Turnaround Time P1 5 (0 - 0) + (7 - 2) + (13 - 9) = 9 14 14 P2 4 (2 - 0) + (9 - 4) = 7 11 11 P3 1 (4 - 0) = 4 5 5 P4 6 (5 - 0) + (11 - 7) + (14 - 13) = 10 16 16 Total 30 46 46 Average 7.5 11.5 11.5