OS Lab Final Assignment
OS Lab Final Assignment
Course Code:CSE2306
Section: 05
Submitted To :
Khairum Islam
Lecturer, Dept of CSE
University of Liberal Arts Bangladesh
Submitted By:
Maria Khan Oishi (221014054)
Report on CPU Scheduling Algorithms
Introduction
CPU scheduling is an essential concept in operating systems, responsible for
managing the execution of processes in an optimal manner. Various scheduling
algorithms exist to ensure efficient CPU utilization and minimize metrics such as
turnaround time and waiting time. This report evaluates the performance of several
algorithms:
The goal is to analyze their effectiveness using average turnaround time and average
waiting time as key metrics, under different conditions.
Implementation
The scheduling algorithms were implemented in C using a structure to represent each
process, which includes properties like arrival time (AT), burst time (BT), priority, and
completion status. The following algorithms were implemented:
1. SJF (Shortest Job First): This algorithm prioritizes processes with the shortest
burst time. It can be either preemptive or non-preemptive. In the non-
preemptive version implemented here, processes are sorted by arrival time,
and the process with the shortest burst time is executed next.
2. FCFS (First-Come, First-Served): Executes processes in the order they
arrive. No priority or burst time comparison is considered. The processes are
sorted by arrival time and executed sequentially.
3. Priority Scheduling: Processes are executed based on their priority. The
process with the highest priority (smallest value) is chosen first, and ties are
resolved by arrival time. If two processes have the same arrival time and
priority, the one with the shorter burst time is selected.
4. Round Robin (RR): This preemptive algorithm assigns each process a time
quantum and cycles through processes, executing each for a set time slice. If a
process isn't finished, it is added back to the queue for the next cycle.
Given Input:
Explanation:
● Turnaround Time (TAT): CT - AT
● Waiting Time (WT): TAT - BT
● Averages:
○ Avg. TAT: (5 + 9 + 5) / 3 = 6.333
○ Avg. WT: (0 + 6 + 3) / 3 = 3.000
Explanation:
Explanation:
● Turnaround Time (TAT): The total time taken by a process from arrival to
completion.
● Waiting Time (WT): The total time a process spends in the ready queue before
execution.
The following table summarizes results from a typical run with three processes:
Discussion
The experiments conducted each algorithm has strengths and weaknesses depending
on the situation, as reflected in the program's outputs for turnaround time and waiting
time.
SJF in the code is great for minimizing both turnaround and waiting times because it
selects processes with the shortest burst times first. This is especially useful when
there are many short tasks, as it significantly reduces the overall waiting time.
However, the SJF algorithm can lead to starvation for longer processes. If shorter
processes keep arriving, the longer ones may be delayed indefinitely. The SJF
implementation in your code reflects this, as it sorts the processes by burst time and
schedules the smallest first, making it very efficient for reducing average waiting time
in ideal scenarios.
FCFS, implemented in the code by sorting processes by their arrival time, is simple
and ensures fairness by executing tasks in the order they arrive. However, it results in
relatively high waiting times for processes that arrive later, especially if the first
process has a long burst time. For example, if a long-running process arrives first, all
subsequent processes must wait until it finishes, which can lead to inefficiency, as
shown in the results generated by the FCFS function in your program.
Round Robin implemented in the code, with its queue-based implementation, is well-
suited for systems where fairness and responsiveness are key. It ensures that each
process gets a chance to run by allocating a small time quantum for each process
before moving to the next one. However, as reflected in the output, the choice of time
quantum has a significant impact on performance. If the quantum is too short,
excessive context switching between processes can lead to inefficiency and higher
waiting times. On the other hand, a larger quantum may reduce fairness, making the
system behave more like FCFS, where processes may wait longer than necessary for
their next turn.
Moreover, the code's results show that burst time plays a critical role in the
performance of SJF and Priority Scheduling, since both algorithms rely heavily on
burst times or priority values to make decisions. In contrast, FCFS remains unaffected
by the differences in burst times, simply following arrival order, while Round Robin is
influenced by both the number of processes and the time quantum, requiring careful
tuning to achieve optimal performance.
In conclusion,the CPU scheduling algorithm clearly demonstrates the trade-offs
involved in each scheduling algorithm. SJF excels in reducing turnaround and waiting
times but may lead to starvation. FCFS is simple but can be inefficient for processes
arriving later. Priority Scheduling offers flexibility but can result in poor performance if
priorities aren't well managed. Round Robin maintains fairness but suffers from high
overhead when the time quantum is too short. These findings align with the results
generated by your program and show how different scheduling approaches perform
under various conditions.
Conclusion
The experiments demonstrate that no single scheduling algorithm is universally
optimal. SJF is highly efficient in reducing turnaround and waiting times by prioritizing
shorter processes, but it risks starving longer ones if shorter tasks keep arriving.
FCFS, though simple and fair, often leads to higher waiting times for processes
arriving later, especially when earlier processes have long burst times. Priority
Scheduling offers flexibility by allowing critical processes to run first, but poorly
managed priorities can cause lower-priority tasks to be delayed indefinitely. Round
Robin, ideal for time-sharing systems, ensures fairness by giving each process CPU
time in turns, but its performance heavily depends on the chosen time quantum. A
small quantum results in too many context switches, while a larger quantum can make
the algorithm behave like FCFS, reducing its effectiveness. Ultimately, the best
algorithm depends on system requirements—whether fairness, efficiency, or priority
handling is more important. The code illustrates these trade-offs and shows how each
algorithm behaves under different scenarios. Ultimately, the best algorithm depends
on the specific requirements of the system—whether it prioritizes fairness, efficiency,
or minimizing delay.