0% found this document useful (0 votes)
42 views11 pages

2 CPU Scheduling

The document discusses CPU scheduling concepts and algorithms. It defines key terms like scheduling criteria, dispatcher, and scheduling algorithms. It then provides examples of First Come First Served (FCFS) scheduling and calculates metrics like turnaround time, waiting time, and average waiting time for different processes arriving in various orders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views11 pages

2 CPU Scheduling

The document discusses CPU scheduling concepts and algorithms. It defines key terms like scheduling criteria, dispatcher, and scheduling algorithms. It then provides examples of First Come First Served (FCFS) scheduling and calculates metrics like turnaround time, waiting time, and average waiting time for different processes arriving in various orders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Dr.

Akhtar Husain
Associate Professor in Department of CSIT,
Faculty of Engineering and Technology,
MJP Rohilkhand University, Bareilly, U.P., India.
Mobile : 9457381048, 9319760019
Email: [email protected]
CPU Scheduling

 Basic Concepts
 Scheduling Criteria
 Scheduling Algorithms
 Thread Scheduling
 Multiple-Processor Scheduling
 Real-Time CPU Scheduling
 Operating Systems Examples
 Algorithm Evaluation

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
Basic Concepts

 Maximum CPU utilization


obtained with multiprogramming
 CPU–I/O Burst Cycle – Process
execution consists of a cycle of
CPU execution and I/O wait
 CPU burst followed by I/O burst
 CPU burst distribution is of main
concern

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
CPU Scheduler
 Short-term scheduler selects from among the processes in
ready queue, and allocates the CPU to one of them
 Queue may be ordered in various ways
 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 nonpreemptive
 All other scheduling is preemptive
 Consider access to shared data
 Consider preemption while in kernel mode
 Consider interrupts occurring during crucial OS activities

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
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

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
Scheduling Criteria

 CPU utilization – keep the CPU as busy as possible


 Throughput –number 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-sharing environment)

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
Scheduling Algorithm Optimization Criteria

 Max CPU utilization


 Max throughput
 Min turnaround time
 Min waiting time
 Min response time

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
First- Come, First-Served (FCFS) Scheduling
Process Burst Time(ms)
P1 15
P2 8
P3 6
Order of Processes arrival : P1 , P2 , P3
Case 1: All the Processes are arrived at same time ( 0 ms)
Gantt Chart:
P1 P2 P3

0 15 23 29
Calculations :
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms
P1 15 0 15 15 0
P2 8 0 23 23 15
P3 6 0 29 29 23
Average =(15+23+29)/3 =(0+15+23)/3
=67/3=22.33 ms =38/3=12.67 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
FCFS Scheduling Continued
• Case 2: Processes arrive at time 0 ms in order of P2, P3 and P1
• Gantt Chart
P2 P3 P1

0 8 14 29

Calculations
Process Burst Time (BT) Arrival Time Completion Time Turn Around Time Waiting Time
Number ms (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P2 8 0 8 8 0

P3 6 0 14 14 8

P1 15 0 29 29 14

Average =(8+14+29)/3 =(0+8+14)/3


=51/3=17 ms =22/3=7.3 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
FCFS Scheduling Continued
Case 3: Processes are arrived in order P1, P2, P3 at times 0 ms, 1 ms, 2 ms.

Gantt Chart:
P1 P2 P3
0 1 2 15 23 29
P1 Arrives
P2 Arrives
P3 Arrives

Calculations:
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 15 0 15 15 0
P2 8 1 23 22 14
P3 6 2 29 27 21
Average =(15+22+27)/3 =(0+14+21)/3
=64/3=21.33 ms =35/3=11.67 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education
FCFS Scheduling Continued
• Case 4: Processes are arrived in order P2, P3, P1 at times 0
ms, 1 ms, 2 ms.

• Gantt Chart:
P2 P3 P1

0 1 2 8 14 29
P2 Arrives
P3 Arrives
P1 Arrives
Calculations:
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P2 8 0 8 8 0
P3 6 1 14 13 7
P1 15 2 29 27 12
Average =(8+13+27)/3 =(0+7+12)/3
=48/3=16 ms =19/3=6.3 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Opera ng


Systems Concepts‖, Wiley 2:Harvey M Dietel, ― An
Introduction to Operating System‖, Pearson Education

You might also like