Operating-System-Simulator
README.md

Operating-System-Simulator

OS simulator created for CS480 (Operating Systems) course (Spring 2022)

Config file and metadata file upload code and helper functions (Sim01) were written by Dr. Michael Leverington, and each character has been typed/debugged by me, myself, and I.

Sim02 consists of the basic structure of the actual simulator.c file, involving the creation and management of Process Control Blocks. Operations default to non-preemptive First Come First Serve (FCFS-N).

Sim03 implements the SJF-N (Shortest Job First) scheduler as well as memory management display and operations.

Sim04 introduces preemptive scheduling, allowing for interrupts. The scheduling algorithms added are FCFS-P, SRTF-P, and RR-P.


Instructions to run simulation:

Runtime flags

There are three flags the simulator is capable of taking in to run the simulation:

-rs run simulator       -> runs the simulator by using data from the config and metadata files given

-dc display config      -> shows all configuration information of the given config file

-dm display metadata -> outputs the op code stream that the simulator is meant to interpret

Command structure

After compiling using the command make -f Sim0X_mf where X is the number of the simulator, the program can be run by typing: ./Sim0X -rs -dc -dm config.cnf where config.cnf is the given configuration file

The flags are not required, but are necessary for the program to execute in any meaningful way.

Required files

For the simulation to run, a configuration file must be provided. Without one, the program will display a message including the required command structure. Two files in total are required:

Configuration File

Here is an example of a properly formatted configuration file. If the format is incorrect, or if the arguments given are not allowed/specified, the program will not run and will spit out an error.

Start Simulator Configuration File:
Version/Phase: 1.05
File Path: metadatafile.mdf
CPU Scheduling Code: SJF-N
Quantum Time (cycles): 3
Memory Available (KB): 11100
Processor Cycle Time (msec): 10
I/O Cycle Time (msec): 20
Log To: Both
Log File Path: logfile.lgf
End Simulator Configuration File.

The details for specific number ranges allowed can be found in the boolean function valueInRange in the configops.c file. The order of configuration specifications does not matter, as long as the Start and End lines are ... at the start and end.

Metadata File

The metadata file (that must be specified in the configuration file) includes the actual operations that the program will simulate. There is one sys start op code in the beginning and one sys end op code at the end of the file.

Each app start is interpreted as a separate process, and is bounded by an app end. The number of app start & app end commands must be equal, or the program will not run.

Start Program Meta-Data Code:
sys start
app start, 0
dev in, keyboard, 50
cpu process, 7
dev out, video signal, 42
cpu process, 5
dev out, hard drive, 21
dev in, usb, 14
dev in, keyboard, 50
cpu process, 9
dev out, hard drive, 30
cpu process, 5
app end
app start, 0
dev in, video signal, 42
dev out, hard drive, 18
dev in, hard drive, 15
dev in, hard drive, 27
cpu process, 9
dev out, hard drive, 21
cpu process, 7
cpu process, 5
app end
app start, 0
dev in, usb, 12
dev out, video signal, 70
dev in, video signal, 35
cpu process, 5
dev out, monitor, 100
dev in, video signal, 63
cpu process, 5
dev out, video signal, 70
cpu process, 8
dev in, serial, 36
dev out, video signal, 63
dev out, sound signal, 30
app end
app start, 0
dev in, hard drive, 21
cpu process, 5
dev out, monitor, 60
cpu process, 8
dev in, video signal, 56
dev in, hard drive, 21
dev in, hard drive, 15
dev in, video signal, 49
dev out, hard drive, 30
app end
sys end
End Program Meta-Data Code.

If the simulator is given the metadata file above, four Process Control Blocks (PCBs) will be created corresponding to the four app start op codes given. The simulator will then use the given scheduling code to display and run the corresponding operations accordingly.

Here is an example of the simulator running with the Shortest Job First Non-preemptive scheduling algorithm: