Question: draw the flow diagram: Process class: { Public variables: int pid, int arrivaltime, int lifetime, int addressspace, int remaining lifetime, int completionTime Process constructor:
draw the flow diagram:
Process class:
Public variables: int pid, int arrivaltime, int lifetime, int addressspace, int remaining lifetime, int completionTime
Process constructor: pid p arrivaltime a lifetime I, addressspace aspace, remaininglife mathrmI completiontime
Create PagingSimulator class: with attributes memorysize, page size, vector of frames, time, lastprintedtime, vector input queue, vector runningprocesses, outputfile, and vector of the turnaround times. Constructor: memorysize memsize, pagesize p g size time lastprintedtime outputfile outputfilename.
Frames.resizememorysize pagesize,
Loadworkload function which takes in a pointer to string called filepath:
Open the file at the file path
If you cannot open file:
Print that there's an error and file doesn't exist and terminate program exit
String line;
Get line in the file
Processcount convert line to int
While there are available lines in the file:
If line is empty then continue to next iteration
Change line to an int and put it into pid
Get line from file
Look at line to get arrivaltime, lifetime
Get next line
Get num of pieces
Totaladdressspace
For loop iteration from to pieces:
Add next value in line into space
Totaladdressspace space
Make a process object that has pid, arrivaltime, lifetime, totaladdressspace
Add this object to allprocesses which is a list
Simulate function:
While time is less than or equal to AND all the processes are not empty or input queue is not empty or running process is not empty:
Use processarrivals function
Use check completions function Use admit processes function
Increment time by
Use calculateaverageturnaroundtime function
Process arrivals function:
For a process in allprocesses:
If the process arrival time equals the current time:
Insert process to back of input queue
Print the current time
Write process pid arrives to the output file
Write input queue: to the output file
For the proc in the inputqueue:
Write pid of proc to the output file
Write to the output file to close the bracket
Take out the process from allprocesses
Else go on to the next process in allprocesses
Checkcompletions function:
For the process in runningprocesses:
Process's remaininglifetime
If the process's remaining lifetime is less than or equal to then
Print the current time
Complete the process and then take out the process from runningProcesses
Else: go on to the next process in the runningprocessesb
Completeprocess function that takes in a process:
Process's completion time current time
Turnaround time is process's complete time the arrival time of the process
Turnaround times list gets turnaround time
Write that process pid completes to the output file
For the frame in frames:
Extract process id from the frame and frame
If processesid equals to process.pid then set the frace to
Use displaymemorymap function
Admitprocesses function:
For the processes in the input queue
If the process fits in the memory then print the time right now, get the process into the memory, and take out the process from the input queue
Else: go on to the next process in the input queue
Can fit in memory function that takes in a process: Required frames is processs address space size of page size of the page Free frames is the count of all frames that has
Return true or false on freeframes at least required frames
Admit process function that takes in a process:
Required frames is processs address space page size size of page Allocated frames
For the frame in memory frames:
If frame is empty then
Assign the frame process's pid frames allocated
Increment the number of allocated frames
If frames allocated equals to the required frames then
Exit the loop
Write that memory manager moves the process pid to the memory to the output file Use display memory map function
Add the process to the list of running processes
Display memory map function:
Write memory map: to the output file
Start
For i from to size of frames:
If i is within frames size and if framesi is then
If start is then start mathrmi pagesize
Else:
If the start does not equal to then:
Write start to i pagesize : free frames to the output file
Start
If i is within the frames size and framesi does not equal to then
Process id is framesi
Page num is framesi
Write i page size to i pagesize : Process the pid, page number
to the output file
Print time function:
If the time does not equal to the last printed time then
Write to output file: t time
Last printed time time
Calculate average turnaround time function:
If the turnaround times is not empty then
Total sum of every value in the turnaroundtimes
Avg total num of elems in turnaround times Write that the average turnaround time is insert average here units to output file Else: write that no processes were completed to the output file
Int main:
Initialize memory size and pageSizeOption which are i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
