Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simulate two CPU scheduling algorithms. FCFS [Code template provided and explained in the class] SJF [Make necessary changes to FCFS to implement this] You must

Simulate two CPU scheduling algorithms. FCFS [Code template provided and explained in the class] SJF [Make necessary changes to FCFS to implement this] You must use the template provided in the class. To understand how to meet the requirements stated below. Required outputs for each algorithm: During the simulation (run for 100 time units): If any process is running, print the process id and global time at each timestamp. If no process is running, print the global time and mention that no process is ready. At the end of the simulation: Print waiting time (WT), completion time (CT) and turnaround time (TAT) for each process. Print average waiting time and average turnaround time. For this task, you can implement additional variables/methods in any class. Prepare a text file (output.txt) with your output lines. You can do this by simply copying the console output to a text file. Otherwise, you can use Java File IO to do it. Follow this link for reference: Java

Create and Write To Files. Submit the text file along with your source codes.

You must use this template: 

package schedulingos; import java.util.Comparator; import java.util.PriorityQueue; public class FCFS{ static PriorityQueue processQueue = new PriorityQueue(10, new Comparator() { public int compare(Process process1, Process process2) { return (int)(process1.getArrivalTime()-process2.getArrivalTime()); } }); static PriorityQueue readyQueue = new PriorityQueue(10, new Comparator() { public int compare(Process process1, Process process2) { return (int)(process1.getArrivalTime()-process2.getArrivalTime()); } }); static GlobalTimer globalTimer = new GlobalTimer(0); public static void main(String[] args) { processQueue.add(new Process(1,3,2,globalTimer)); processQueue.add(new Process(2,6,3,globalTimer)); processQueue.add(new Process(3,1,4,globalTimer)); processQueue.add(new Process(4,4,5,globalTimer)); while(globalTimer.time < 100){ // TASK: Write your code here // You may look for available priority queue methods here: https://www.javatpoint.com/java-priorityqueue // Check for processes that have arrived using checkIfNewProcessArrived() // If found, move them to ready queue // If any process is ready to run, run a process from ready queue following the queue policy // Otherwise print the global time and mention that no process is ready to run } // TASK: Write your code here // Print performance statistics } public static boolean checkIfNewProcessArrived(){ // TASK: Write your code here // return True/False by comparing the earliest arrival time from process queue with the global time } public static void runProcessInCpu(){ // TASK: Write your code here // Retrieve a process that is ready to run and run it } }

package schedulingos; public class GlobalTimer { int time; public GlobalTimer(int initialTime){ this.time=initialTime; } }

package schedulingos; public class Process { int id; int arrivalTime; int duration; GlobalTimer globalTimer; public Process(int id,int arrivalTime, int duration, GlobalTimer globalTimer){ this.id=id; this.arrivalTime=arrivalTime; this.duration=duration; this.globalTimer=globalTimer; } public void runProcess(){ // TASK: Write your code here // The process will print it's id and global time for the duration specified by burst time } public int getId() { return id; } public int getArrivalTime() { return arrivalTime; } public int getDuration() { return duration; } public GlobalTimer getGlobalTimer() { return globalTimer; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions