Highlights
There are 3 classes given to you for this assignment, defined in the ProcessState.[cpp|hpp], Process.[cpp|hpp], and ProcessSimulator.[cpp|hpp] files respectively. You will mostly need to add code and functions to the ProcessSimulator class. You probably will not need to make any changes to the ProcessState type nor the Process type, though if you feel it makes your solution or approach easier, you can make changes or additions as needed to those classes.
You should probably begin by familiarizing yourself with the ProcessState enumerated type that is given to you. This is a simple user-defined type that simply defines an enumerated type of the valid process that states that processes can be in your simulation. These correspond to the 3/5 process states from our textbook, e.g. NEW, READY, RUNNING, BLOCKED and DONE. For your simulation, processes will pretty much be in one of the READY/RUNNING/BLOCKED states. You will need to handle the creation of NEW processes, but in your simulation when a NEW process enters the system it should immediately be transitioned into a READY state and added to the end of the ready queue, so it will not stay in the NEW state long enough to see this state normally.
The other class that is given to you for this assignment is the Process class defined in the Process.hpp header file and the Process.cpp implementation file. The Process class should define most of the information you will need to keep track of the current state and information about processes being managed by your simulation. For example, if you look in the Process header file you will see that a Process has member variables to keep track of the processes' unique identifier (its pid), the state the process is currently in, the time when the process entered the system and was started, etc. For the most part, you should only need to use the public function given for the Process class to create and manage the processes you will need to implement your simulation.
As a starting point, just like in assignment 1, you should begin with the unit tests given to you in the assg02-tests.cpp file. The first test case in the unit tests actually test the Process class. These tests should all be passing for you. You can look at that code to get an idea of how you should be using the Process class in your simulation.
Your work will begin with the second test case, that starts by testing the initial construction and setup of the
ProcessSimulator, then tests the individual methods you will need to complete to get the simulation working.
So for this assignment, you should start by getting all of the unit tests to pass, and I strongly suggest you work on implementing the functions and passing the tests in this order. You will need to perform the following tasks.
1. You should start by getting the initial state tests to work. I did not give you the implementation of the constructor for the ProcessSimulator class, so you will need to start with a constructor that specifies the system time slice quantum and savest that value. The other functions that are tested in this first unit test are things like getNextProcessId(), getNumActiveProcesses(), readyQueueSize(), blockedListSize(), etc. I would suggest that you start by simply hard coding the expected initial values you need to return from these functions and just get these tests to pass. Then later on as you are forced to implement more, you will add in the actual code you will need in these methods. Most of these methods are used for debugging the unit tests so that we can query different properties of the current state of your simulation and see if they return the expected value or not.
2.Implement the newEvent() function. The newEvent() function is called whenever a new occurs in the simulation. Basically you need to create a new process, assign it the correct next process id, make the process ready, and add it to the end of your ready queue. I would suggest again you work on implementing the functions in the order given in the unit test. For example, just get the check of the sim.getNextProcessId() == 2 to work first by defining a member variable in your ProcessSimulator that keeps track of the next process id that will be assigned and returns it in this function. You will want to use the constructor for the Process and the ready() member function of the Process in your implementation of newEvent().
3.Implement the dispatch() function. There are two actions that don’t directly correspond to explicit events in our simulation. Later on, when we get to implementing the whole simulation, the dispatch() should basically occur before you process the next explicit event of the simulation (and the timeout() will always occur after you process each explicit event). The first unit test of dispatch() are where you may need to implement a real ready queue (you could probably fake it or ignore it through the previous unit tests). Before you work on defining a queue structure for your ready queue, you will need to define some mechanism by which you keep track of whether or not the cpu is currently idle or is currently running a process, and if it is running process you need to know which process is currently running on the cpu.
4.Implement basic cpuEvent() cpu cycles. The cpuEvent() is relatively simple. The system time should be incremented by 1 every time a cpu event occurs. Also, if a process is currently running on the cpu, its timeUsed should be incremented by 1 and its quantumUsed as well. You should use the cpuCycle() member function of the Process class to do the work needed to increment the time used and quantum used of the currently running process.
5.Implement the timeout() function. This is the other implicit action needed for your simulation. The basic thing that timeout() should do is to test if the quantum used of the current running process is equal to or has exceeded the system time slice quantum. If it has, then the process needs to be timed out, which means it goes back to a ready state and is returned back to the tail of the ready queue. You should use the isQuantumExceeded() and timeout() member functions from the Process class in your implementation of the simulation timeout() member function.
There is a test case after the timeout() test case that does some more extensive testing of a dispatch/cpu/timeout cycle. Hopefully, if you implemented these 3 functions well, these tests will be passing as well from your implementations of dispatch(), cpuEvent() and timeout().
6.Implement the blockEvent() simulation function. Besides the round-robin scheduling of processes, your simulation will also simulate blocking and unblocking on simulated I/O or other types of events. An event in our simulation is simple, we just abstractly say that some event of a given unique eventId will occur, and that processes block until this eventId occurs when they become unblocked. In your simulation, we simplify things and say that only 1 process can ever be waiting on any particular eventId. In some real systems, it is possible for 1 event to cause multiple processes to become unblocked, but we will not implement that idea here.
The blockEvent() function should put the current running process into a BLOCKED state and should record the eventId that the process is now waiting on. You should use the block() Process member function in your implementation of blockEvent().
7.Implement the unblockEvent() simulation function. You would not need this for the previous unit test, but now you need to have some way to find out which process is blocked waiting on a particular eventId to occur. You could just do a simple search of your process list to find the blocked process waiting on the particular eventId. In the example solution I will post after this assignment, I used an STL map, to map from an eventId to a process id, and thus be able to directly query the map to find which process should be unblocked when an eventId occurs. However you implement keeping track of the mapping, once you identify the process that should be unblocked, you should use the unblock() member function of the Process class in your unblockEvent() function. You will also need to put the blocked process back onto the tail of the ready queue when it unblocks.
8.Implement the doneEvent() simulation function. This function simulates a process finishing and exiting the system. There is no done() function in the Process class, though you could add one if you think you need it. But for a done event, you can simply remove the process from the list of active processes (for example take it out of your process list).
The above Network Security Assessment has been solved by our Network Security Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.