Assignment No. B5
Assignment No. B5
Experiment No: B5
Name of the Student: Roll No:
Marks:
Sign of Teacher
Title: Write a Java program (using OOP features) to implement following scheduling algorithms:
FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive).
Problem Statement: To write programs to implement FCFS, SJF, and Priority & RR Scheduling
Algorithms.
Learning Outcome: After completion of this assignment students will be able to:
How CPU scheduling decides the processing of upcoming process request by
Considering different scheduling algorithms.
Theory:
Problem Explanation:
CPU scheduling deals with the problem of deciding which of the processes in the ready queue
Is to be allowed to utilize the CPU. The criteria for selection for a algorithm are,
1. The maximum throughput
2. Least turnaround time.
1
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
This is the simplest CPU scheduling algorithm. The Process that request the CPU first, is the one to
which it is allocated first. The algorithm is implemented using a job queue. When a process
Requests the CPU it is added at the tail of the job queue.
The CPU is allocated to the process at the head of the queue. However the TAT varies, which is not
favorable.
This algorithm associates with it the length of the next CPU burst. When the CPU is available, it is
assigned to that job with the smallest CPU burst. This algorithm provides the minimum average waiting
time. The major problem with this knows the CPU burst of a job.
2
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
● Priority scheduling is a non-preemptive algorithm and one of the most common scheduling
algorithms in batch systems.
● Each process is assigned a priority. Process with highest priority is to be executed first and so
on.
● Processes with same priority are executed on first come first served basis.
● Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
P0 9-0=9
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
3
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
● The processor is allocated to the job closest to completion but it can be preempted by a newer
ready job with shorter time to completion.
● Impossible to implement in interactive systems where required CPU time is not known.
● It is often used in batch environments where short jobs need to give preference.
Implementation Logic:-
1. Choose how to represent a process & how to keep track of different parameters of all
Processes.
2. Choose with which rules the scheduler will choose the next process.
3. Design an algorithm that applies the above rules. Take into consideration arrival time,
Priority, quantum etc appropriately.
4. Implement the algorithm.
Solve following examples with Gantt Chart & Calculate WT, AWT, TT & ATT:
1) FCFS:-
4
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
Solve following examples with Gantt Chart & Calculate WT, AWT, TT & ATT:
2) SJF:-
5
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
Solve following examples with Gantt Chart & Calculate WT, AWT, TT & ATT:
3) Priority:-
6
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
4) RR:-
Draw Gantt Chart & Calculate the Avg. Turnaround time and Avg. waiting time of the processes on the basis
of round robin scheduling algorithm. Assume Time Quantum is set to 4 units.
7
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
Applications:-
8
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
FCFS:-
___________________________________________________________________________________
___________________________________________________________________________________
SJF:
___________________________________________________________________________________
___________________________________________________________________________________
PRIORITY:
___________________________________________________________________________________
___________________________________________________________________________________
ROUND ROBIN
___________________________________________________________________________________
___________________________________________________________________________________
Conclusion:-
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
LAB QUIZ
1. List types of scheduler & scheduling.
-------------------------------------------------------------------------------------------------------------
9
Shri Chhatrapati Shivaji Maharaj College of Engineering, Nepti SPOSL
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
10