This repository contains a simulation designed for exploring various scheduling policies applied to processes or threads executing within a simulated environment. Developed for the Programming Assignment #2 of Class CSCI-GA.2250-001 Spring 2024, guided by Professor Hubertus Franke, it aims to provide a comprehensive understanding of scheduling algorithms' impact on process management in an operating system.
The simulation employs a Discrete Event Simulation (DES) system, focusing on a single-core CPU model without hyperthreading. It intricately models the process life cycle, encompassing states from creation to completion, and simulates the effect of different scheduling algorithms on these processes.
- FCFS (First-Come, First-Served)
- LCFS (Last-Come, First-Served)
- SRTF (Shortest Remaining Time First)
- RR (Round Robin)
- PRIO (Priority Scheduling)
- PREPRIO (Preemptive Priority Scheduling)
At the core of the scheduler/dispatcher simulation lies the DES methodology, which abstractly represents the system's operation through a chronological sequence of events. Each event signifies a state transition, offering a precise and clear-cut simulation of process scheduling and execution.
The simulation defines processes with attributes such as Arrival Time (AT), Total CPU Time (TC), CPU Burst (CB), and IO Burst (IO). It simulates single-threaded processes in a non-preemptive or preemptive manner, depending on the scheduling algorithm applied, closely mirroring real-world operating system behavior.
Implemented algorithms range from basic to advanced, including FCFS, LCFS, SRTF, RR, PRIO, and PREPRIO, each demonstrating unique characteristics and impacts on process scheduling. The simulation provides insights into the algorithms' operational intricacies and their implications on system performance.
A priority queue-based event management system orchestrates the simulation, ensuring chronological processing of events. This system facilitates an in-depth analysis of the scheduling algorithms by tracking process state transitions and scheduling decisions.
The simulation integrates advanced computer science and programming concepts, including:
- Polymorphism and Object-Oriented Design: Employing abstract classes and interfaces to define a common scheduler framework, enabling the seamless integration and comparison of different scheduling algorithms.
- Priority Queue for Event Management: Utilizing data structures to manage events efficiently, ensuring that process transitions and scheduling decisions adhere to the simulation timeline.
- Atomic Operations for Thread Safety: In scenarios where multithreading might be explored, atomic operations ensure data integrity without compromising performance.
- Algorithmic Complexity Considerations: Optimizing data structures and algorithms to minimize computational complexity, enhancing the simulation's efficiency and scalability.
- GNU Compiler Collection (GCC) or compatible C++ compiler
- GNU Make for building the project
- Clone the repository:
git clone https://github.com/your-username/your-repo-name.git
- Navigate to the project directory:
cd your-repo-name
- Compile the project:
make
- Run the simulation with the desired scheduling algorithm and input files:
./sched -s[algorithm] inputfile randfile
Replace [algorithm]
with the scheduling algorithm code (e.g., F
for FCFS), inputfile
with the path to the process specification file, and randfile
with the path to the random numbers file.
Your program should follow the following invocation:
<program> [-v] [-t] [-e] [-p] [-s<schedspec>] inputfile randfile
Options should be able to be passed in any order. This is the way a good programmer will do that. See GNU libc manual on getopt for examples.
Test input files and the sample file with random numbers.
The scheduler specification is “–s [ FLS | R | P[:] | E[:] ]”, where F=FCFS, L=LCFS, S=SRTF and R10 and P10 are RR and PRIO with quantum 10. (e.g., “./sched –sR10”) and E10 is the preemptive prio scheduler. Supporting this parameter is required and the quantum is a positive number. In addition, the number of priority levels is specified in PRIO and PREPRIO with an optional “:num” addition. E.g., “-sE10:5” implies quantum=10 and numprios=5. If the addition is omitted then maxprios=4 by default.
- (a) The input and randfile must accept any path and should not assume a specific location relative to the code or executable.
- (b) All output must go to the console (due to the harness testing)
- (c) All code/grading will be executed on machine
<linserv1.cims.nyu.edu>
As always, if you detect errors in the sample inputs and outputs, let me know immediately so I can verify and correct if necessary. Please refer to the input/output file number and the line number.
At the end of the program, you should print the following information, and the example outputs provide the proper expected formatting (including precision); this is necessary to automate the results checking; all required output should go to the console (stdout / cout).
- Which scheduler algorithm and, in case of RR/PRIO/PREPRIO, also the quantum.
Printed in the order of process appearance in the input file. For each process (assume processes start with pid=0), the correct desired format is shown below:
pid: AT TC CB IO PRIO | FT TT IT CW
- FT: Finishing time
- TT: Turnaround time (finishing time - AT)
- IT: I/O Time (time in blocked state)
- PRIO: Static priority assigned to the process (note this only has meaning in PRIO/PREPRIO case)
- CW: CPU Waiting time (time in Ready state)
Finally, print a summary for the simulation:
- Finishing time of the last event (i.e., the last process finished execution)
- CPU utilization (i.e., percentage (0.0 – 100.0) of time at least one process is running)
- IO utilization (i.e., percentage (0.0 – 100.0) of time at least one process is performing IO)
- Average turnaround time among processes
- Average CPU waiting time among processes
- Throughput of number processes per 100 time units
CPU / IO utilizations and throughput are computed from time=0 till the finishing time.
FCFS
0000: 0 100 10 10 2 | 223 223 123 0
0001: 500 100 20 10 1 | 638 138 38 0
SUM: 638 31.35 25.24 180.50 0.00 0.313
Distributed under the MIT License. See LICENSE
for more information.