Professional Documents
Culture Documents
Ch. 4 ... Part - 2
Ch. 4 ... Part - 2
System
CH. 4 Services
BY DR. VEEJYA KUMBHAR
Ch. 4 Operating System Services
Syllabus
• Processes ✓
• Process Structure ✓
• Process Scheduling ✓
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Scheduling Algorithms
❑ FCFS (Non-pre-emptive)
❑ SJF ( Pre-emptive and Non-pre-emptive)
❑ Priority ( Pre-emptive and Non-pre-emptive)
❑ Round-Robin ( Pre-emptive)
❑ Multilevel Queue ( Pre-emptive)
❑ Multilevel Feedback Queue( Pre-emptive)
Choosing a scheduling algorithm
Burst Time
Every process in a computer system requires some amount of time for its execution. This
time is both the CPU time and the I/O time. The CPU time is the time taken by CPU to
execute the process. While the I/O time is the time taken by the process to perform some
I/O operation. In general, we ignore the I/O time and we consider only the CPU time for a
process. So, Burst time is the total time taken by the process for its execution on the
CPU.
Arrival time
Arrival time is the time when a process enters into the ready state and is ready for its
execution.
Here in the above example, the arrival time of all the 3 processes are 0 ms, 1 ms, and 2 ms respectively.
Exit time is the time when a process completes its execution and exit from the system.
Gantt Chart
Response Time
Waiting Time
Turnaround Time
Throughput
CPU Utilization
Metrics to evaluate algorithm performance
Response Time
The first response time when the process gets selected
for execution.
Waiting Time
The total time process has spent in the system sitting idle.
Metrics to evaluate algorithm performance
Turnaround Time
It is the total time a process has spent in the system(including burst
time, CPU time, I/O time , waiting time etc.)
Throughput
It is the total no. of processes completed in one unit of time.
CPU Utilization
It is measured as how much time the CPU is busy in executing the
processes.
1. First Come First Serve:
FCFS considered to be the simplest of all operating system scheduling algorithms. First
come first serve scheduling algorithm states that the process that requests the CPU
first is allocated the CPU first and is implemented by using FIFO queue.
Characteristics of FCFS:
•FCFS supports non-preemptive CPU scheduling algorithms.
•Tasks are always executed on a First-come, First-serve concept.
•FCFS is easy to implement and use.
•This algorithm is not much efficient in performance, and the wait time is quite high.
1. First Come First Serve:
Advantages of FCFS:
• Easy to implement
• First come, first serve method
Disadvantages of FCFS:
FCFS suffers from Convoy effect.
The average waiting time is much higher than the other algorithms.
FCFS is very simple and easy to implement and hence not much efficient.
Convoy Effect in OS
Convoy Effect is phenomenon associated with the First Come First Serve
(FCFS) algorithm, in which the whole Operating System slows down due
to few slow processes.
FCFS algorithm is non-preemptive in nature, that is, once CPU time has been
allocated to a process, other processes can get CPU time only after the current
process has finished. This property of FCFS scheduling leads to the situation
called Convoy Effect.
Ex. 1 Schedule following processes using FCFS algorithm
and Calculate response time, waiting time, turnaround
time, completion time of all the processes. Also Calculate
average turnaround time, average waiting time ,
throughput, and CPU utilization.
0 ms
P1
0 ms 8 ms
P1 P2
0 ms 8 ms 15 ms
P1 P2 P3
0 ms 8 ms 15 ms 25 ms
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P1 0 8 0 8 8-0 = 8 8-8 = 8
P2 0 7 8 15 15-0= 15 15-7 = 8
P3 2 10 15 25 25-2 = 23 23-10 = 13
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Shortest job first (SJF) is a scheduling process that selects the waiting process with
the smallest execution time to execute next.
This scheduling method may or may not be preemptive.
Shortest remaining time first(SRTF) is the preemptive version of the Shortest job
first
Characteristics of SJF:
• Shortest Job first has the advantage of having a minimum average waiting time among
all operating system scheduling algorithms.
• It is associated with each task as a unit of time to complete.
• It may cause starvation if shorter processes keep coming. This problem can be solved
using the concept of ageing.
2. Shortest Job First
Advantages of SJF:
As SJF reduces the average waiting time thus, it is better than the first come first serve
scheduling algorithm.
SJF is generally used for long term scheduling.
Disadvantages of SJF:
One of the demerit SJF has, is the starvation.
Many times, it becomes complicated to predict the length of the upcoming CPU
request
Ex. 1 Schedule following processes using SJF (Non Pre-
emptive) algorithm and Calculate response time, waiting
time, turnaround time, completion time of all the
processes. Also Calculate average turnaround time,
average waiting time , throughput, and CPU utilization.
0 ms
P2
0 ms 7 ms
P2 P1
0 ms 7 ms 15 ms
P2 P1 P3
0 ms 7 ms 15 ms 25 ms
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P2 0 7 0 7 7-0 = 7 7-7 = 0
P1 0 8 7 15 15-0= 15 15-8 = 7
P3 2 10 15 25 25-2 = 23 23-10 = 13
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Idle P0 Idle P3
0 ms 2 ms 3 ms 4 ms 6 ms
Idle P0 Idle P3 P2
0 ms 2 ms 3 ms 4 ms 6 ms 9 ms
Idle P0 Idle P3 P2 P1
0 ms 2 ms 3 ms 4 ms 6 ms 9 ms 14 ms
Idle P0 Idle P3 P2 P1 P4
0 ms 2 ms 3 ms 4 ms 6 ms 9 ms 14 ms 21 ms
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P0 2 1 2 3 3-2 = 1 1-1 = 0
P1 5 5 9 14 14 -5= 9 9-5 = 4
P2 5 3 6 9 9-5 = 4 4-3 = 1
P3 4 2 4 6 6-4 = 2 2-2 = 0
p4 4 7 14 21 21-4 = 17 17-7 = 10
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Avg. Turnaround Time = Total Turnaround Time / no. of processes
= 33 / 5 = 6.6 ms
Avg. Waiting Time = Total Waiting Time / no. of processes
= 15 / 6 = 2.6 ms
Throughput = no. of processes /(System Competition Time- System Start Time)-System Idle Time
=5 / ( 21-0-3) = 0.277 = 28 % of a process is completed in 1 unit of time
CPU Utilization = 100 * (System Competition Time- System Start Time- = 100*(21-0-3) / 21
system idle time) / System Completion Time = 0.857 = 86 %
3. Priority Scheduling
Algorithm
3. Priority Algorithm:
Priority Scheduling is a scheduling process that selects the waiting process with the
highest priority (smallest priority number ) for execution.
This scheduling method may or may not be preemptive.
p2 p1 p3 p2
0 ms 1 ms 4 ms 11 ms 12 ms
p2 p1 p3 p2 p5
0 ms 1 ms 4 ms 11 ms 12 ms 14 ms
p2p4 p1 p3 p2 p5 p4
0 ms 1 ms 4 ms 11 ms 12 ms 14 ms 14 ms
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P1 0 4 0 4 4-0=4 4-4 = 0
P2 0 3 11 14 14 -0= 14 14-3 = 11
P3 3 7 4 11 11-3 = 8 8-7 = 1
p4 11 4 16 20 20-11 = 9 9-4 = 5
p5 12 2 14 16 16-12 = 4 4-2 = 2
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Avg. Turnaround Time = Total Turnaround Time / no. of processes
= 39 / 5 = 7.5 ms
Avg. Waiting Time = Total Waiting Time / no. of processes
= 19 / 5 = 3.8 ms
Throughput = no. of processes /(System Competition Time- System Start Time)-System Idle Time
=5 / ( 20-0-0) = 0.25 = 25 % of a process is completed in 1 unit of time
CPU Utilization = 100 * (System Competition Time- System Start Time- = 100*(20-0-0) / 20
system idle time) / System Completion Time = 100 %
3. Priority Scheduling
Algorithm
(Pre-emptive)
Ex. 1 Schedule following processes using Priority (Pre-
emptive) algorithm and Calculate response time, waiting
time, turnaround time, completion time of all the
processes. Also Calculate average turnaround time,
average waiting time , throughput, and CPU utilization.
Process Priority Burst Time Arrival Time
P1 1 (highest) 4 1
P2 4 3 0
P3 1 7 3
P4 3 4 11
P5 2 2 12
Burst Arrival
Process
p2 Time Time
0 ms 1 ms P1 4 1
P2 3 0
p2 p1 P3 7 3
0 ms 1 ms 3 ms P4 4 11
P5 2 12
p2 p1 p3
0 ms 1 ms 3 ms 5 ms
p2 p1 p3 p2
0 ms 1 ms 3 ms 5 ms 7 ms
p2 p1 p3 p2 p1
0 ms 1 ms 3 ms 5 ms 7 ms 9 ms
p2 p1 p3 p2 p1 p3
0 ms 1 ms 3 ms 5 ms 7 ms 9 ms 11 ms
p2 p1 p3 p2 p1 p3 p4 p5
0 1 3 5 7 9 11 13 15
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P1 1 4 1 5 5-1=4 4-4 = 0
P2 0 3 0 20 20 -0= 20 20-3 = 17
P3 3 7 5 12 12-3 = 9 9-7 = 2
p4 11 4 14 18 18-11 = 7 7-4 = 3
p5 12 2 12 14 14-12 = 2 2-2 = 0
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Avg. Turnaround Time = Total Turnaround Time / no. of processes
= 42 / 5 = 8.4 ms
Avg. Waiting Time = Total Waiting Time / no. of processes
= 22 / 5 = 4.4 ms
Throughput = no. of processes /(System Competition Time- System Start Time)-System Idle Time
=5 / ( 20-0-0) = 0.25 = 25 % of a process is completed in 1 unit of time
CPU Utilization = 100 * (System Competition Time- System Start Time- = 100*(20-0-0) / 20
system idle time) / System Completion Time = 100 %
4. Round – Robin
Algorithm
4. Round Robin Algorithm:
Round Robin is a CPU scheduling algorithm where each process is cyclically assigned
a fixed time slot.
It is the preemptive version of First come First Serve CPU Scheduling algorithm.
Round Robin CPU Algorithm generally focuses on Time Sharing technique.
p2 p1 p3 p2
0 ms 2 ms 4 ms 6 ms 7 ms
p2 p1 p3 p2 p1
0 ms 2 ms 4 ms 6 ms 7 ms 9 ms
p2 p1 p3 p2 p1 p3
0 ms 2 ms 4 ms 6 ms 7 ms 9 ms 11 ms
p2 p1 p3 p2 p1 p3 p4 p5
0 2 4 6 7 9 11 13 15
p2 p1 p3 p2 p1 p3 p4 p5 p3 p4 p3
0 2 4 6 7 9 11 13 15 17 19 20
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P1 1 4 2 7-1=6
7 4-4 = 0
P2 0 3 0 9 -0= 9
9 20-3 = 17
P3 3 7 4 20 -3 = 17 9-7 = 2
20
p4 11 4 11 19 -11 = 7-4 = 3
19
p5 12 2 13 715 -12 = 2-2 = 0
15
2
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time
Avg. Turnaround Time = Total Turnaround Time / no. of processes
= 42 / 5 = 8.4 ms
Avg. Waiting Time = Total Waiting Time / no. of processes
= 22 / 5 = 4.4 ms
Throughput = no. of processes /(System Competition Time- System Start Time)-System Idle Time
=5 / ( 20-0-0) = 0.25 = 25 % of a process is completed in 1 unit of time
CPU Utilization = 100 * (System Competition Time- System Start Time- = 100*(20-0-0) / 20
system idle time) / System Completion Time = 100 %
5. Multiple /Multiple Queue
Processes in the ready queue can be divided into different classes where each class has
its own scheduling needs.
For example, a common division is a foreground (interactive) process and
a background (batch) process.
These two classes have different scheduling needs.
For this kind of situation Multilevel Queue Scheduling is used.
5. Multiple /Multiple Queue
Advantages :
The main merit of the multilevel queue is that it has a low scheduling overhead.
Disadvantages :
• Starvation problem
• It is inflexible in nature
6. Multilevel Feedback Queue
Advantages :
• It is more flexible
• It allows different processes to move between different queues
Disadvantages :
• It also produces CPU overheads
• It is the most complex algorithm.
Algorithm Average waiting
Allocation is Complexity Preemption Starvation Performance
time (AWT)
According to the arrival
Simple and easy to
FCFS time of the processes, the
implement
Large. No No Slow performance
CPU is allocated.
According to the process More complex than the Good performance but
MLQ that resides in the bigger priority scheduling Smaller than FCFS No Yes contain a starvation
queue priority algorithms problem