Question

Write a C++ (or Java) program for Round Robin scheduling as following: Round Robin is a...

Write a C++ (or Java) program for Round Robin scheduling as following:
Round Robin is a CPU scheduling algorithm where each process is assigned a fixed time slot in a
cyclic way.
• It is simple, easy to implement, and starvation-free as all processes get fair share of CPU.
• One of the most commonly used technique in CPU scheduling as a core.
• It is preemptive as processes are assigned CPU only for a fixed slice of time at most.
• The disadvantage of it is more overhead of context switching.
To compute the associated times in Round Robin:
1. Completion Time: Time at which process completes its execution.
2. Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
3. Waiting Time (W.T): Time Difference between turnaround time and burst time.
Waiting Time = Turn Around Time – Burst Time
Assume the arrival times are 0 second so that turnaround and completion times are same.
Once waiting times are computed, turnaround times can be quickly computed.
Steps to find waiting times of all processes:
1. Create an array rem_bt[ ] to keep track of remaining burst time of processes.
This array is initially a copy of bt[ ] (burst times array)
2. Create another array wt[ ] to store waiting times of processes. Initialize this array as 0.
3. Initialize time: t = 0.
4. Keep traversing the all processes while all processes are not done. Do following for ith
process if it is not done yet.
If rem_bt[i] > quantum
(i) t = t + quantum
(ii) bt_rem[i] -= quantum;
Else // Last cycle for this process
(i) t = t + bt_rem[i];
(ii) wt[i] = t - bt[i]
(ii) bt_rem[i] = 0; // This process is over
Once we have waiting times, we can compute turnaround time tat[i] of a process as sum of
waiting and burst times, i.e., wt[i] + bt[i]

Homework Answers

Answer #1

main.cpp

#include<iostream>

using namespace std;

struct processes

{

int nums;

int arrival,estimated,wait,total;

int est;

int time;

};

int main()

{

processes arr[99];

int x,y,z;

cout<<"Please enter the total number of processes:"<<endl;

int processNum;

cin>>processNum;

for (x=0;x<processNum;x++)

{

cout<<"Please enter the execution time of processes "<<x+1<<":"<<endl;

cin>>arr[x].estimated;

arr[x].est=arr[x].estimated;

arr[x].arrival=arr[x].time=arr[x].total=arr[x].wait=0;

arr[x].nums=x+1;

}

cout<<"Please enter the time quantum:"<<endl;

int a;

cin>>a;

cout<<"The entered data is as follows: "<<endl;

cout<<"Processes\tET"<<endl;

for(x=0;x<processNum;x++)

{

cout<<endl;

    cout<<arr[x].nums<<"\t\t\t"<<arr[x].estimated;

}

int totaltime=0;

for(x=0;x<processNum;x++)

{

totaltime+=arr[x].estimated;

}

x=0;

z=0;

int rrg[99];

for(y=0;y<totaltime;y++)

{

if((z==0)&&(arr[x].estimated!=0))

{

arr[x].wait=y;

if((arr[x].time!=0))

{

arr[x].wait-=a*arr[x].time;

}

}

if((arr[x].estimated!=0)&&(z!=a))

{

rrg[y]=arr[x].nums;

arr[x].estimated-=1;

z++;

}

else

{

if((z==a)&&(arr[x].estimated!=0))

{

arr[x].time+=1;

}

x=x+1;

if(x==processNum)

{

x=0;

}

z=0;

y=y-1;

}

}

int waitTotal=0;

int timeTotal=0;

cout<<endl;

cout<<"Final result of round robin scheduling: "<<endl;

cout<<"Process Id\tEstimated Time\tWait Time\tTurn around Time";

for(x=0;x<processNum;x++)

{

arr[x].total=arr[x].wait+arr[x].est;

timeTotal+=arr[x].total;

waitTotal+=arr[x].wait;

cout<<endl;

    cout<<arr[x].nums<<"\t\t"<<"\t\t"<<arr[x].est<<"\t\t\t\t"<<arr[x].wait<<"\t\t\t\t"<<arr[x].total<<endl;

}

cout<<endl;

cout<<"Average Waiting Time: "<<(float)waitTotal/processNum<<endl;

cout<<"Average Turn Around Time: "<<(float)timeTotal/processNum<<endl;

return 0;

}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following processes are being scheduled using a preemptive, round-robin scheduling algorithm. (20 Marks) Process    ...
The following processes are being scheduled using a preemptive, round-robin scheduling algorithm. Process     Priority Burst Time Arrival P1 40 20 0 P2 30 25 25 P3 30 15 30 P4 35 10 60 P5 5 10 100 P6 10 10 105 Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified...
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...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Process Priority Burst...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Process Priority Burst Arrival P 1 8 15 0 P 2 3 20 0 P 3 4 20 20 P 4 4 20 25 P 5 5 545 P 6 5 15 55 Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. The scheduler will execute the highestpriority process. For processes with the same priority, a round-robin scheduler will be...
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...
Refer to the information provided below: Refer to the information provided below: Process Burst Arrival-time Priority...
Refer to the information provided below: Refer to the information provided below: Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2 D 12 2 1 Note: A lower priority number indicates a higher priority For each of the following CPU scheduling algorithms, determine the turnaround and wait times for each process as well as the average wait and turnaround times. First Come First Serve Round Robin with quantum=2 ms (assume 1ms = 1...
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2...
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2 D 12 2 1 Note: A lower priority number indicates a higher priority For each of the following CPU scheduling algorithms, determine the turnaround and wait times for each process as well as the average wait and turnaround times. 2. Round Robin with quantum=2 ms (assume 1ms = 1 CPU Burst) Continuation of https://www.chegg.com/homework-help/questions-and-answers/refer-information-provided-process-burst-arrival-priority-time-2-1-3-b-8-0-2-3-1-2-d-12-2--q58716840
Suppose that the following processes arrive for execution at the times indicated. Each process will run...
Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use non-preemptive scheduling, and base all decisions on the information you have at the time the decision must be made. Process Arrival Time Burst Time P1 0.0 8 P2 0.4 4 P3 1.0 1 a. What is the average turnaround time for these processes with the FCFS scheduling algorithm? b. What is the average...
Job A B C D E F Arrival Time 0 2 4 6 8 10 CPU...
Job A B C D E F Arrival Time 0 2 4 6 8 10 CPU Cycles 8 1 5 2 4 3 Refer to the table above to answer the following questions. What is the average turnaround time for the First-Come, First-Served (FCFS) process scheduling algorithm? What is the average turnaround time for the Shortest Job Next (SJN) process scheduling algorithm? What is the average turnaround time for the Shortest Remaining Time (SRT) process scheduling algorithm? What is the...
Consider the following set of processes, with the length of the CPU burst given in milliseconds:...
Consider the following set of processes, with the length of the CPU burst given in milliseconds: Process Burst Time Priority P1 4 3 P2 7 2 P3 2 6 P4 5 1 P5 4 2 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 priority (a larger priority number implies...
Process Burst Time Priority Arrival p1 8 15 0 p2 3 20 0 p3 4 20...
Process Burst Time Priority Arrival p1 8 15 0 p2 3 20 0 p3 4 20 20 p4 4 20 25 p5 5 5 45 p6 5 15 55 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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT