The project is to design, code and simulate a CPU scheduler utilizing round-robi
ID: 3693104 • Letter: T
Question
The project is to design, code and simulate a CPU scheduler utilizing round-robin algorithm on a system comprising one ready queue and two cores as illustrated in figure 1. The process can utilize any of the available cores , and if the quantum time is insufficient to complete the process task, then process will return back to the ready queue. Otherwise, the process will terminate as shown in figure 1.
Figure 1. An overview of system
The goal of the project is to determine a suitable ready queue size out of the following sizes (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024) , where the decision should be based on the following parameters: average turnaround time, average waiting time, average response time and average number of context switches .
The program should read from a file the number of processes, and a list comprising each process ID and its CPU burst time. Assume the arrival time of all processes is 0.
Run the program several times and give it a different queue size each time. The program should display the Gantt chart of the processes and print the average turnaround time, average waiting time, average response time and average number of context switches.
The time quantum for round-robin is selected based on the process burst time. That is, run the program with queue size = 2 and time quantum = minimum burst time.
Then, run the program with queue size = 2 and time quantum = maximum burst time.
Then, run the program with queue size = 2 and time quantum = average burst time.
Again, run the program with queue size = 4 and time quantum = minimum burst time.
Then, run the program with queue size = 4 and time quantum = maximum burst time.
Then, run the program with queue size = 4 and time quantum = averageburst time.
Explanation / Answer
Answer:
import java.util.*;
class RoundRobinProgram
{
Scanner sc=new Scanner(System.in);
int[] burst_time,reamaining_time_left,waiting_time,turn_around_time;
int capacity,q,b=0,t=0,temp=0;
RoundRobinProgram(int capacity)
{
this.capacity=capacity;
burst_time=new int[capacity];
waiting_time=new int[capacity];
turn_around_time=new int[capacity];
reamaining_time_left=new int[capacity];
}
void read()
{
for(int i=0;i<capacity;i++)
{
System.out.print(" Please Enter burs time of P"+(i+1)+":");
burst_time[i]=reamaining_time_left[i]=sc.nextInt();
}
System.out.print("Enter quantum time required:");
q=sc.nextInt();
}
void round()
{
do{
temp=0;
for(int i=0;i<capacity;i++)
{
if(reamaining_time_left[i]>=q)
{
System.out.print("P"+(i+1)+" ");
for(int j=0;j<capacity;j++)
{
if(j==i)
reamaining_time_left[i]=reamaining_time_left[i]-q;
else if(reamaining_time_left[j]>0)
waiting_time[j]+=q;
}
}
else if(reamaining_time_left[i]>0)
{
System.out.print("P"+(i+1)+" ");
for(int j=0;j<capacity;j++)
{
if(j==i)
reamaining_time_left[i]=0;
else if(reamaining_time_left[j]>0)
waiting_time[j]+=reamaining_time_left[i];
}
}
}
for(int i=0;i<capacity;i++)
if(reamaining_time_left[i]>0)
temp=1;
}while(temp==1);
for(int i=0;i<capacity;i++)
turn_around_time[i]=waiting_time[i]+burst_time[i];
}
void print()
{
System.out.println(" Process burst_timest waiting time Turnaround");
for(int i=0;i<capacity;i++)
{
System.out.println("P"+(i+1)+" "+burst_time[i]+" "+waiting_time[i]+" "+turn_around_time[i]);
b+=waiting_time[i];
t+=turn_around_time[i];
}
System.out.println("Average waiting time:"+(b/capacity));
System.out.println("Average Turnaround time:"+(t/capacity));
}
}
class BaseRoundRobinProgram
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of process:");
int normal=sc.nextInt();
RoundRobinProgram entity = new RoundRobinProgram(normal);
entity.read();
entity.round();
entity.print();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.