0% found this document useful (0 votes)
23 views15 pages

Chapter#02 - CPU Scheduling

Uploaded by

laibakhaliq492
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)
23 views15 pages

Chapter#02 - CPU Scheduling

Uploaded by

laibakhaliq492
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/ 15

Chapter 2: CPU Scheduling

COURSE INSTRUCTOR:

ENGR. FARHEEN QAZI

COURSE:
COMPUTER APPLICATIONS (CS-353)

DEPARTMENT OF COMPUTER SCIENCE (UBIT)


UNIVERSITY OF KARACHI (UoK)
Today’s Agenda

 Objective
 Scheduling Criteria
 Scheduling Algorithms
Objectives

 To introduce CPU scheduling, which is the basis for multiprogrammed


operating systems

 To describe various CPU-scheduling algorithms

 To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a


particular system
Scheduling Criteria

 CPU utilization – keep the CPU as busy as possible

 Throughput – # of processes that complete their execution per time unit

 Turnaround time – amount of time to execute a particular process

 Waiting time – amount of time a process has been waiting in the ready
queue
Scheduling Algorithm Optimization Criteria

CPU utilization,
Throughput

Turnaround Time,
Waiting Time,
Response Time
First-Come, First-Served (FCFS) Scheduling

Process Burst Time/Execution 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 P2 P3

0 24 27 30

 Waiting time for P1 = 0; P2 = 24; P3 = 27


 Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling (Cont.)

Suppose that the processes arrive in the order:


P2 , P3 , P1
 The Gantt chart for the schedule is:

P2 P3 P1

0 3 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
 Consider one CPU-bound and many I/O-bound processes
Shortest-Job-First (SJF) Scheduling

 Associate with each process the length of its next CPU burst
 Use these lengths to schedule the process with the shortest time
 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
know as the Shortest-Remaining-Time-First (SRTF)
 SJF is optimal – gives minimum average waiting time for a given set of
processes
 The difficulty is knowing the length of the next CPU request
 Could ask the user
Example of SJF (non-preemptive)

Process Arrival Time Burst Time


P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (non-preemptive)

P1 P3 P2 P4

0 3 7 8 12 16

 Average waiting time = (0 + 6 + 3 + 7)/4 = 4


Round Robin

 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 (n-1)q time units.
 Performance
 q large  FIFO
 q small  q must be large with respect to context switch, otherwise
overhead is too high.
Example#01 of RR

Process Burst Time


P1 24
P2 3
P3 3

 The Gantt chart is:


Average waiting time = (6 + 4 + 7)/3 = 5.66 milliseconds.

 Typically, higher average turnaround than SJF, but better response


 q should be large compared to context switch time
 q usually 10ms to 100ms
Example#02 of RR

Process Burst Time


P1 53
P2 17
P3 68
P4 24
 The Gantt chart is:

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

 Typically, higher average turnaround than SJF, but better response


Class Activity # 01

Draw the Gantt Chart and also calculate average waiting time and average
turnaround time of the following algorithms using given table:
1. FCFS
2. SJF(Non-Preemptive)

Process Arrival Time Burst Time


P1 0.0 16
P2 0.3 5
P3 1.0 3
Class Activity # 02

Draw the Gantt Chart and also calculate average waiting time and average
turnaround time of the following algorithms using given table:
1. FCFS
2. SJF(Non-Preemptive)
3. Round Robin (Q=5)

Process Arrival Time Burst Time


P1 2 6
P2 5 3
P3 1 8
P4 0 3
P5 4 4
End of Chapter 2
Thank you

You might also like