Assignment No.
3
Date:
TITLE:
Implement the C program for CPU Scheduling Algorithms: Shortest Job First (Preemptive) and
Round Robin with different arrival time.
OBJECTIVE:
To understand the concept of process management and scheduling.
Apply the concepts of process scheduling.
SOFTWARE REQUIREMENTS:
1. Ubuntu 16.04
2. GNU C Compiler
THEORY:
Process Scheduling
• Non-preemptive
– Once a process is in the running state, it will continue until it terminates or blocks
itself for I/O
• Preemptive
– Currently running process may be interrupted and moved to ready state by the OS
– Preemption may occur when new process arrives, on an interrupt, or periodically.
Shortest job first (SJF):
Shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process
with the smallest execution time to execute next. SJN is a non-preemptive algorithm.
Shortest Job first has the advantage of having a minimum average waiting time among all
scheduling algorithms.
It is a Greedy Algorithm.
It may cause starvation if shorter processes keep coming. This problem can be solved using
the concept of ageing.
It is practically infeasible as Operating System may not know burst time and therefore may
not sort them. While it is not possible to predict execution time, several methods can be used
to estimate the execution time for a job, such as a weighted average of previous execution
times. SJF can be used in specialized environments where accurate estimates of running time
are available.
Algorithm:
1. Sort all the process according to the arrival time.
2. Then select that process which has minimum arrival time and minimum Burst time.
3. After completion of process make a pool of process which after till the completion of previous
process and select that process among the pool which is having minimum Burst time.
How to compute below times in SJF using a program?
1. Completion Time: Time at which process completes its execution.
2. Turn Around Time: Time Difference between completion time and arrival time. Turn Around
Time = Completion Time – Arrival Time
3. Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
Round Robin is a CPU scheduling algorithm
Round Robin is a CPU scheduling algorithm where each process is assigned a fixed time slot in a
cyclic way.
It is simple, easy to implement, and starvation-free as all processes get fair share of CPU.
One of the most commonly used technique in CPU scheduling as a core.
It is preemptive as processes are assigned CPU only for a fixed slice of time at most.
The disadvantage of it is more overhead of context switching.
Characteristics of Round-Robin Scheduling
Here are the important characteristics of Round-Robin Scheduling:
Round robin is a pre-emptive algorithm
The CPU is shifted to the next process after fixed interval time, which is called time quan-
tum/time slice.
The process that is pre-empted is added to the end of the queue.
Round robin is a hybrid model which is clock-driven
Time slice should be minimum, which is assigned for a specific task that needs to be pro-
cessed. However, it may differ OS to OS.
It is a real time algorithm which responds to the event within a specific time limit.
Round robin is one of the oldest, fairest, and easiest algorithm.
Widely used scheduling method in traditional OS.
Conclusion: Thus we have studied and Implemented Page Replacement Algorithms: FCFS, LRU,
and Optimal for frame size as minimum three.