1. Experiment Number: 03
TITLE: CPU Scheduling Algorithms: Shortest Job First (Preemptive) and
Round Robin with different arrival time.
OBJECTIVE:
1. Demonstration of CPU Scheduling algorithm.
2. Implement CPU Scheduling algorithm.
SOFTWARE REQUIREMENTS:
1. LINUX OPERATING SYSTEM LIKE FEDORA/REDHAT/UBUNTU….
2. GNU C Compiler
PROBLEM STATEMENT: Implement the C program for CPU Scheduling
Algorithms: Shortest Job First (Preemptive) and Round Robin with different
arrival time.
THEORY:
Shortest Remaining Time First (SRTF) scheduling
In the Shortest Remaining Time First (SRTF) scheduling algorithm, the
process with the smallest amount of time remaining until completion is
selected to execute. Since the currently executing process is the one with
the shortest amount of time remaining by definition, and since that time
should only reduce as execution progresses, processes will always run until
they complete or a new process is added that requires a smaller amount of
time.
2. Advantage:
1- Short processes are handled very quickly.
2- The system also requires very little overhead since it only makes a
decision when a process completes or a new process is added.
3- When a new process is added the algorithm only needs to compare the
currently executing process with the new process, ignoring all other
processes currently waiting to execute.
Disadvantage:
1- Like shortest job first, it has the potential for process starvation.
2- Long processes may be held off indefinitely if short processes are
continually added.
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
SJF CPU SCHEDULING ALGORITHM :
For SJF scheduling algorithm, read the number of processes/jobs in
the system, their CPU burst times. Arrange all the jobs in order with respect
to their burst times. There may be two jobs in queue with the same
execution time, and then FCFS approach is to be performed. Each process
will be executed according to the length of its burst time. Then calculate the
waiting time and turnaround time of each of the processes accordingly.
ROUND ROBIN CPU SCHEDULING ALGORITHM:
The name of this algorithm comes from the round-robin principle,
where each person gets an equal share of something in turns. It is the
oldest, simplest scheduling algorithm, which is mostly used for multitasking.
In Round-robin scheduling, each ready task runs turn by turn only in a cyclic
queue for a limited time slice. This algorithm also offers starvation free
execution of processes.
3. For round robin scheduling algorithm, read the number of
processes/jobs in the system, their CPU burst times, and the size of the time
slice. Time slices are assigned to each process in equal portions and in
circular order, handling all processes execution. This allows every process to
get an equal chance. Calculate the waiting time and turnaround time of each
of the processes accordingly.
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 quantum/time slice.
The process that is preempted 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 processed. 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.
ALGORITHM
1. Start
2. Declare the array size
3. Read the number of processes to be inserted
4. Read the burst times of the processes
5. Read the Time Quantum
6. If the burst time of a process is greater than time Quantum then subtract
time quantum form the burst time
Else
Assign the burst time to time quantum.
7. Calculate the average waiting time and turnaround time of the processes.
8. Display the values
9. Stop
Note : Solve one example of each algorithm.
CONCLUSION (At least three points):
4. 1. Understood what is CPU scheduling.
2. Studied concept of Preemptive and non-preemptive scheduling.
3. Studied and implemented CPU scheduling algorithm.
REFERENCES:
1. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne, Operating
System Concepts, John Wiley & Sons ,Inc., 9th Edition