Question: Simulation Exercise 1 : Process Management Simulation Goal: To simulate five process management functions: process creation, replacing the current process image with a new process

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:
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 (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:
Sn : 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.
Fn : 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:
\table[[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.
Simulation Exercise 1 : Process Management

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!