CPU Scheduling computing the average response time and througput in FCFS SJF MultiLevel FB

 

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

As discussed in the class, please finish the three functions:

(1) public static void FCFS(List ready_q)                 (20%)

Complete it by computing the average response time and througput.  

(2) public static void SJF_preemptive(List ready_q)        (40%)

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Complete this function by using shortest job first algorithm in preemptive mode. You need to compute the average waiting time, average response time and throughput and print them out.

      – Processes are executed in the correct order (25%)

      – Correctly print out the average waiting time, average response time and throughput. (15%)

(3) public static void multiLevel_FB(List ready_q)          (40%)

Complete this function by using multi-level feedback algorithm. You need to compute the average waiting time, average response time and throughput and print them out.

      – Processes are executed in the correct order (25%)
      – Correctly print out the average waiting time, average response time and throughput. (15%)
 

Submission:

Feel free to modify the Process class as needed. So after you finish the code, you only need to turn in the “CPUscheduling.java” file

package demo;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Process {
int id;
Instant ready; //The time the process enter the ready queue
Instant starting_timing; //The time the process is picked up by CPU
int burst_time; //CPU execution time
Instant finishing_time; //The time that the process is finished by CPU

Process(int i, List ready_q)
{
id = i;

Instant cur_time = Instant.now();

//1. Let the process wait for a random amount of time and then set the time to the ready time (between 0 and 2000)
Random rd = new Random();
int amount = rd.nextInt(2000) + 1;
Duration d = Duration.ofMillis(amount);
ready = cur_time.plus(d);

//2. Assign a burst_time for the process
burst_time = rd.nextInt(2000) + 1000; //between 1000ms and 3000ms to finish

//3. Add the current process into ready_q
ready_q.add(this);

}

}
public class CPUScheduling {

/*Finish the FCFS by computing the average waiting time, average response time and throughput and print them out*/
//Follow the algorithm of FCFS to start the processes in the ready_q
public static void FCFS(List ready_q)
{
Instant global_time = Instant.now().plus(Duration.ofMillis(3000)); //Represent the time CPU start scheduling

List finishing_q = new ArrayList();

/* Loop finding minimum process and remove it from the ready_q */
//Pick a process to start execution (assign “starting_timing” and “finishing_time”)
// Once a process is removed from the ready_q, you can add them to another list: finishing_q
while(ready_q.size() > 0)
{
Instant big_time = Instant.now().plus(Duration.ofMillis(10000)); //Create a bigger timestamp than all of the processes.ready time in the queue
int idx = -1; //The index that points to the process with minimum ready time

//The following for loop will find the earliest job (with minimum ready_time)
for(int i = 0; i < ready_q.size(); i++) { //find the minimum ready_time if(big_time.compareTo(ready_q.get(i).ready) > 0)
{
idx = i;
big_time = ready_q.get(i).ready;
}

}

System.out.print(“The minimum one is: “);
System.out.println(ready_q.get(idx).ready);

//assign “starting_timing” and “finishing_time”
ready_q.get(idx).starting_timing = global_time;
ready_q.get(idx).finishing_time = ready_q.get(idx).starting_timing.plus(Duration.ofMillis(ready_q.get(idx).burst_time));
global_time = ready_q.get(idx).finishing_time;

//remove it from ready_q and add it to the finishing_q
finishing_q.add(ready_q.get(idx));
ready_q.remove(idx);
}

System.out.println(“Finishing Q: “);

int total_waiting = 0;
for(int i = 0; i < finishing_q.size(); i++) { //Print out (1) Average waiting time (2) Average response time (3) Throughput System.out.print("[" + i + "]: start: "); System.out.print(finishing_q.get(i).starting_timing); System.out.print("| end: "); System.out.println(finishing_q.get(i).finishing_time); //Accumulate each process's waiting time = starting_time - ready total_waiting += Duration.between(finishing_q.get(i).ready, finishing_q.get(i).starting_timing).toMillis(); } //Compute the Average waiting time double avg_waiting = total_waiting / finishing_q.size(); System.out.println("Total waiting: ” + total_waiting + “, avg waiting: ” + avg_waiting);
}

/*SJF (preemptive): Finish this function by computing the average waiting time, average response time and throughput and print them out*/
public static void SJF_preemptive(List ready_q)
{

//global_time – represents the time CPU start performing scheduling
Instant global_time; //Assign the global_time by using the minimum ready (time) among all the processes in the ready_q
}

/*SJF (preemptive): Finish this function by computing the average waiting time, average response time and throughput and print them out*/
public static void multiLevel_FB(List ready_q)
{

//global_time – represents the time CPU start performing scheduling
Instant global_time; //Assign the global_time by using the minimum ready (time) among all the processes in the ready_q
}

public static void main(String args[])
{
List ready_q = new ArrayList();

//Create 10 processes and then add them to the ready_q
for(int i = 0; i < 10; i++) { Process p = new Process(i, ready_q); } for(int i = 0; i < ready_q.size(); i++) { System.out.print("[" + ready_q.get(i).id + "]: "); System.out.print(ready_q.get(i).ready); System.out.println(" | burst: " + ready_q.get(i).burst_time); } //FCFS FCFS(ready_q); //After all the processes are finished, print out the overall wait time. } }

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.

Order your essay today and save 30% with the discount code ESSAYHELP