Ilovepdf Merged
Ilovepdf Merged
Scheduling
Operating System
FCFS Scheduling-
In FCFS Scheduling,
• The process which arrives first in the ready queue is firstly assigned the CPU.
• In case of a tie, process with smaller process id is executed first.
• It is always non-preemptive in nature.
Advantages-
Disadvantages-
Convoy Effect
In convoy effect,
• Consider processes with higher burst time arrived before the processes with smaller burst time.
• Then, smaller processes have to wait for a long time for longer processes to release the CPU.
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
Process Id Arrival time Burst time
P1 3 4
P2 5 3
P3 0 2
P4 5 1
P5 4 3
If the CPU scheduling policy is FCFS, calculate the average waiting time and
average turn around time.
Solution-
Gantt Chart-
Now, we know-
• Turn Around time = Exit time – Arrival time
• Waiting time = Turn Around time – Burst time
Also read- Various Times of Process
P1 7 7–3=4 4–4=0
P2 13 13 – 5 = 8 8–3=5
P3 2 2–0=2 2–2=0
P4 14 14 – 5 = 9 9–1=8
P5 10 10 – 4 = 6 6–3=3
Now,
• Average Turn Around time = (4 + 8 + 2 + 9 + 6) / 5 = 29 / 5 = 5.8 unit
• Average waiting time = (0 + 5 + 0 + 8 + 3) / 5 = 16 / 5 = 3.2 unit
Problem-02:
Consider the set of 3 processes whose arrival time and burst time are given below-
P1 0 2
P2 3 1
P3 5 6
If the CPU scheduling policy is FCFS, calculate the average waiting time and
average turn around time.
Solution-
Gantt Chart-
Now, we know-
• Turn Around time = Exit time – Arrival time
• Waiting time = Turn Around time – Burst time
P1 2 2–0=2 2–2=0
P2 4 4–3=1 1–1=0
P3 11 11- 5 = 6 6–6=0
Now,
• Average Turn Around time = (2 + 1 + 6) / 3 = 9 / 3 = 3 unit
• Average waiting time = (0 + 0 + 0) / 3 = 0 / 3 = 0 unit
Problem-03:
Consider the set of 6 processes whose arrival time and burst time are given below-
P1 0 3
P2 1 2
P3 2 1
P4 3 4
P5 4 5
P6 5 2
If the CPU scheduling policy is FCFS and there is 1 unit of overhead in scheduling
the processes, find the efficiency of the algorithm.
Solution-
Gantt Chart-
Here, δ denotes the context switching overhead.
Now,
• Useless time / Wasted time = 6 x δ = 6 x 1 = 6 unit
• Total time = 23 unit
• Useful time = 23 unit – 6 unit = 17 unit
Efficiency (η)
= Useful time / Total Total
= 17 unit / 23 unit
= 0.7391
= 73.91%
Contents
Practical Problems Based On FCFS Scheduling ........................................................................... 2
Problem-01:............................................................................................................................. 2
Problem-02: ............................................................................................................................ 3
Problem-03: ............................................................................................................................ 4
Practice Problems Based On SJF Scheduling ............................................................................... 5
Problem-01:............................................................................................................................. 5
Problem-02: ............................................................................................................................ 6
Problem-03: ............................................................................................................................ 7
Problem-04: ............................................................................................................................ 8
Problem-05: ............................................................................................................................ 9
Practice Problems Based On Round Robin Scheduling ............................................................. 10
Problem-01:........................................................................................................................... 10
Problem-02: .......................................................................................................................... 11
Problem-03: .......................................................................................................................... 12
Problem-04: .......................................................................................................................... 13
Practice Problems Based On Priority Scheduling ...................................................................... 14
Problem-01:........................................................................................................................... 14
Problem-02: .......................................................................................................................... 15
Practice Problems Based On CPU Scheduling Algorithms......................................................... 16
Problem-01:........................................................................................................................... 16
Problem-02: .......................................................................................................................... 17
Problem-03: .......................................................................................................................... 18
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 1
Practical Problems Based On FCFS Scheduling
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
Solution:
Gantt Chart-
Now, we know
Now,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 2
Problem-02:
Consider the set of 3 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is FCFS, calculate the average waiting time and average
turnaround time.
Solution-
Gantt Chart-
Now, we know
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 3
Problem-03:
Consider the set of 6 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is FCFS and there is 1 unit of overhead in scheduling the
processes, find the efficiency of the algorithm.
Solution-
Gantt Chart-
Efficiency (η)
= Useful time / Total
= 17 unit / 23 unit
= 0.7391
= 73.91%
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 4
Practice Problems Based On SJF Scheduling
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is SJF non-pre-emptive, calculate the average waiting time and
average turnaround time.
Solution-
Gantt Chart-
Now, we know-
Now,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 5
Problem-02:
Consider the set of 5 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is SJF pre-emptive, calculate the average waiting time and
average turnaround time.
Solution-
Gantt Chart-
Now, we know-
Now,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 6
Problem-03:
Consider the set of 6 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is shortest remaining time first, calculate the average waiting time
and average turnaround time.
Solution-
Gantt Chart-
Now, we know-
Now,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 7
Problem-04:
Consider the set of 3 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is SRTF, calculate the average waiting time and average
turnaround time.
Solution-
Gantt Chart-
Now, we know-
Now,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 8
Problem-05:
Consider the set of 4 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is SRTF, calculate the waiting time of process P2.
Solution-
Gantt Chart-
Now, we know-
Thus,
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 9
Practice Problems Based On Round Robin Scheduling
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is Round Robin with time quantum = 2 unit, calculate the average
waiting time and average turnaround time.
Solution-
Gantt Chart-
Ready Queue-
P5, P1, P2, P5, P4, P1, P3, P2, P1
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (13 + 11 + 3 + 6 + 10) / 5 = 43 / 5 = 8.6 unit
Average waiting time = (8 + 8 + 2 + 4 + 7) / 5 = 29 / 5 = 5.8 unit
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 10
Problem-02:
Consider the set of 6 processes whose arrival time and burst time are given below-
Process Id Arrival time Burst time
P1 0 4
P2 1 5
P3 2 2
P4 3 1
P5 4 6
P6 6 3
If the CPU scheduling policy is Round Robin with time quantum = 2, calculate the average
waiting time and average turnaround time.
Solution-
Gantt chart-
Ready Queue-
P5, P6, P2, P5, P6, P2, P5, P4, P1, P3, P2, P1
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (8 + 17 + 4 + 6 + 17 + 13) / 6 = 65 / 6 = 10.84 unit
Average waiting time = (4 + 12 + 2 + 5 + 11 + 10) / 6 = 44 / 6 = 7.33 unit
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 11
Problem-03:
Consider the set of 6 processes whose arrival time and burst time are given below-
Process Id Arrival time Burst time
P1 5 5
P2 4 6
P3 3 7
P4 1 9
P5 2 2
P6 6 3
If the CPU scheduling policy is Round Robin with time quantum = 3, calculate the average
waiting time and average turnaround time.
Solution-
Gantt chart-
Ready Queue-
P3, P1, P4, P2, P3, P6, P1, P4, P2, P3, P5, P4
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (27 + 23 + 30 + 29 + 4 + 15) / 6 = 128 / 6 = 21.33 unit
Average waiting time = (22 + 17 + 23 + 20 + 2 + 12) / 6 = 96 / 6 = 16 unit
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 12
Problem-04:
Four jobs to be executed on a single processor system arrive at time 0 in the order A, B, C, D.
Their burst CPU time requirements are 4, 1, 8, 1 time units respectively. The completion time
of A under round robin scheduling with time slice of one-time unit is-
10
4
8
9
Solution-
Gantt chart-
Ready Queue-
C, A, C, A, C, A, D, C, B, A
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 13
Practice Problems Based On Priority Scheduling
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is priority non-pre-emptive, calculate the average waiting time and
average turnaround time. (Higher number represents higher priority)
Solution-
Gantt Chart-
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (4 + 14 + 10 + 6 + 7) / 5 = 41 / 5 = 8.2 unit
Average waiting time = (0 + 11 + 9 + 1 + 5) / 5 = 26 / 5 = 5.2 unit
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 14
Problem-02:
Consider the set of 5 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is priority pre-emptive, calculate the average waiting time and
average turnaround time. (Higher number represents higher priority)
Solution-
Gantt Chart-
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (15 + 11 + 1 + 5 + 6) / 5 = 38 / 5 = 7.6 unit
Average waiting time = (11 + 8 + 0 + 0 + 4) / 5 = 23 / 5 = 4.6 unit
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 15
Practice Problems Based On CPU Scheduling Algorithms
Problem-01:
Consider three process, all arriving at time zero, with total execution time of 10, 20 and 30
units respectively. Each process spends the first 20% of execution time doing I/O, the next 70%
of time doing computation, and the last 10% of time doing I/O again. The operating system
uses a shortest remaining compute time first scheduling algorithm and schedules a new process
either when the running process gets blocked on I/O or when the running process finishes its
compute burst. Assume that all I/O operations can be overlapped as much as possible. For what
percentage of does the CPU remain idle?
1. 0%
2. 10.6%
3. 30.0%
4. 89.4%
Solution-
Process P1 10 2 7 1
Process P2 20 4 14 2
Process P3 30 6 21 3
= (5 / 47) x 100
= 10.638%
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 16
Problem-02:
Consider the set of 4 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is Shortest Remaining Time First, calculate the average waiting time
and average turnaround time.
Solution-
Gantt Chart-
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (11 + 7 + 7 + 11) / 4 = 36 / 4 = 9 units
Average waiting time = (6 + 4 + 4 + 8) / 4 = 22 / 5 = 4.4 units
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 17
Problem-03:
Consider the set of 4 processes whose arrival time and burst time are given below-
If the CPU scheduling policy is Priority Scheduling, calculate the average waiting time and
average turnaround time. (Lower number means higher priority)
Solution-
Gantt Chart-
Now, we know-
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Now,
Average Turn Around time = (10 + 13 + 6) / 3 = 29 / 3 = 9.67 units
Average waiting time = (6 + 9 + 3) / 3 = 18 / 3 = 6 units
MCA 304 and MSc IT 301 Operating System – CPU Scheduling Algorithm (Problem) 18
Operating System
Q1.
Available
A B C D
2 5 3 2
Process Need
A B C D
P0 0 1 1 0
P1 1 6 5 0
P2 0 1 2 2
P3 1 3 3 0
P4 1 2 4 4
Available
A B C D
3 3 2 1
Process Need
A B C D
P0 2 2 1 1
P1 2 1 3 1
P2 0 2 1 3
P3 0 1 1 2
P4 2 2 3 3
Operating System
Available
A B C D
1 5 2 0
Process Need
A B C D
P0 0 0 0 0
P1 0 7 5 0
P2 1 0 0 2
P3 0 0 2 0
P4 0 6 4 2
Operating System
Available
A B C
3 3 2
Process Need
A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 3