Question: Write code in java to simulate the following CPU scheduling algorithm Priority Scheduling with Preemption (PR_withPREMP). Take arrival times into account, and implement preemption. Whenever
Write code in java to simulate the following CPU scheduling algorithm
Priority Scheduling with Preemption (PR_withPREMP).
Take arrival times into account, and implement preemption. Whenever a new process arrives, add it to a priority queue, in which the key is the priority read from the input file. After Time 0, scheduling decisions are made when the process that currently has the CPU terminates or when a higher priority process arrives. The scheduling decision will be giving the CPU to the process with the highest priority (smallest priority number). Ties are broken arbitrarily. If the process with the highest priority process is the new process that has just arrived, the process that has the CPU will get preempted and added to the priority queue (unless it has just terminated at that point).
Your program should read an input file named input.txt and write the results into an output file named output.txt. The formats of these files are as follows:
Input File:
The first line has a space-separated list of scheduling algorithm names to run (any combination of the four names given above).
The second line has a single integer representing the number of processes in the file.
The rest of the file has one line per process with the following information:
Process number Arrival Time CPU burst time Priority
If multiple processes have the same arrival time, your scheduling algorithm should assume that there are negligibly small differences in arrival times with the processes arriving in the order they appear in the file. For priority scheduling, assume that smaller numbers indicate higher priorities. Non-priority algorithms will simply ignore the priority field.
Output File:
The output file will have the scheduling results for each of the algorithms listed in the input file. There should be one line for each CPU assignment (one line for each vertical line in the Gantt chart). Each line should have two numbers: one indicating the time point and one indicating the process number that got the CPU at that point. The last line for each scheduling algorithm should have the average waiting time.
Examples:
Input 4
PR_withPREMP
4
1 0 8 3
2 3 1 1
3 5 2 4
4 6 2 2
Output 4
0 1
3 2
4 1
6 4
8 1
11 3
AVG Waiting Time: 2.25
Priority Queue Implementation
You can implement the priority queue using the easiest and most convenient way for you (the simplest implementation is probably an unsorted array).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
