0% found this document useful (0 votes)
30 views16 pages

Process Scheduling Simulator

The Process Scheduling Simulator is a Python-based tool designed to model and analyze various scheduling algorithms to optimize task management in computational systems. It evaluates performance metrics such as turnaround time, waiting time, and CPU utilization across algorithms like FCFS, STCF, Round Robin, MLFQ, and Lottery Scheduling. The simulator aims to aid researchers and system designers in understanding and implementing efficient scheduling mechanisms through interactive simulations and visualizations.

Uploaded by

dowymoragy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views16 pages

Process Scheduling Simulator

The Process Scheduling Simulator is a Python-based tool designed to model and analyze various scheduling algorithms to optimize task management in computational systems. It evaluates performance metrics such as turnaround time, waiting time, and CPU utilization across algorithms like FCFS, STCF, Round Robin, MLFQ, and Lottery Scheduling. The simulator aims to aid researchers and system designers in understanding and implementing efficient scheduling mechanisms through interactive simulations and visualizations.

Uploaded by

dowymoragy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Process Scheduling Simulator 1

Process Scheduling Simulator

Hla Hatem (211001679)

Asmaa Hazem (211001680)

Mariam Mattar (211000120)

Radwa El-Maraghy (211000446)

Faculty of Engineering Nile University

ECEN427: Operating Systems

Dr. Abdullah M. A. Saad

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

strategies such as First-Come-First-Serve (FCFS), Shortest Time to Completion First (STCF),

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

understanding and implementing efficient scheduling mechanisms.

Introduction

Efficient task scheduling is a cornerstone of effective resource management in computational

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

scheduling techniques, including First-Come-First-Serve (FCFS), Shortest Time to Completion

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

developing the scheduling simulator:

1. Algorithm and Design Implementation:

Scheduling algorithms were implemented in python, with each algorithm encapsulated in

separate module for clarity and maintainability. These include:

• 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.

• Round Robin: Time sharing mechanism with a predefined time quantum.

• Multi-Level Feedback Queue (MLFQ): A dynamic scheduling algorithm that

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

• Lottery Scheduling: A probabilistic scheduling algorithm where each process is

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.

2. Input and Output Framework:

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

depending on the scheduling process that the user selects.

3. Performance Metrics:

Key metrics used for evaluating performance metrics and visual representations include:

• Turnaround Time

• Waiting Time

• Response Time

4. Testing and Validation:

The algorithms were tested against predefined scenarios to ensure correctness.

5. Visualization:

The Matplotlib library was used to generate visual outputs, such as Gantt charts to help

users interpret results more intuitively.


Process Scheduling Simulator 6

Schedulers Mechanisms:

1. First Come First Serve (FCFS):

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

Response Time (RT) are calculated as follows:

• Completion Time: The time when a process finishes execution.

• 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

representation of the execution timeline.

2. Shortest Time to Completion First (STCF):

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

process spends waiting in the queue, calculated as WT = TAT - BT.

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

4. Multi-Level Feedback Queue (MLFQ):

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

queues based on user-defined configurations.

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

on the queue's scheduling policy:

• 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

recorded metrics provide a detailed view of the execution.


Process Scheduling Simulator 9

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

algorithm suitable for systems that prioritize fairness and responsiveness.


Process Scheduling Simulator 10

Results

Implementation of the schedulers:

1. First Come First Serve:

2. Shortest Time to Completion First:


Process Scheduling Simulator 11

3. Round Robin:

4. Multi-Level Feedback Queue:

5. Lottery Scheduling:

Effectiveness of different scheduling algorithms:

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

metrics and compare the effectiveness of each algorithm.

Key Performance Metrics:

1. Completion Time (CT):

o The time when a process completes execution.

2. Turnaround Time (TAT):


Process Scheduling Simulator 12

o Total time a process spends in the system, from arrival to completion.

o Formula: TAT = CT - AT.

3. Response Time (RT):

o The time between a process’s arrival and its first execution.

4. CPU Utilization:

o Percentage of time the CPU is actively executing processes (non-idle time).

Comparative Analysis:

1. First Come First Serve (FCFS):

• Advantages:

o Simple and easy to implement.

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.

o Poor responsiveness for time-sensitive tasks.

• 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.

2. Shortest Time to Completion First (STCF):

• Advantages:

o Optimizes turnaround time by prioritizing processes with the shortest burst times.
Process Scheduling Simulator 13

o Dynamically preempts longer jobs to accommodate shorter ones.

• Disadvantages:

o Starvation of longer processes if many short processes keep arriving.

o Complex to implement due to continuous sorting of ready queue.

• 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.

3. Round Robin (RR):

• Advantages:

o Ensures fairness by giving all processes a time slice (quantum).

o Improves responsiveness compared to FCFS.

• Disadvantages:

o Overhead due to frequent context switching, especially with small time slices.

o Performance depends heavily on the chosen time quantum.

• 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.

4. Multilevel Feedback Queue (MLFQ):

• Advantages:

o Combines benefits of multiple scheduling policies (e.g., FCFS, RR).


Process Scheduling Simulator 14

o Dynamically adjusts process priority based on behavior.

o Optimizes for both responsiveness (short jobs) and throughput (long jobs).

• Disadvantages:

o Complex to implement and tune queue configurations.

o Risk of starvation for lower-priority processes.

• Metrics:

o CT & TAT: Optimized for short jobs due to preemptive nature.

o RT: Very low for short jobs in high-priority queues.

5. Lottery Scheduling:

• Advantages:

o Fairness is probabilistic, giving all processes a chance to execute.

o Dynamically adjusts execution based on the number of tickets.

• Disadvantages:

o Lack of deterministic guarantees for process completion.

o Potential for high variance in waiting and turnaround times.

• Metrics:

o CT & TAT: Can vary significantly due to randomness in ticket selection.

o RT: Probabilistic but generally acceptable if the ticket distribution is fair.

Effectiveness Based on Scenarios:

1. Batch Systems:

o Best: FCFS or STCF (focus on throughput and turnaround time).


Process Scheduling Simulator 15

o Worst: RR or Lottery (due to unnecessary context switches or randomness).

2. Interactive Systems:

o Best: RR or MLFQ (ensures responsiveness for short tasks).

o Worst: FCFS (long jobs block short jobs).

3. Fairness-Critical Systems:

o Best: Lottery or MLFQ (dynamic and probabilistic fairness).

o Worst: STCF (short jobs dominate longer jobs).

4. Real-Time Systems:

o Best: STCF or MLFQ (preemptive and priority-based scheduling).

o Worst: FCFS or Lottery (lack of guarantees for time-sensitive tasks).

Conclusion:

• STCF is the most efficient for minimizing turnaround and waiting times but can lead to

starvation for longer processes.

• 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

You might also like