PROGRAM DESCRIPTION:

In this programming assignment, you will write a complete C program that implement a simulation for the Shortest Remaining Time First (SRTF) preemptive CPU scheduling algorithm. Note that in this exercise, we know the burst time of each process.

You will read input using a file (you must prompt for the name of the file) where the input will be formatted as follows on each line (using whitespace as a delimiter):

ProcessID ArrivalTime BurstTime

where ProcessID is a C-string up to 6 characters (5 with a NULL terminator) and the ArrivalTime and BurstTime are integers, representing units of time. See the SAMPLE OUTPUT for examples of some input files. There is no limit to the number of processes supported by your CPU scheduler, so you will need to read the file to determine how many processes are specified (note that each process must be specified in the file on a separate line).

Based on the SRTF algorithm, you will calculate the finish and wait times for each process as well as the average throughput, waiting time, and turnaround time for the processes.

SAMPLE OUTPUT

$ more pData1.txt
P1 0 11
P2 7 2
P3 5 5
$ ./a.out

Enter name of process file: pData1.txt

PID arrive burst remain finish wait
---------------------------------------
P1 0 11 0 18 7
P2 7 2 0 9 0
P3 5 5 0 12 2
average throughput = 0.1667 processes/unit
average waiting time = 3.0000 units
average turnaround time = 9.0000 units
$ more pData2.txt
P1 0 8
P2 1 4
P3 2 9
P4 3 5
$ ./a.out
Enter name of process file: pData2.txt

PID arrive burst remain finish wait
---------------------------------------
P1 0 8 0 17 9
P2 1 4 0 5 0
P3 2 9 0 26 15
P4 3 5 0 10 2
average throughput = 0.1538 processes/unit
average waiting time = 6.5000 units
average turnaround time = 13.0000 units
$ more pData3.txt
P1 0 6
P2 1 2
P3 2 8
P4 3 4
$ ./a.out
Enter name of process file: pData3.txt

PID arrive burst remain finish wait
---------------------------------------
P1 0 6 0 12 6
P2 1 2 0 3 0
P3 2 8 0 20 10
P4 3 4 0 7 0
average throughput = 0.2000 processes/unit
average waiting time = 4.0000 units
average turnaround time = 9.0000 units
$ ./a.out
Enter name of process file: pData4.txt
error: unable open file pData4.txt. terminating...
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.