Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
Part III - Design and Implementation of an API Simulator: fork/exec [5 marks]
We will reuse Assignment 1, where we simulated an interrupt system.
The system has one CPU. The OS use fixed partitions in memory. The simulator uses the following data structures:
Partition Number |
Size |
Code |
Unsigned int |
Unsigned int |
String. Only use free, init or the program name (this will be clear as you read through the assignment) |
Using the textbook/slides, you need to define a table (array of structs, linked list) with similar contents of those found in a PCB (only include the information needed: PID, CPU, and I/O information, remaining CPU time – needed to represent preemption –, partition number where the process is located). You should add any other information that your simulator needs.
Your simulator will initialize the PCB table and pid 0, called init, which will use Partition 6; it uses 1 Mb of memory.
This is another table (implemented as an array of structs, linked list, or your choice of data structure for the table). Its initial contents are loaded from an external text file (external_files.txt) at the start of the simulation. It simulates your persistent memory (hard drive, USB, flash drive…). It only contains a list of programs as follows:
Program Name |
Size of the program when loaded in memory |
String; 20 chars |
Unsigned Integer |
The simulator will implement simulated versions of the fork, exec system calls. For all the system calls, the simulation should try to reproduce the behavior of this state diagram (from Silberschatz et al.) which was implemented in Assignment 1, for both system calls and interrupts.
In this simulator, we implement the two system calls as follows:
a. Simulates SYSCALL (Assignment 1)b. The ISR copies the PCB of the parent to the child processc. At the end of the ISR, you call the routine scheduler (), which is, for now, empty (it just displays “scheduler called”).d. Return from the ISR (Assignment 1)
a. Simulates SYSCALL (Assignment 1)b. The ISR uses the size of the new executable; should search the file in the file list, and obtain the memory size
c. It finds an empty partition where the executable fits (Assume best-fit policy)
d. It marks the partition as occupied
e. It records which process is using that partitionf. It updates the PCB with the new information
g. At the end of the ISR, you call the routine scheduler (), which is, for now, empty (it just displays “scheduler called”).
h. Return from the ISR (Assignment 1)
All the activities by fork and exec must be logged by the simulator. Each step is associated with a random execution time between 1 and 10 milliseconds.
The simulator checks the Ready Queue (in the PCB table you defined), grabs the first process available, and simulates its execution. How? By reading the program name from the external_files table and loading the appropriate program into the simulator. Other than that, you execute the fork, exec and exit syscall as above.
- When the EXEC system call is invoked, assume it is only called by the child process and not by the parent.
- The child process has a higher priority than the parent process. Therefore, the child process should be executed until completion before resuming the parent process. This means that the simulator does not account for orphaned processes yet; the child must finish execution before the parent process can terminate.
- EXEC is found at vector 3 and for FORK is found at vector 2
At the end of each simulated system call, the simulator saves, in a file called system_status.txt the following information:
FORK, 10EXEC program1, 50FORK, 15EXEC program2, 25
CPU, 100
SYSCALL 4, 125
FORK, 17EXEC program1, 16
Contents of program1:
FORK, 15
EXEC program2, 33
CPU, 53SYCALL 5, 128END_IO 11, 115
FORK, 20EXEC program1, 60
FORK, 17EXEC program2, 46
FORK, 16EXEC program3, 58
CPU, 50SYSCALL 6, 110CPU, 15END_IO 10, 220
Your Test Scenarios
The input to your program:
- List of external files in external_files.txt
- Initial trace file in trace.txt
- Your vector table in vector_table.txt
- This is not an input, but you need the traces of your external programs accessible by your simulator. The simulator will look at the respective program name from the EXEC call, check memory requirements from the external_files table and fetch the corresponding program.
Test cases and an example document will be posted on Brightspace, as in Assignment 1.