Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
/ OS-Simulator Public archive

Simulation of an operating system by means of a java program. The OS simulator was worked on in three phases and consisted of four main components

Notifications You must be signed in to change notification settings

saehaana/OS-Simulator

Repository files navigation

Summary


This is a semester long project where students are to simulate an operating system by means of a program. Done in any language of choosing, the operating system simulator was worked on in three phases and consisted of four main components.

Phase 1 - Process Management: Handling of all resource allocation and scheduling; anything related to CPU and its processes.

Phase 2 - Memory Management: Handling of all memory allocation and deallocation associated with process operations.

Phase 3 - Bonus and GUI: GUI will be implementation of a front end system using javaFX rather than console based print statements used in phase 1 and 2.

How To Run


The OS simulator was created using IntelliJ IDE and as of right now there is no executable. So the only way to run the program is to save all files to a folder and execute Main.java from within the IDE. One thing to note is the inclusion of the BufferedReader class to read text from specified templates/program files. Your version of the OS simulator will not run correctly if you do not change the file paths of the templates to your download's directory. If you do not change the file path directory, BufferedReader will not be able to read correctly and therefore processes and their associated operations cannot be properly set.


Enter number corresponding to specific functionality you want to see (on program launch, any options other than 1 won't do anything)

image.png

Option 1:

Enter keyword(s) corresponding to what you want to do as directed by the terminal; case sensitivity is ignored, correct spacing is required

image.png

At any point you may return to the main menu with keyword 'return', and exit/stop the simulator with keyword '0', 'exit', or 'quit'

image

Addendum


Phase 2 requirements have been implemented into the OS simulator. These include memory management, IO interrupts, parent-child relations, and multithreading.

Memory Management

Total memory size of 1024mb (memorySize) was given to the OS and simulated in the form of an integer located within Process.java. Since memorySize was of int type, basic operations such as allocate and deallocating with +/- operations was implemented. In addition, all templates had fixed memory sizes that reallocated memory to their process from memorySize and was stored as a number as indicated below

*Note the +/- operators next to the memory numbers; -50 indicates 50mb of memory was taken away from total memory and allocated to this process, with +50 giving 50mb back to total memory

image.png

*total memory being deallocated for process

image.png

*memory allocated back to total memory after the end of a process run

image.png

IO Interrupts

With the use of Math.random(), IO interrupts were generated by chance. Method randomIO(int min, int max) was created to set upper and lower bounds for a random number to be selected. If the number selected was less than some condition number (i.e. '5', the number selected, is less than '20', the condition number), than this would cause the process to wait for a certain time.

*visual of randomIO()

image.png

*an IO interrupt occurring during a CALCULATE cycle, process continues running next cycles once interrupt has completed

image.png

Parent-Child Relation

To create a parent and child relationship, keyword FORK was added to specific templates for deterministic spawning, rather than having child processes spawn by chance. Once the fork keyword was read by BufferedReader, a child pid was set to match their parent's pid (called ppid within the simulation) as well as other attributes. The child process would contain same cycles as the parent and be added to the run and wait queues just as any other process.

Multithreading

Multithreading implementation was done by having a class extend Thread and overriding the library's run() and start() methods. Two threads were created for the OS and both were used for the purpose of reading template commands concurrently; instead of having a single thread sequentially read calculate and io commands, one thread was in charge of reading calculate commands, and another io commands.

About

Simulation of an operating system by means of a java program. The OS simulator was worked on in three phases and consisted of four main components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages