Question
Write a program in Java that will simulate process scheduling. From the command line you take in the input file name as one of the
Write a program in Java that will simulate process scheduling.
From the command line you take in the input file name as one of the arguments
The input file will be a CSV file format:
priority, submission time, CPU burst time, IO burst time
The number of rows in the file is the number of process profiles
Simulate FCFS and Priority First scheduling algorithms:
Your program should analyze the given sets of process profiles:
- Average Wait time
- Average Turnaround time
- Throughput
*****I have wrote the FCFS already. I just need Priority First ******
Here the code:
import java.util.Scanner; import java.io.FileNotFoundException; import java.io.IOException; import java.io.FileInputStream; public class Fcfs { public static void main(String[] args) { //To Store Name of the file to be opened String file = args[0]; int i=0,n; double AWT=0,ATT=0; int AT[]=new int[100]; int BT[]=new int[100]; int WT[]=new int[100]; int TAT[]=new int[100]; int PID[]=new int[100]; //To open file in read mode FileInputStream fin=null; //To read input(file name) from standard input
stream Scanner s = new Scanner(System.in); //To hold each single record obtained from CSV
file String oneRecord = ""; try { //Open the CSV file for reading fin = new FileInputStream(file); //To read from CSV file s = new Scanner(fin); //Loop until all the records in CSV file are
read while (s.hasNextLine()) { oneRecord = s.nextLine(); // Split record into fields using comma as
separator String[] details = oneRecord.split(","); PID[i]=Integer.parseInt(details[0]); AT[i]=Integer.parseInt(details[1]); BT[i]=Integer.parseInt(details[2]); System.out.printf("Process Id=%d\tArrival
Time=%d\tBurst Time=%d ",PID[i],AT[i],BT[i]); i++; } WT[0]=0; for(n=1;n
"+WT[n]+" "+TAT[n]); } System.out.println("Avg waiting time="+AWT/i); System.out.println("Avg waiting time="+ATT/i); } catch (FileNotFoundException e) { System.out.printf("There is no CSV file with
the name %s",file); } finally { if (fin != null) { try { fin.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
The Sample File and Output is
C: Windows system32cmd.exe Users sagar notepad Sanple.csu VUsers sagar java. Fcfs Sanple.csv Process d 1 Arrival Tine 0 Hurst Tinc 50 Process d 2 Arrival Tine 1 Hurst Tine M5 Process d 3 Arrival Tine 2 Burst Tinc 65 d A Arrival Tine 3 Burst Tinc 88 Process d 5 Arrival Tine Burst Tine 91 PROCESS TAT 50 50 94 65 157 88 154 242 91 235 326 Aug waiting tine 106.0 Rug waiting tine 173.8 VUsers sagar Sample Notepad File Edit Format View Help 1,0, 50 2, 1,45 3,2,65 4, 3, 88 5, 7, 91 o O 83 10:16 AMStep 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