Professional Documents
Culture Documents
Unit2 CPU Scheduling
Unit2 CPU Scheduling
Basic Concept
Non-Preemptive
Preemptive
Non-Preemptive or Cooperative Scheduling
Once the CPU is allocated to a process, process keeps
the CPU until:
it releases when it completes
by switching to waiting state
E.g : 1. Windows 3.x and Apple Macintosh operating
systems uses non-preemptive scheduling
2. Windows (also 10) uses a round-robin technique with
a multi-level feedback queue for priority scheduling
Process is executed till completion. It cannot be
interrupted.
Eg First In First Out
Preemptive Scheduling
The running process is interrupted for some
time and resumed later on, when the priority
task has finished its execution.
16
First-Come, First-Served (FCFS)
P1 P2 P3 AWT = (0+24+27)/3
= 17
0 24 27 30
P2 P3 P1 AWT = (6+0+3)/3
=3
0 3 6 30
Example: First-Come, First-Served (FCFS)
Shortest Job First
Processes with least execution time are selected first.
CPU is assigned to process with less CPU burst time.
SJF:
Non-Preemption: CPU is always allocated to the process with least
burst time and Process Keeps CPU with it until it is completed.
P1 P3 P2 P4
0
• Average 3 time = [0
waiting 7 + (8-2)
8 + 3 +12
7]/4 = 4 16
Shortest Job First(Non-Preemptive)
Q1. Consider foll. Processes with A.T and B.T
Process A.T B.T
P1 1 7
P2 2 5
P3 3 1
P4 4 2
P5 5 8
Cal. Completion time, turn around time and avg. waiting time.
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
• SJF (preemptive)
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
P1 burst time: 15
P2 burst time: 8
P3 burst time: 10
P4 burst time: 3
27
Practice: Shortest Job First (Preemption)
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Practice: Shortest Job First
(Preemption)
P2 P5 P1 P3 P4
0 1 6 16 18 19
AWT = (6+0+16+18+1)/5=8.2
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 1 5 4
P2 2 7 2 Consider 4 as
P3 3 4 3 Highest and 7
as Lowest
Priority
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 0 2 10
P2 2 1 5 Consider 3 as
P3 3 0 2 Lowest and 0
P4 5 3 20 as Highest
Priority
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 1 4 4
P2 2 5 2 Consider 4 as
P3 2 7 3 Lowest and 8
P4 3 8 5 as Highest
P5 3 5 1 Priority
P6 4 6 2
Round Robin Scheduling
A Time Quantum is associated to all processes
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
P1 0 5 10
P2 1 7 13
P3 2 1 5
P1 0 3
P2 3 4
P3 4 6
Round Robin
P1 0 4
P2 1 5
P3 2 2
P4 3 1
P5 4 6
P6 6 3
Time Quantum and Context Switch
Time
Turnaround Time Varies With The
Time Quantum
531512
15+
8+
9+
17 = 49
49/4 = 12.25
Multilevel Queue
A multilevel queue scheduling algorithm partitions
the ready queue into several separate queues.
1. System processes
2. Interactive processes
3. Interactive editing processes
4. Batch processes
5. Student/ user processes
Multilevel Queue
A process can move between various queues
Multilevel Queue Scheduler defined by the following
parameters:
No. of queues
Scheduling algorithms for each queue
Method used to determine when to upgrade / demote
a process
Method used to determine which queue a process
will enter and when that process needs service.
Multilevel Queue
Example:
Disadvantages:
1. Until high priority queue is not empty, No process from
lower priority queues will be selected.
2. Starvation for lower priority processes
Advantage:
Can apply separate scheduling algorithm for each queue.
Practice: Multilevel Queue
Process Arrival Burst Queue
Time Time
P1 0 4 1
P2 0 3 1
P3 0 8 2
P4 10 5 1
1. Asymmetric multiprocessing
1. Processor Affinity
(a process has an affinity for the processor on which it is currently
running.)
Consider what happens to cache memory when a process
has been running on a specific processor?
1. Processor Affinity
1. Processor Affinity
2. Hard affinity
Assign a processor to a particular process and do not allow it
to migrate. Guarantees that process will remain on a single
processor.
Issues concerning SMP systems
Hard affirnity
Example:
2. Load Balancing
2. Load Balancing
2. Load Balancing
3. Multicore Processors
3. Multicore Processors
3. Multicore Processors
3. Multicore Processors
Memory Stall
If one thread stalls while waiting for memory, the core can
switch to another thread.
Real Time Scheduling
A real-time operating system (RTOS) is intended to serve real-time
applications that process data without buffer delays.
Example
When more than one task is available for execution, the one
with the shortest period is serviced first.
• The execution time, C, is the amount of processing time required for each
Occurrence of the task.
Rate-Monotonic Scheduling
rate-monotonic scheduling assumes that the processing time of
a periodic process is the same for each CPU burst.
For example
Consider P1, P2 with time period 50,100 resp. and B.T 20,35
resp.
Cal. CPU utilization of each process and total CPU
utilization.
Sol:
CPU utilization=(Burst time/Time period)= (Ti/Pi)
For P1: (20/50)=0.40 i.e 40%
For P2: (35/100)=0.35 i.e 35%
Total CPU utilization is 75%
Rate-Monotonic Scheduling
rate-monotonic scheduling assumes that the processing time of
a periodic process is the same for each CPU burst.
For example
Consider t1,t2,t3 with time period 100,150,350 resp. and B.T
20,40,100 resp. U1, U2, U3 ?
Rate-Monotonic Scheduling
Consider 2 processes P1 , P2. Time Period: 50,100 resp. Burst
time: 20,35. Schedule processes using Rate monotonic
scheduling
Consider 2 processes P1 , P2. Time Period: 50,70 resp. Burst time: 20,35. Schedule
processes using Rate monotonic scheduling
Rate-Monotonic Scheduling
Rate-monotonic scheduling has a limitation:
The earlier the deadline, the higher the priority the later the
deadline, the lower the priority.