Question
Need help in C program. Thank you. 2.1 Input Specification(input.txt): The input will be given in the form of a text file named input.txt. The
Need help in C program. Thank you.
2.1 Input Specification(input.txt):
The input will be given in the form of a text file named input.txt. The first line in the text file will contain a number, n, that represents the number of processes to fork. The file will then be followed by n lines of the form where each number is a positive integer:
arrivalTime numCPUBursts CPUBurst IOBurst CPUBurst ...
Processes will be specified in order of their arrival time. The number of CPU bursts will be capped at five. Recall that the number of I/O bursts is the number of CPU bursts 1. An I/O burst length will always be followed by a CPU burst length. CPU and I/O burst times will be between 1 and 20. A larger integer specifies a longer CPU or I/O operation while a smaller integer specifies a shorter CPU or I/O operation. For simplicity, you may assume that the input file contains no errors.
2.6 Wait2 System Call:
For the timing information of a process to be accessed from user space, a new system call needs to be implemented. Wait2 should take 5 arguments: the creation time, the start time, the end time, the run time , and the io time of a process. The wait time is the time spent by a process that is RUNNABLE waiting to be scheduled which we calculate in the user program by the equation below. =
The function prototype of wait2 system call is:
int wait2(int * creationTime, int* startTime, int* runTime, int* ioTime, int* endTime);
A parent process calls wait2 to wait for a child process to terminate and to retrieve information about that child process. Wait2 should set up the arguments that were passed to it just like we did in the date assignment. Then, wait2 will call getProcessStats to wait on the process to exit and record the time information. The creation time, start time, run time, io time, and end time should be returned by reference to the parent process. To implement wait2 system call, you need to modify following files like in previous assignment
The wait2 system call will call getProcessStats(int * creationTime, int* startTime, int* runTime, int* ioTime, int* endTime) to retrieve these time stamps.
We need to implement getProcessStats in proc.c. The function prototype should be defined in defs.h as: int getProcessStats(int * creationTime, int* startTime, int* runTime, int* ioTime, int* endTime);
Note that defs.h is a header file included in sysproc.c so we need to define the function here so that it is visible to a system call in sysproc.c. The function getProcessStats behaves very similarly to the already-existing wait function in proc.c. Just like wait, getProcessStats should return the pid of the child process that terminated. However, getProcessStats will take 5 arguments, int* creationTime, int* startTime, int* runTime, int* ioTime and int* endTime and set these variables from the processs proc fields.
2.7 Parent Process:
The input file for the program will be given as a command line argument. The parent process should read the input file and store the information, perhaps in a 2D array where each row represents a process and entries in the row specify alternating CPU and I/O burst lengths.
Hint: The maximum number of processes xv6 can handle is 64. Since the number of CPU bursts is capped at five, you can have up to nine columns to store the burst lengths (max CPU bursts (5) + max I/O bursts (4)). So, you may choose store the process information in a 2D array with 64 rows and at least 9 columns. However, you may find it easier to use an extra column and have the first column in each row hold the number of CPU bursts for that process. The parent process is responsible for forking the child processes and waiting for them to finish.
Processes are specified in the order of their arrival time. Before starting to fork children, the parent should get the start time in ticks by calling uptime(). Before forking a child, the parent should check whether its arrival time is greater than the current time (retrieved via another call to uptime()) minus the start time. If the arrival time is not greater, the parent should sleep until the arrival time is greater.
Information about each childs creation time, start time, end time, run time, and waiting time should be kept; hence, the wait2 system call should be used. The parent should also keep track of the turnaround time and response time of each process.
= =
After each child process exits, parent should print the creation time, start time, end time, run time, io time, waiting time, turnaround time, and response time of each process in the following format: child[pid]: creationTime [creationTime] startTime [startTime] endTime [endTime] runTime [runTime] ioTime [ioTime] waitTime [waitTime] turnaround time [tat] response time [response]
In addition, the parent should calculate and print the average turnaround time and average response time for all processes.
= =1 = =1
2.7.1 Parent Process Algorithm:
The algorithm for the parent process is as follows:
read input file s
Time = uptime() f
or i = 0 to numProcs do
currentTime = uptime()
if arrivalTime[i] > (currentTime sTime)
then sleep until process is ready to arrive
endif
pid = fork() if pid == 0 then
// child process algorithm
endif
endfor
for i = 0 to numProcs do
pids[i] = wait2(&creationTime, &startTime, &runTime,&endTime)
store times for process
calculate TAT and Response
endfor
for i = 0 to numProcs do
print process timing information to the screen
endfor
print average TAT and average response to the screen
2.8 Child Processes:
Child processes will do some CPU calculations and possibly some I/O operations. The CPU operation will consist of incrementing a counter a given number of times. The I/O operation will consist of the process printing its pid to the screen a given number of times.
Recall that information is provided for each process about its CPU and I/O burst lengths. These lengths should be used to determine how many times to increment the counter or to print its pid to the screen. Because the range of burst lengths is [1, 20], if this value was simply used as the number of times to increment a counter, the operation would be over too quickly to demonstrate the effect of CPU bursts. As such, the numbers read in from the file for CPU burst lengths should be used as a multiplier for a constant CPU_ITERATIONS variable, which should be set equal to 10000000. The CPU operation thus consists of incrementing a counter cpu_burst_length*CPU_ITERATIONS times.
Each child should perform at least one CPU burst (since each process has at least one) followed by any remaining I/O and CPU bursts, alternating. The child, if it has any I/O bursts, should print its pid in the following format:
child [pid] prints for the [i] time The child should not print anything during a CPU burst.
2.8.1 Child Process Algorithm:
Use the following algorithm sketch for the child processes. How you get the burst lengths for each process depends on how you set up your array(s) storing those lengths.
counter = 0
pid = getpid()
// perform cpu burst (always at least one)
for i = 0 to first_cpu_burst_length * CPU_ITERATIONS do
counter++
endfor
for each remaining I/O and CPU burst pair do
// next burst is an I/O burst
for i = 0 to next_io_burst_length do print pid to screen
endfor
// next burst is a CPU burst
for i = 0 to next_cpu_burst_length * CPU_ITERATIONS do
counter++
endfor
endfor
exit()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started