Question

In: Computer Science

IN JAVA Implement SJF scheduling algorithms based on following actions: The simulation maintains the current time,...

IN JAVA

Implement SJF scheduling algorithms based on following actions:

The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions:

repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */
while no process is active, increment t /* if no process is ready to run, just advance t */
choose active processes pᵢ to run next
according to scheduling algorithm /* Ex: FIFO, SJF, SRT */
decrement Rᵢ /* pᵢ has accumulated 1 CPU time unit */
if Rᵢ == 0 /* process i has terminated */
set active flag of pᵢ = 0 /* process i is excluded from further consideration */
TTᵢ = t - Aᵢ /* the turnaround time of process i is the time
since arrival, TTᵢ, until the current time t */
compute the average turnaround time,
ATT, by averaging all values TTᵢ

Solutions

Expert Solution

class Process

{

    int pid;

    int bt;

    int art;

     

    public Process(int pid, int bt, int art)

    {

        this.pid = pid;

        this.bt = bt;

        this.art = art;

    }

}

public class GFG

{

    

    static void findWaitingTime(Process proc[], int n,

                                     int wt[])

    {

        int rt[] = new int[n];

        for (int i = 0; i < n; i++)

            rt[i] = proc[i].bt;

      

        int complete = 0, t = 0, minm = Integer.MAX_VALUE;

        int shortest = 0, finish_time;

        boolean check = false;

        while (complete != n)

            for (int j = 0; j < n; j++)

            {

                if ((proc[j].art <= t) &&

                  (rt[j] < minm) && rt[j] > 0) {

                    minm = rt[j];

                    shortest = j;

                    check = true;

                }

            }

      

            if (check == false) {

                t++;

                continue;

            }

      

            

            rt[shortest]--;

            minm = rt[shortest];

            if (minm == 0)

                minm = Integer.MAX_VALUE;

            if (rt[shortest] == 0) {

                complete++;

                check = false;

                finish_time = t + 1;

                wt[shortest] = finish_time -

                             proc[shortest].bt -

                             proc[shortest].art;

      

                if (wt[shortest] < 0)

                    wt[shortest] = 0;

            }

            t++;

        }

    }

      

    static void findTurnAroundTime(Process proc[], int n,

                            int wt[], int tat[])

    {

        for (int i = 0; i < n; i++)

            tat[i] = proc[i].bt + wt[i];

    }

      

    static void findavgTime(Process proc[], int n)

    {

        int wt[] = new int[n], tat[] = new int[n];

        int total_wt = 0, total_tat = 0;

        findWaitingTime(proc, n, wt);

        findTurnAroundTime(proc, n, wt, tat);

        System.out.println("Processes " +

                           " Burst time " +

                           " Waiting time " +

                           " Turn around time");

        for (int i = 0; i < n; i++) {

            total_wt = total_wt + wt[i];

            total_tat = total_tat + tat[i];

            System.out.println(" " + proc[i].pid + "\t\t"

                             + proc[i].bt + "\t\t " + wt[i]

                             + "\t\t" + tat[i]);

        }

      

        System.out.println("Average waiting time = " +

                          (float)total_wt / (float)n);

        System.out.println("Average turn around time = " +

                           (float)total_tat / (float)n);

    }

  

    public static void main(String[] args)

    {

         Process proc[] = { new Process(1, 6, 1),

                            new Process(2, 8, 1),

                            new Process(3, 7, 2),

                            new Process(4, 3, 3)};

         

         findavgTime(proc, proc.length);

    }

}


Related Solutions

IN JAVA Implement SRT scheduling algorithms based on following actions: The simulation maintains the current time,...
IN JAVA Implement SRT scheduling algorithms based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to run...
Implement 3 scheduling algorithms, FIFO, SJF, SRT based on following actions: The simulation maintains the current...
Implement 3 scheduling algorithms, FIFO, SJF, SRT based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in class: 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with different quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2....
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with di_erent quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the ready queue The simulator needs to...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an array.   2- Implement an algorithm to determine if an array has all unique integer values. 3- Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Write a program that implements the follow disk scheduling algorithms. You can use C or Java...
Write a program that implements the follow disk scheduling algorithms. You can use C or Java for this assignment. FCFS SSTF SCAN C-SCAN LOOK C-LOOK Your program will service a disk with 5000 cylinders (numbered 0 to 4999). Your program will generate a random initial disk head position, as well as a random series of 1000 cylinder requests, and service them using each of the 6 algorithms listed above. Your program will report the total amount of head movement required...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java program to reverse a stack of characters. Make your own assumption and your own design on the methods signature, inputs, outputs, and the full main program.
Draw six Gantt charts that illustrate the execution of these processes using the following scheduling algorithms:
Draw six Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: 
Provide and implement three completely different algorithms of different running time that will check if two...
Provide and implement three completely different algorithms of different running time that will check if two strings are anagrams.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT