07/10/2020 1
Lecture 11
Chapter 2
Processes and Threads
discover yourself
Three- level Scheduling
discover yourself
10/07/2020 3
Robin (RR) Scheduling
Processes are dispatched in a FIFO manner
but are given a limited amount of CPU time
called a time-slice or a quantum.
discover yourself
Robin (RR) Scheduling
1.
list of runable processes
2.
list of runable processes after B uses up its quantum
3.
Length of quantum too short means too much context switching.
discover yourself
10/07/2020 5
Example: The time slot could be 100 milliseconds. If a job1 takes a total time of 250ms to complete, the round-robin scheduler will suspend the job after 100ms and give other jobs their time on the CPU. Once the other jobs have had their equal share (100ms each), job1 will get another allocation of CPU time and the cycle will repeat. This process continues until the job finishes and needs no more time on the CPU.
Job1 = Total time to complete 250ms (quantum 100ms). 1.First allocation = 100ms.
2.Second allocation = 100ms.
3.Third allocation = 100ms but job1 self-terminates after 50ms. 4.Total CPU time of job1 = 250ms.
Round Robin (RR) Scheduling
discover yourself
Round Robin (RR) Scheduling
APPLICATION
Using round-robin scheduling allots a slice of time to each
process that is running. In a computer for example, the user
starts three applications,
, a web browser, and a
word processor
. These applications are loaded into system
memory as processes and each is allowed to run without the
user considering which applications are running in the
background.
discover yourself
10/07/2020 7
Burst Waiting Turnaround Process Time Time Time
P1 24 6 30
P2 3 4 7
P3 3 7 10
Average - 5.66 15.66
Time Quantum= 4ms (without priority)
discover yourself
Time Quantum= 1ms (without priority)
discover yourself
10/07/2020 9
discover yourself
inspire posterity
Process
Burst
P1
8
P2
6
P3
1
P4
9
P5
3
Q-
Assume that you have the following processes all arriving at
time 0:
discover yourself
inspire posterity
Process B.T Priority W.T T.T
P1 8 4 12 20
P2 6 1 16 22
P3 1 2 8 9
P4 9 2 18 27
P5 3 3 13 16
average 67/5=13.4 94/5=18.8
P1
P2
P3
P4
P5
P1
P2
P4
P4
0 4 8 9 13 16 20 22 26 27
10/07/2020 11
discover yourself
inspire posterity
Process
Burst
Priority
P1
8
4
P2
6
1
P3
1
2
P4
9
2
P5
3
3
Q-
Assume that you have the following processes all arriving at
time 0:
discover yourself
inspire posterity
P2
P3
P4
P5
P1
P2
P4
P1
P4
0 4 5 9 12 16 18 22 26 27
Process B.T Priority W.T T.T
P2 6 1 12 18
P3 1 2 4 5
P4 9 2 18 27
P5 3 3 9 12
P1 8 4 18 26
average 12.2 17.6
10/07/2020 13
Time Quantum= 2ms (without priority)
discover yourself
inspire posterity
Process
Arrival
Burst Time
P1
0
3
P2
1
2
P3
2
1
Total Waiting Time = (WT of Process 1)+ (WT of Process 2) + (WT of Process 3) = (3+1+2)s
discover yourself
inspire posterity
Processes Burst time Arrival time
P1 8 0.0
P2 4 1.0
P3 2 2.0
P4 5 3.0
Q-
Assume that you have following processes with arrival time and burst time given in milliseconds.Draw a Gantt chart to determine average process waiting time of each process using round robin scheduling algorithm (Quantum Time = 2ms). Ignore process switching overhead.
10/07/2020 15
Priority Scheduling
1. Each process is assigned a priority, and priority is
allowed to run. Equal-Priority processes are
scheduled in FCFS order.
2. The shortest-Job-First (SJF) algorithm is a special
case of general priority scheduling algorithm.
discover yourself
Priority Scheduling
discover yourself
10/07/2020 17
Burst Waiting Turnaround
Process Time Priority Time Time
P1 10 3 6 16
P2 1 1 0 1
P3 2 4 16 18
P4 1 5 18 19
P5 5 2 1 6
Average - - 8.2 12
discover yourself
inspire posterity
discover yourself
10/07/2020 19
discover yourself
inspire posterity
Process Priority AT BT
P1 2 0 4
P2 4 1 2
P3 6 2 3
P4 10 3 5
P5 8 4 1
P6 12 5 4
P7 9 6 6
Priority Scheduling-Non-Preemptive
EXAMPLE-3
discover yourself
inspire posterity
P1
P4
P6
P7
P5
P3
P2
Process W.T TAT
P1 0 4
P2 22 24
P3 18 21
P4 1 6
P5 15 16
Priority Scheduling-Non-Preemptive
SOLUTION
10/07/2020 21
discover yourself
inspire posterity
Process Priority AT BT
P1 2 0 4
P2 4 1 2
P3 6 2 3
P4 10 3 5
P5 8 4 1
P6 12 5 4
P7 9 6 6
Priority Scheduling-Preemptive
EXAMPLE- 4
discover yourself
inspire posterity
P1
P2
P3
P4
P6
P4
P7
P5
P3
P2
P1
Process W.T TAT RT
P1 21 25 0
P2 19 21 0
P3 16 19 0
P4 4 9 0
P5 14 15 14
Priority Scheduling-Preemptive
SOLUTION
10/07/2020 23
Priority Scheduling
In this example, Tasks B and C are at the same priority, which is higher than that of Task A.
Task A is running when Task B becomes ready to run. Task A is preempted so that Task B can run. While Task B is running, Task C also becomes ready to run. The scheduler therefore allows Task B to run for a time slice period. After this period expires, the scheduler gives Task C an opportunity to run. Then Task C completes its work. Because Task B still has work to complete and has the highest priority of all ready tasks, the scheduler allows Task B to run. Once Task B completes its work, Task A can finish.
discover yourself
HOME READING
HOME READING
1. Multiple Queues Scheduling
2. Fair Share Scheduling
discover yourself
07/10/2020 25