Java program
The round-robin scheduling problem: using queue
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) - C(200) - D(200)
First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms).
B(80) - C(200) - D(200) - A(50)
Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue.
C(200) - D(200) - A(50)
Your task is to write a program which simulates the round-robin scheduling.
Input:
n q
name1 time1
name2 time2
...
namen timen
In the first line the number of processes n and the quantum q are given separated by a single space.
In the following n lines, names and times for the n processes are given. namei and timei are separated by a single space.
Output: For each process, prints its name and the time the process finished in order.
Constraints:
Sample Input 1
5 100 p1 150 p2 80 p3 200 p4 350 p5 20
Sample Output 1
p2 180 p5 400 p1 450 p3 550 p4 800
CODE
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
class Process {
private String name;
private int time;
public Process(String name, int time) {
this.name = name;
this.time = time;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public String getName() {
return name;
}
}
public class RoundRobin {
public static void main(String[] args) {
// scanner for input.
Scanner s = new
Scanner(System.in);
// accept number of
processes.
int numberOfProcesses =
s.nextInt();
// accept time quantum.
int timeQuantum =
s.nextInt();
// declare queue for
processes.
Queue<Process> processes =
new LinkedList<Process>();
// fill the queue form the
input.
for (int i = 0;
i<numberOfProcesses; i++) {
String namei =
s.next();
int timei =
s.nextInt();
Process processi
= new Process(namei, timei);
processes.add(processi);
}
// intialize current ongoing
time.
int currTime = 0;
// check if process(Queue) is
empty
while(!processes.isEmpty()) {
// get the head
of queue and remove from queue.
Process p =
processes.poll();
// if the
current process is greater than time quantum
// subtract its
remaining time. and add the current time.
// add the
process back to queue.
if (p.getTime()
> timeQuantum) {
p.setTime(p.getTime() - timeQuantum);
currTime += timeQuantum;
processes.add(p);
}
// Else add the
current time and display the output.
else {
currTime += p.getTime();
System.out.println(p.getName() + " " +
currTime);
}
}
}
}
OUTPUT
Java program The round-robin scheduling problem: using queue There are n processes in a queue. Each...
4. Consider a ready queue with four processes :- Process Arrival Time Burst Time (ms) P1 Priority P2 P3 P4 P5 For each of the following CPU scheduling algorithms, determine the turnaround and average waiting time for each of the process :- a. Shortest remaining Time First b. Shortest Job First C. Priority Scheduling (Both pre-emptive and non-preemptive) d. Round Robin (quantum is 1 ms)
The following processes are being scheduled using a pre-emptive, priority-based, round-robin scheduling algorithm. Process Burst Time Priority Arrival 20 20 0 20 25 45 55 5 5 5 15 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 pre-empted by a higher-priority process,...
16. Consider a single-processor system that uses the round-robin (RR) process scheduling algorithm. Assume that the time quantum is 10 milliseconds. Consider the five processes with the arrival time and the burst time, in milliseconds, shown in the table below Arrival Time Burst Time (milliseconds) (milliseconds) Process Pl P2 P3 P4 P5 0 24 20 23 24 Which of the five processes is the last to finish its execution? (A) P (B) P2 (C) P3 (D) P4 (E) P5
Consider a multilevel feedback queue shown below. Assuming that the following processes are the only ones that exist, determine the finish time for each of the processes. Assume that each queue is following FCFS scheduling policy. CPU first schedules all processes in the top queue (Quantum-8) before scheduling processes in queue 2 (Quantum 16), and only then it will schedule processes in queue 3 (FCFS). CPU Burst time Arrival time Priority Process P1 8 15 1 P2 10 15 2...
The following processes P1, P2, P3, P4 and P5 arrive at the same time (t = 0). Establish a timeline of the process scheduling for the following scheduling algorithms while also identifying start times for each process. FCFS (first come, first serve; assume order of P1, P2, P3, P4 and P5) SJF (shortest job first) Priority iv Round Robin (quantum = 1, assume order of P1, P2, P3, P4 and P5) Determine the average waiting time for each algorithm.
Please answer the following question in C++ language Consider the following set of processes, with the length of the CPU burst time given in milliseconds: Process Burst Time Priority P1. 7 5 P2 2 4 P3 11 3 P4 9 1 P5 5 3 The processes are assumed to have arrived in the order P1,P2, P3, P4, P5, all at time 0. a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive...
Given the following set of processes---with the specified length of the CPU burst, arrival time, and priority---compute response time for P1-P5 with round-robin scheduling with time quantum of 10 units. Also compute average response time. Assume that a newly arriving process arrives first at time T- and a process that is preempted due to the completion of its quantum arrives at time T+ in the waiting queue. (Note: Show the Gantt chart and other working details in your worksheet.) Process...
Assume a dynamic queue which is serviced by a Priority Based Round Robin algorithm such that there exists three priorities (1,2,3) which are used as multipliers of the basic time quantum value with the resulting number being the maximum service time the corresponding job will receive each time it gets the CPU. For a maximum amount of time equal to 1 basic time quantum , a priority 2 job gets the CPU for the maximum amount of time equal to...
Table 1 shows the list of processes and burst time for each processesTable 1 ProcessBurst TimeP113P25P323P43P531P66P714 The processes are assumed to have arrived in the order of P1, P2, P3, P4, P5, P6 and P7 all at time 0. a) Calculate the average waiting time when each of the below scheduling algorithm is used. Assume that a quantum 8 is being used:i.) First Come, First Server (6 marks)ii.) Round Robin (6 marks)iii.) Shortest Job First, non preemptive (6 marks)
Round Robin Simulation in C++ using queue Description: Write a program that utilizes STL queue that simulates the round robin process scheduling algorithm. Requirement: - write a class Process that holds following integer information: id, arrival_time, time_needed, finished_time. - read and initiate 5 Process objects from associated file (round_robin.txt) - file format: id, arrival_time, time_needed - once a process is finished, mark its finished_time accordingly. - CPU time frame: 4. - utilize a queue for process scheduling. - store finished...