SlideShare a Scribd company logo
Selects from among the processes in memory
that are ready to execute, and allocates the CPU
to one of them
 CPU scheduling decisions may take place when
a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates
 Scheduling under 1 and 4 is non preemptive
 All other scheduling is preemptive

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 utilization – keep the CPU as busy as
possible
Throughput – # of processes that complete
their execution per time unit
Turnaround time – amount of time to execute
a particular process
Waiting time – amount of time a process has
been waiting in the ready queue
Response time – amount of time it takes from
when a request was submitted until the first
response is produced, not output (for time-






Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
First-Come, First-Served (FCFS)
 Complete the jobs in order of arrival
 Shortest Job First (SJF)
 Complete the job with shortest next CPU burst
 Priority (PRI)
 Processes have a priority
 Round-Robin (RR)
 Each process gets a small unit of time on CPU
(time quantum or time slice)

Process Burst Time
P1
24
P2
3
P3
3
 Suppose that the processes arrive in the order:
P1 , P2 , P3
The Gantt Chart for the schedule is:
P1
0




P2
24

P3
27

30

Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
Suppose that the processes arrive in the order
P2 , P3 , P1
 The Gantt chart for the schedule is:
P2
0






P3
3

P1
6

30

Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect short process behind long process
Associate with each process the length of its
next CPU burst. When the CPU is available, it is
assigned to the process that has the smallest
next CPU burst
 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



Process Arrival Time Burst Time
P1
0.0
6
P2
0.0
8
P3
0.0
7
P4
0.0
3
SJF scheduling chart
P4
0



P3

P1
3

9

P2
16

24

Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
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
 SJF is a priority scheduling where priority is the
predicted next CPU burst time
 Problem Starvation – low priority processes
may never execute

Process Burst Time

Priority

P1

4

0

1

0

P3

1

10

P2

3

5

Arrival Time

2

0

P2
0

P4

P5
1

P1

1
6

P1

P4

P3

16

18

Average waiting time:
P5
5
(0+1+6+16+18)/5 = 8.2

19

0
0
FCFS (First-come, First-Served)
 Non-preemptive
 SJF (Shortest Job First)
 Can be either
 Choice when a new (shorter) job arrives
 Can preempt current job or not
 Priority
 Can be either
 Choice when a processes priority changes or
when a higher priority process arrives

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 there are n processes in the ready queue and
the time quantum is q, then each process gets
1/n of the CPU time in chunks of at most q time
units at once. No process waits more than (n1)q time units.
 Performance

Process

Burst Time

P1
P2
P3



0
0
0

The Gantt chart is:
P1
0



24
3
3

Arrival

P2
4

P3
7

P1
10

P1
14

P1
18 22

P1
26

P1
30

Average waiting time: (0+4+7+(10-4))/3 =
5.66
With FCFS: (0+24+27)/3 = 17


Ready queue is partitioned into separate
queues:
foreground (interactive)
background (batch)



Each queue has its own scheduling
algorithm
 foreground – RR
 background – FCFS



Scheduling must be done between the
queues

 Fixed priority scheduling; (i.e., serve all from

foreground then from background). Possibility of
starvation.
A process can move between the various
queues; aging can be implemented 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


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 FCFS.

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 FCFS and receives 16
additional milliseconds. If it still does not


The Critical-section Problem



Synchronization Hardware


n processes all competing to use some shared

data
 Each process has a code segment, called critical
section, in which the shared data is accessed.
 Problem – ensure that when one process is
executing in its critical section, no other process
is allowed to execute in its critical section.



Only 2 processes, P0 and P1
General structure of process Pi (other
process Pj)
do {

entry section

critical section

exit section



reminder section
} while (1);
Processes may share some common
variables to synchronize their actions.






Mutual Exclusion. If process Pi is executing in its
critical section, then no other processes can be
executing in their critical sections
Progress. If no process is executing in its critical
section and there exist some processes that wish to
enter their critical section, then the selection of the
processes that will enter the critical section next cannot
be postponed indefinitely
Bounded Waiting. A bound must exist on the number
of times that other processes are allowed to enter their
critical sections after a process has made a request to
enter its critical section and before that requestReturn
is
granted.


Any solution to critical section problem requires
a simple tool or a lock



modern computers provide special hardware
instructions that allow us to test and modify the
content of a word atomically ie as a one
uninterrupted unit



TestAndSet lock and Semaphores are two
examples of H/W tools
Back


Definition:
Boolean TestAndSet (boolean *target)
{
boolean rv = *target;
*target = TRUE;
return rv:
}



Shared Boolean variable lock., initialized to false.
Solution:
do {

while ( TestAndSet (&lock ))
; // do nothing
//

critical section

lock = FALSE;
//
} while (TRUE);

remainder section






Synchronization tool that does not require busy
waiting
Semaphore S – integer variable
Two standard operations modify S: wait() and
signal()
 Originally called P() and V()
Less complicated
Can only be accessed via two indivisible
(atomic) operations
 wait (S) {

while S <= 0
; // no-op
S--;

}
 signal (S) {
S++;
Counting semaphore – integer value can range over
an unrestricted domain
 Binary semaphore – integer value can range only
between 0
and 1; can be simpler to implement
 Also known as mutex locks
 Can implement a counting semaphore S as a binary
semaphore
 Provides mutual exclusion


Semaphore mutex; // initialized to 1
do {
wait (mutex);
// Critical Section
signal (mutex);
// remainder section




Concurrently running processes P1,P2
Executing statement S1 first then S2
int (synch) initialized to 0
S1;
P1
Signal (synch);
Wait (synch);
P2
S2;





Ajay
Anandu
Archith
Abhijith






Subeesh
Sai
Navneeth
Navin

More Related Content

What's hot

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
Ravi Kumar Patel
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
vampugani
 
Priority Scheduling
Priority Scheduling  Priority Scheduling
Priority Scheduling
JawadHaider36
 
Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )
HimanshuSharma1389
 
Chapter 10 - File System Interface
Chapter 10 - File System InterfaceChapter 10 - File System Interface
Chapter 10 - File System Interface
Wayne Jones Jnr
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
Shanu Kumar
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
sathish sak
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Riya Choudhary
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
Kathirvel Ayyaswamy
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
vampugani
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
Shubhashish Punj
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
Damian T. Gordon
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
Edwin Makeu
 
Process Management
Process ManagementProcess Management
Process Management
Christalin Nelson
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
Pawandeep Kaur
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
Shipra Swati
 
Lecture 4 process cpu scheduling
Lecture 4   process cpu schedulingLecture 4   process cpu scheduling
Lecture 4 process cpu scheduling
Kumbirai Junior Muzavazi
 
Process management in os
Process management in osProcess management in os
Process management in osSumant Diwakar
 

What's hot (20)

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Priority Scheduling
Priority Scheduling  Priority Scheduling
Priority Scheduling
 
Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )Process scheduling : operating system ( Btech cse )
Process scheduling : operating system ( Btech cse )
 
Chapter 10 - File System Interface
Chapter 10 - File System InterfaceChapter 10 - File System Interface
Chapter 10 - File System Interface
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
Process Management
Process ManagementProcess Management
Process Management
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Lecture 4 process cpu scheduling
Lecture 4   process cpu schedulingLecture 4   process cpu scheduling
Lecture 4 process cpu scheduling
 
Process management in os
Process management in osProcess management in os
Process management in os
 

Similar to Cpu scheduling

Ch6
Ch6Ch6
Ch6C.U
 
Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Nagarajan
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
Vishnu Prasad
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
ImranKhan880955
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
donny101
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
Binal Parekh
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
Amir Khan
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2pri534
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling gopi7
 
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILEDCPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
VADAPALLYPRAVEENKUMA1
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
Harshit Jain
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
Dr. Mazin Mohamed alkathiri
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
A. S. M. Shafi
 

Similar to Cpu scheduling (20)

OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
OSCh6
OSCh6OSCh6
OSCh6
 
Ch5
Ch5Ch5
Ch5
 
Ch6
Ch6Ch6
Ch6
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
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
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
 
Os..
Os..Os..
Os..
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILEDCPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 

Cpu scheduling

  • 1.
  • 2. Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them  CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates  Scheduling under 1 and 4 is non preemptive  All other scheduling is preemptive 
  • 3. 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 
  • 4.      CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-
  • 5.      Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
  • 6. First-Come, First-Served (FCFS)  Complete the jobs in order of arrival  Shortest Job First (SJF)  Complete the job with shortest next CPU burst  Priority (PRI)  Processes have a priority  Round-Robin (RR)  Each process gets a small unit of time on CPU (time quantum or time slice) 
  • 7. Process Burst Time P1 24 P2 3 P3 3  Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: P1 0   P2 24 P3 27 30 Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17
  • 8. Suppose that the processes arrive in the order P2 , P3 , P1  The Gantt chart for the schedule is: P2 0     P3 3 P1 6 30 Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Convoy effect short process behind long process
  • 9. Associate with each process the length of its next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst  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 
  • 10.  Process Arrival Time Burst Time P1 0.0 6 P2 0.0 8 P3 0.0 7 P4 0.0 3 SJF scheduling chart P4 0  P3 P1 3 9 P2 16 24 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
  • 11. 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  SJF is a priority scheduling where priority is the predicted next CPU burst time  Problem Starvation – low priority processes may never execute 
  • 12. Process Burst Time Priority P1 4 0 1 0 P3 1 10 P2 3 5 Arrival Time 2 0 P2 0 P4 P5 1 P1 1 6 P1 P4 P3 16 18 Average waiting time: P5 5 (0+1+6+16+18)/5 = 8.2 19 0 0
  • 13. FCFS (First-come, First-Served)  Non-preemptive  SJF (Shortest Job First)  Can be either  Choice when a new (shorter) job arrives  Can preempt current job or not  Priority  Can be either  Choice when a processes priority changes or when a higher priority process arrives 
  • 14. 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 there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n1)q time units.  Performance 
  • 15. Process Burst Time P1 P2 P3  0 0 0 The Gantt chart is: P1 0  24 3 3 Arrival P2 4 P3 7 P1 10 P1 14 P1 18 22 P1 26 P1 30 Average waiting time: (0+4+7+(10-4))/3 = 5.66 With FCFS: (0+24+27)/3 = 17
  • 16.  Ready queue is partitioned into separate queues: foreground (interactive) background (batch)  Each queue has its own scheduling algorithm  foreground – RR  background – FCFS  Scheduling must be done between the queues  Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation.
  • 17.
  • 18. A process can move between the various queues; aging can be implemented 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
  • 19.  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 FCFS. 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 FCFS and receives 16 additional milliseconds. If it still does not
  • 20.
  • 22.  n processes all competing to use some shared data  Each process has a code segment, called critical section, in which the shared data is accessed.  Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section.
  • 23.   Only 2 processes, P0 and P1 General structure of process Pi (other process Pj) do { entry section critical section exit section  reminder section } while (1); Processes may share some common variables to synchronize their actions.
  • 24.    Mutual Exclusion. If process Pi is executing in its critical section, then no other processes can be executing in their critical sections Progress. If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely Bounded Waiting. A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that requestReturn is granted.
  • 25.  Any solution to critical section problem requires a simple tool or a lock  modern computers provide special hardware instructions that allow us to test and modify the content of a word atomically ie as a one uninterrupted unit  TestAndSet lock and Semaphores are two examples of H/W tools Back
  • 26.  Definition: Boolean TestAndSet (boolean *target) { boolean rv = *target; *target = TRUE; return rv: }
  • 27.   Shared Boolean variable lock., initialized to false. Solution: do { while ( TestAndSet (&lock )) ; // do nothing // critical section lock = FALSE; // } while (TRUE); remainder section
  • 28.      Synchronization tool that does not require busy waiting Semaphore S – integer variable Two standard operations modify S: wait() and signal()  Originally called P() and V() Less complicated Can only be accessed via two indivisible (atomic) operations  wait (S) { while S <= 0 ; // no-op S--; }  signal (S) { S++;
  • 29. Counting semaphore – integer value can range over an unrestricted domain  Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement  Also known as mutex locks  Can implement a counting semaphore S as a binary semaphore  Provides mutual exclusion  Semaphore mutex; // initialized to 1 do { wait (mutex); // Critical Section signal (mutex); // remainder section
  • 30.    Concurrently running processes P1,P2 Executing statement S1 first then S2 int (synch) initialized to 0 S1; P1 Signal (synch); Wait (synch); P2 S2;