Process Scheduling Simulator
Process Scheduling Simulator
December 2024
Process Scheduling Simulator 2
Contents
Abstract ....................................................................................................................... 3
Introduction ................................................................................................................. 3
Methodology ................................................................................................................ 4
Program Overview: .................................................................................................... 4
1. Algorithm and Design Implementation: ............................................................. 4
2. Input and Output Framework: .......................................................................... 5
3. Performance Metrics: ...................................................................................... 5
4. Testing and Validation: ..................................................................................... 5
5. Visualization: .................................................................................................. 5
Schedulers Mechanisms: ........................................................................................... 6
1. First Come First Serve (FCFS): .......................................................................... 6
2. Shortest Time to Completion First (STCF): ......................................................... 6
3. Round Robin: .................................................................................................. 7
4. Multi-Level Feedback Queue (MLFQ): ............................................................... 8
5. Lottery Scheduling: ......................................................................................... 9
Results ....................................................................................................................... 10
Implementation of the schedulers: ........................................................................... 10
1. First Come First Serve: ................................................................................... 10
2. Shortest Time to Completion First: ................................................................. 10
3. Round Robin: ................................................................................................ 11
4. Multi-Level Feedback Queue: ......................................................................... 11
5. Lottery Scheduling: ....................................................................................... 11
Conclusion ................................................................................................................. 16
Process Scheduling Simulator 3
Abstract
This documentation presents the Scheduling Simulator, a Python-based tool designed to model
and analyze various scheduling algorithms for optimized task management in computational
systems. The simulator provides an interactive framework to evaluate key performance metrics,
including turnaround time, waiting time, and CPU utilization, across different scheduling
Round Robin (RR), Multi-Level Feedback Queue (MLFQ), and Lottery Scheduling. By simulating
real-world scenarios, this project aims to assist researchers, educators, and system designers in
Introduction
systems, impacting both system performance and user experience. With the proliferation of
multitasking environments, the need to analyze and optimize scheduling algorithms has become
increasingly critical. Scheduling algorithms determine the order and allocation of tasks to system
resources, directly influencing factors such as response time, throughput, and system efficiency.
The Scheduling Simulator is a Python-based tool that enables users to simulate and compare
various scheduling algorithms under customizable conditions. The simulator supports popular
First (STCF), Round Robin (RR), Multi-Level Feedback Queue (MLFQ), and Lottery Scheduling,
and provides detailed performance analysis for each algorithm. Designed to be user-friendly and
extensible, the simulator is suitable for both academic and practical applications, offering insights
into the trade-offs and suitability of different scheduling approaches in diverse scenarios.
Process Scheduling Simulator 4
This documentation details the objectives, design, implementation, and usage of the Scheduling
Simulator. It serves as a comprehensive guide for understanding the simulator’s features and
functionality, as well as the theoretical and practical implications of scheduling algorithm selection
in computational systems.
Methodology
Program Overview:
This project utilizes python as the primary programming language to design and implement
scheduling algorithms for the simulator. The objective was to create a modular and extensible tool
that allows users to experiment with various scheduling strategies and compare their performance
under different task conditions. The following steps outline the methodology employed in
• First Come First Serve (FCFS): Processes are executed in their order of arrival.
• Shortest Time to Completion First (STCF): Tasks with the shortest time remaining
are prioritized, with preemption allowed for incoming tasks with shorter times.
adjusts the priority of tasks based on their behavior and execution history, enabling
fair resource allocation and efficient handling of both short and long tasks.
Process Scheduling Simulator 5
assigned a number of “lottery tickets”, and the CPU is allocated to the process
selected by a random draw. This method ensures fairness while providing flexibility
in resource allocation.
Users input tasks details, such as arrival time, burst time, and time quanta, in the user
interface. The simulator would then process those inputs and generates performance
metrics and visual representations, including Gantt charts and comparative graphs
3. Performance Metrics:
Key metrics used for evaluating performance metrics and visual representations include:
• Turnaround Time
• Waiting Time
• Response Time
5. Visualization:
The Matplotlib library was used to generate visual outputs, such as Gantt charts to help
Schedulers Mechanisms:
The First Come First Serve (FCFS) scheduling algorithm operates by handling tasks in the order
they arrive, ensuring that the earliest arriving process is executed first. The simulation begins by
sorting all processes based on their arrival times. For each process, the scheduler checks the current
time. If the process arrives after the current time, idle time is recorded until the arrival of the
process. Once the process arrives, it begins execution immediately and continues until its burst
time is fully utilized. Key metrics such as Completion Time (CT), Turnaround Time (TAT), and
• Turnaround Time: The total time from arrival to completion, calculated as TAT = CT -
AT.
• Response Time: The time between the process's arrival and the start of its execution.
The Gantt chart is updated to reflect the sequence of process executions and any idle times in the
CPU. Processes execute to completion before the next process starts, reflecting the non-preemptive
nature of FCFS. If no process is ready at a given time, the CPU is marked as idle until the next
process arrives. For each process, these metrics are stored, and the Gantt chart provides a visual
The Shortest Time to Completion First (STCF) scheduling algorithm prioritizes processes based
on their remaining burst times, always selecting the process with the shortest remaining time for
execution. The simulation begins by tracking the burst times and arrival times of all processes. At
Process Scheduling Simulator 7
each unit of time, processes that have arrived by the current time are added to the ready queue.
Then the ready queue is sorted by the remaining burst time of the processes, ensuring the process
with the shortest remaining burst time is selected for execution. If the CPU is idle (no process in
the ready queue), it remains idle until a process arrives. The selected process executes for one-time
unit, and its remaining burst time is decremented. If the process completes during execution, the
same key metrics as FCFS are calculated in addition to: Waiting Time (WT): The total time the
Similar to the FCFS, the Gantt chart is updated to reflect the execution timeline, including idle
times. The algorithm dynamically preempts the currently running process if a newly arrived
process has a shorter remaining burst time, ensuring optimal response for short jobs. Once all
processes are completed, the Gantt chart and the calculated metrics are returned.
3. Round Robin:
The implementation of Round Robin scheduling involves managing a queue of processes and
allowing each process to execute for a time quantum. The simulation starts by sorting processes
by their arrival time and maintaining their burst times. During each cycle all processes that have
arrived by the current time are added to the ready queue. The first process in the queue executes
for either its defined time quantum or the remaining burst time (if the burst time is less than the
time quantum).
If the process completes during its execution time the key metrics mentioned previously are
calculated. If process does not finish execution, it is re-added to the end of the queue with its
updated burst time. If no process is ready at a given time, the CPU is set to idle till a process
arrives.
Process Scheduling Simulator 8
The Multilevel Feedback Queue (MLFQ) scheduling algorithm organizes processes into multiple
priority queues, each with its own scheduling policy. The simulation begins by initializing the
processes with their attributes (Process ID, Arrival Time, and Burst Time) and setting up the
At each unit of time, processes that have arrived are added to the highest-priority queue. Then, the
highest-priority queue with ready processes is selected, and a process is chosen for execution based
• Round Robin (RR): A process executes for a fixed time slice or its remaining burst time,
whichever is smaller.
• First Come First Serve (FCFS): A process executes to completion in the order of its
arrival.
If no process is ready to execute, the CPU is set to idle until a process arrives. During execution,
if a process completes its execution, it is removed from the system, and our previously mentioned
key metrics are recorded. If a process exhausts its time slice without completing, it is demoted to
a lower-priority queue.
Similar to the rest of the schedulers, the Gantt chart is updated dynamically to reflect the execution
timeline for each queue, including idle periods. The algorithm ensures fairness by allowing
processes to move between queues based on their execution behavior, balancing responsiveness
for short jobs and efficiency for longer ones. Once all processes are completed, the Gantt chart and
5. Lottery Scheduling:
The Lottery Scheduling algorithm operates by assigning each process a number of tickets
proportional to its burst time, with processes that have longer burst times receiving more tickets.
The simulation begins by calculating the total number of tickets and distributing them among
processes based on their burst times as a percentage of the total. At each unit of time, a random
number is drawn to simulate the selection of a lottery ticket. The process associated with the
selected ticket is given CPU time for one unit. If a process completes execution during its turn, it
is removed from the ticket pool. Otherwise, its burst time is decremented, and the process remains
eligible for future lottery draws. If no process is ready to execute (all have completed their burst
times), the CPU remains idle. The simulation continues until all the processes complete execution.
As with the other schedulers, the Gantt chart is updated dynamically to reflect the order in which
processes execute, based on the random selection of tickets. This approach ensures fairness by
giving all processes a chance to execute, with the probability of execution proportional to their
burst times. The randomness of ticket selection also introduces unpredictability, making this
Results
3. Round Robin:
5. Lottery Scheduling:
The scheduling algorithms provided—First Come First Serve (FCFS), Shortest Time to
Completion First (STCF), Round Robin (RR), Multilevel Feedback Queue (MLFQ), and
Lottery Scheduling —can be evaluated based on several performance metrics. Let’s analyze these
4. CPU Utilization:
Comparative Analysis:
• Advantages:
o Processes are executed in the order they arrive, ensuring fairness in terms of arrival.
• Disadvantages:
o Convoy Effect: Long processes delay shorter ones, increasing average waiting and
turnaround times.
• Metrics:
o CT & TAT: Higher for processes arriving later due to non-preemptive nature.
o RT: Equal to WT for the first process but increases for subsequent processes.
• Advantages:
o Optimizes turnaround time by prioritizing processes with the shortest burst times.
Process Scheduling Simulator 13
• Disadvantages:
• Metrics:
o CT & TAT: Lower overall compared to FCFS due to prioritization of shorter jobs.
o RT: Very low for shorter jobs, but longer processes may experience delays.
• Advantages:
• Disadvantages:
o Overhead due to frequent context switching, especially with small time slices.
• Metrics:
o CT & TAT: Higher for processes with long burst times due to preemption and
waiting.
o RT: Low for all processes as each gets CPU time quickly.
• Advantages:
o Optimizes for both responsiveness (short jobs) and throughput (long jobs).
• Disadvantages:
• Metrics:
5. Lottery Scheduling:
• Advantages:
• Disadvantages:
• Metrics:
1. Batch Systems:
2. Interactive Systems:
3. Fairness-Critical Systems:
4. Real-Time Systems:
Conclusion:
• STCF is the most efficient for minimizing turnaround and waiting times but can lead to
• RR and MLFQ balance fairness and responsiveness, making them ideal for interactive
systems.
• Lottery provides fairness probabilistically, but its randomness makes it less predictable for
critical systems.
• FCFS is simple but inefficient for systems with mixed job sizes.
Selecting the right algorithm depends on the system's goals, workload, and priorities (e.g., fairness,
or responsiveness).
Process Scheduling Simulator 16
Conclusion