Question

In: Computer Science

Java round robin scheduling algorithm: 10 processes arrive at the same time and the time that...

Java round robin scheduling algorithm:
10 processes arrive at the same time and the time that each requires is random. Show that the output of the original list and list as it changes all the way until nothing is left in the array. Using only main method and not any additional static methods and Only using scanner, arrays, and for looper while/do while loops. No array lists or other methods in java.

Solutions

Expert Solution

import java.io.*;
import java.util.concurrent.TimeUnit;
import java.util.Random;
class Main
{
public static void main(String args[])throws IOException
{   
int arrayOfProcesses[] = new int[10];
int i = 0;
while (i < 10)
{
try
{
TimeUnit.MILLISECONDS.sleep(100);
}
catch(InterruptedException e)
{
// this part is executed when an exception (in this example InterruptedException) occurs
}
arrayOfProcesses[i] = new Random().nextInt(100);
i++;
}
int initialTotalTimeTaken = 0;
i = 0;
while (i < 10)
{
System.out.println("Initial Time taken by " + i + " process is " + arrayOfProcesses[i] + " milliseconds");
initialTotalTimeTaken += arrayOfProcesses[i];
i++;
}
System.out.println();
i = 0;
while (i < 10)
{
try
{
TimeUnit.MILLISECONDS.sleep(100);
}
catch(InterruptedException e)
{
// this part is executed when an exception (in this example InterruptedException) occurs
}
arrayOfProcesses[i] = new Random().nextInt(70);
i++;
}
int newTotalTimeTaken = 0;
i = 0;
while (i < 10)
{
System.out.println("New Time taken by " + i + " process is " + arrayOfProcesses[i] + " milliseconds");
newTotalTimeTaken += arrayOfProcesses[i];
i++;
}

System.out.println("\nTotal time taken initially by all processes = " + initialTotalTimeTaken + " milliseconds");
System.out.println("Total time taken later by all processes = " + newTotalTimeTaken + " milliseconds");
   }
}


Related Solutions

The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is assigned a numerical priority,with a higher number indicating a higher relative priority. The scheduler will execute the highest-priority process. For processes with the same priority, a round-robin scheduler will be used with a time quantum of 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue. Process            Burst Time Arrival Time...
Question 5 The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each...
Question 5 The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is assigned a numerical priority,with a higher number indicating a higher relative priority. The scheduler will execute the highest-priority process. For processes with the same priority, a round-robin scheduler will be used with a time quantum of 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue. Process          Burst Time      Arrival Time   Priority P1                15            0            8...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
For Round Robin (RR) Scheduling, What is the arrival time, completion time, burst time, turnaround time,...
For Round Robin (RR) Scheduling, What is the arrival time, completion time, burst time, turnaround time, and the waiting time? discuss these terms further as they pertain to the efficiency of the algorithm as well as properties such as starvation. Pros and Cons of RR
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum...
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum = 4. Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority. The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Process Burst Time Priority P1 5 2 P2 10 5 P3 4 1 P4 6 4 P5 9 3...
Solve the the process scheduling problem using the round robin FCFS algorithm studied in assignment 7....
Solve the the process scheduling problem using the round robin FCFS algorithm studied in assignment 7. The program will show the order of execution of the processing and will provide the average waiting time for the following scenarios: a) Time quantum =1 b) Time Quantum=3 Use the table below to draw the Gantt Chart (Spread sheet or by hand). Process ID Arrival Time Burst Time 1 0 4 2 1 5 3 2 2 4 3 1 5 4 6...
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum...
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum = 4. Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority. The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Process Burst Time Priority P1 5 2 P2 10 5 P3 4 1 P4 6 4 P5 9 3...
Describe how the Round Robin Scheduling algorithm works. Explain the differences of working procedure between preemptive...
Describe how the Round Robin Scheduling algorithm works. Explain the differences of working procedure between preemptive and non-preemptive version of this algorithm.
First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling Priority Scheduling Shortest Remaining Time Round Robin(RR) Scheduling Multiple-Level...
First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling Priority Scheduling Shortest Remaining Time Round Robin(RR) Scheduling Multiple-Level Queues Scheduling Provide a timing example of each of the algorithms above. List some processes (at least four) with the appropriate properties for creating a time diagram (such as Process ID, Arrival Time, Burst Time, and Execution Time). Walk through the timing diagram identifying the algorithm you’re using and state which process goes first, which process finishes first, etc.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT