Question: / / PLEASE WRITE THE CODE IN C + + / / Simulation Exercise 1 : Process Management Simulation Goal: To simulate five process management

// PLEASE WRITE THE CODE IN C++// Simulation Exercise 1: Process Management Simulation
Goal: To simulate five process management functions: process creation, replacing the
current process image with a new process image, process state transition, process
scheduling, and context switching.
You will use Linux system calls such as fork(), wait(), pipe(), and sleep(). Read man
pages of these system calls for details.
This simulation exercise consists of three types of Linux processes: commander, process
manager, and reporter. There is one commander process (this is the process that starts
your simulation), one process manager process that is created by the commander process,
and a number of reporter processes that get created by the process manager, as needed.
Commander Process
The commander process first creates a pipe and then a process manager process. It then
repeatedly reads commands (one command per second) from the standard input and
passes them to the process manager process via the pipe. There are four types of
commands:
1. Q: End of one unit of time.
2. U: Unblock the first simulated process in blocked queue.
3. P: Print the current state of the system.
4. T: Print the average turnaround time, and terminate the system.
Command T appears exactly once, being the last command.
Simulated Process
Process management simulation manages the execution of simulated processes. Each
simulated process is comprised of a program that manipulates (sets/updates) the value of
a single integer variable. Thus the state of a simulated process at any instant is comprised
of the value of its integer variable and the value of its program counter. A simulated
process program consists of a sequence of instructions. There are seven types of
instructions as follows:
1. S n: Set the value of the integer variable to n, where n is an integer.
2. A n: Add n to the value of the integer variable, where n is an integer.
3. D n: Subtract n from the value of the integer variable, where n is an integer. 4. B: Block this simulated process.
5. E: Terminate this simulated process.
6. F n: Create a new simulated process. The new (simulated) process is an exact copy of
the parent (simulated) process. The new (simulated) process executes from the instruction
immediately after this (F) instruction, while the parent (simulated) process continues its
execution n instructions after the next instruction.
7. R filename: Replace the program of the simulated process with the program in the file
filename, and set program counter to the first instruction of this new program.
An example of a program for a simulated is as follows:
S 1000
A 19
A 20
D 53
A 55
F 1
R file_a
F 1
R file_b
F 1
R file_c
F 1
R file_d
F 1
R file_e
E
You may store the program of a simulated process in an array, with one array entry for
each instruction.
Process Manager Process
The process manager process simulates five process management functions: creation of
new (simulated) processes, replacing the current process image of a simulated process
with a new process image, management of process state transitions, process scheduling,
and context switching. In addition, it spawns a reporter process whenever it needs to print
out the state of the system.
The process manager creates the first simulated process (process id =0). Program for this
process is read from a file (filename: init). This is the only simulated process created by
the process manager on its own. All other simulated processes are created in response to
the execution of the F instruction.
Process manager: Data structures The process manager maintains six data structures: Time, Cpu, PcbTable, ReadyState,
BlockedState, and RunningState. Time is an integer variable initialized to zero. Cpu is
used to simulate the execution of a simulated process that is in running state. It should
include data members to store a pointer to the program array, current program counter
value, integer value, and time slice of that simulated process. In addition, it should store
the number of time units used so far in the current time slice.
PcbTable is an array with one entry for every simulated process that hasn't finished its
execution yet. Each entry should include data members to store process id, parent process
id, a pointer to program counter value (initially 0), integer value, priority, state, start time,
and CPU time used so far.
ReadyState stores all simulated processes (PcbTable indices) that are ready to run. This
can be implemented using a queue or priority queue data structure. BlockedState stores all
processes (PcbTable indices) that are currently blocked. This can be implemented using a
queue data structure. Finally, RunningState stores the PcbTable index of the currently
running simulated process.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!