The Process Scheduler relies on a scheduling algorithm, based on a specific sche
ID: 3719738 • Letter: T
Question
The Process Scheduler relies on a scheduling algorithm, based on a specific scheduling policy, to allocate the CPU in the best way to move jobs through the system efficiently. Write a Java program that will simulate the following process scheduling algorithm: 1. First-Come, First-Served (FCFS) Your Java program should produce tables to presents computed results for each scheduling algorithm as shown in the following sample data for the validation your program’s computed results for each scheduling algorithm. IMPORTANT : Please do not use Process and the data need to be entered manually via a prompt in the console.
A) Timeline for First-Come First-Served (FCFS) algorithm: 12 15 18 20 Arrival CPU Start Finish Time Cycle Time Time Turnaround Time Finish Time Arrival Time Job 17-0=7 12 15 18 12 12-1 = 11 15 15-2 13 18 18 3 15 20 20-4 = 16 2 Average Turnaround Time (711 1315 16)/5 62/5 12.4Explanation / Answer
import java.io.*;
class FCFS
{
public static void main(String args[]) throws Exception
{
int n,at[],cpuCycle[],wt[],tat[];
float AWT=0;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println(“Enter no of process”);
n=Integer.parseInt(br.readLine());
wt=new int[n];
tat=new int[n];
cpuCycle=new int[n];
at=new int[n];
System.out.println(“Enter Burst time for each process ”);
for(int i=0;i<n;i++)
{
System.out.println(“Process[“+(i+1)+"]");
cpuCycle[i]=Integer.parseInt(br.readLine());
}
System.out.println(“ Enter Around Time”);
for(int i=0;i<n;i++)
{
System.out.println(“Process[”+i+"]");
at[i]=Integer.parseInt(br.readLine());
}
System.out.println(“ ”);
wt[0]=0;
for(int i=1;i<n;i++)
{
wt[i]=wt[i-1]+cpuCycle[i-1];
wt[i]=wt[i]-at[i];
}
for(int i=0;i<n;i++)
{
tat[i]=wt[i]+cpuCycle[i];
awt=awt+wt[i];
}
System.out.println(” PROCESS BURST-TIME WAITING-TIME TURN AROUND-TIME “);
for(int i=0;i<n;i++)
{
System.out.println(” “+ i + ” “+cpuCycle[i]+” “+wt[i]+” “+tat[i]);
}
awt=awt/n;
System.out.println(“ ”);
System.out.println(“Avg waiting time=”+awt+” ”);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.