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 : 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:
Q: End of one unit of time.
U: Unblock the first simulated process in blocked queue.
P: Print the current state of the system.
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 setsupdates 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:
S n: Set the value of the integer variable to n where n is an integer.
A n: Add n to the value of the integer variable, where n is an integer.
D n: Subtract n from the value of the integer variable, where n is an integer. B: Block this simulated process.
E: Terminate this simulated process.
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.
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
A
A
D
A
F
R filea
F
R fileb
F
R filec
F
R filed
F
R filee
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 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 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
