Exp3 1
Exp3 1
Exp3 1
EXPERIMENT NO- 3
1. Title:
Write a Java program (using OOP features) to implement following scheduling algorithms: FCFS ,
SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive).
2. Objectives :
- To understand OS & SCHEDULLING Concepts
- To implement Scheduling FCFS, SJF, RR & Priority algorithms
- To study about Scheduling and scheduler
3. Problem Statement :
Write a Java program (using OOP features) to implement following scheduling algorithms: FCFS ,
SJF, Priority and Round Robin .
4. Outcomes:
After completion of this assignment students will be able to:
- Knowledge Scheduling policies
- Compare different scheduling algorithms
5. Software Requirements:
JDK/Eclipse
6. Hardware Requirement:
- M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM ,500GB HDD
7. Theory Concepts:
CPU Scheduling:
• CPU scheduling refers to a set of policies and mechanisms built into the operating systems that govern
the order in which the work to be done by a computer system is completed.
• Scheduler is an OS module that selects the next job to be admitted into the system and next process to
run.
• The primary objective of scheduling is to optimize system performance in accordance with the criteria
deemed most important by the system designers.
What is scheduler?
1. Scheduler in an OS module that selects the next job to be admitted into the system and the next
process to run.
2. Primary objective of the scheduler is to optimize system performance in accordance with the
criteria deemed by the system designers. In short, scheduler is that module of OS which
schedules the programs in an efficient manner.
Necessity of scheduling
• Scheduling is required when no. of jobs are to be performed by CPU.
• Scheduling provides mechanism to give order to each work to be done.
• Primary objective of scheduling is to optimize system performance.
• Scheduling provides the ease to CPU to execute the processes in efficient manner.
Types of schedulers
In general, there are three different types of schedulers which may co-exist in a complex operating
system.
• Long term scheduler
• Medium term scheduler
• Short term scheduler.
What is scheduling?
Scheduling is defined as the process that governs the order in which the work is to be done. Scheduling
is done in the areas where more no. of jobs or works are to be performed. Then it requires some plan i.e.
scheduling that means how the jobs are to be performed i.e. order. CPU scheduling is best example of
scheduling.
Scheduling Criteria :
CPU Utilization:
Keep the CPU as busy as possible. It range from 0 to 100%. In practice, it range from 40 to 90%.
Throughput:
Throughput is the rate at which processes are completed per unit of time.
Turnaround time:
This is the how long a process takes to execute a process. It is calculated as the time gap between the
submission of a process and its completion.
Waiting time:
Waiting time is the sum of the time periods spent in waiting in the ready queue.
Response time:
Response time is the time it takes to start responding from submission time. It is calculated as the
amount of time it takes from when a request was submitted until the first response is produced.
Non-preemptive Scheduling :
In non-preemptive mode, once if a process enters into running state, it continues to execute until it
terminates or blocks itself to wait for Input/Output or by requesting some operating system service.
Preemptive Scheduling :
In preemptive mode, currently running process may be interrupted and moved to the ready State by the
operating system.
When a new process arrives or when an interrupt occurs, preemptive policies may incur greater
overhead than non-preemptive version but preemptive version may provide better service.
It is desirable to maximize CPU utilization and throughput, and to minimize turnaround time, waiting
time and response time.
Disadvantages
Convoy effect occurs. Even very small process should wait for its turn to come to utilize the CPU.
Short process behind long process results in lower CPU utilization.
Throughput is not emphasized.
Note : solve complete e.g. as we studied in practical(above is just sample e.g.). you can take any
e.g.
Easy to implement in Batch systems where required CPU time is known in advance.
Impossible to implement in interactive systems where required CPU time is not known.
The processer should know in advance how much time process will take.
Advantages
It gives superior turnaround time performance to shortest process next because a short job is given
immediate preference to a running longer job.
Throughput is high.
Disadvantages
• Pre-emptive SJF
• Non-pre-emptive SJF
Note : solve complete e.g. as we studied in practical(above is just sample e.g.). you can take any e.g.
In this algorithm, job having less burst time is selected 1st for execution. It is executed for its total
burst time and then the next job having least burst time is selected.
Note : solve complete e.g. as we studied in practical(above is just sample e.g.). you can take any e.g.
Round Robin Scheduling :
Round Robin is the preemptive process scheduling algorithm.
Once a process is executed for a given time period, it is preempted and other process executes for a
given time period.
Disadvantages
Note : solve complete e.g. as we studied in practical(above is just sample e.g.). you can take any
e.g.
Priority Scheduling :
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.
Advantage
Disadvantage
FCFS :
SJF :
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
RR :
Priority Scheduling :
Algorithms :
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time, priority
Step 4: Start the Ready Q according the priority by sorting according to lowest to
highest burst time and process.
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
Step 6: For each process in the ready queue, calculate
(e) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(f) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
(g) Average waiting time = Total waiting Time / Number of process
(h) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
8. Conclusion: