Question

ROUND ROBIN TQ = 4 process number arrival time service time response waiting time total time context switches time P1 02 P24

Fill out both charts

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Round Robin:

Time Quantum (TQ): 4

Process Number Arrival Service Waiting Time Response Time Total Time Context Switches
P1 0 9 9 0 18 3
P2 4 5 8 4 13 2
P3 8 7 14 12 21 2
P4 14 7 11 18 18 2
P5 15 4 8 22 12 1

Gantt Chart

P1 P2 P1 P3 P2 P1 P4 P5 P3 P4

Program:

RoundRobin.cpp

#include<iostream>

using namespace std;

void SearchStack01(int pnt,int tm);

void SearchStack02(int pnt, int tm);

void AddQue(int pnt);

int at[50], bt[50], ct[50]={0}, qt, rqi[50]={0}, c=0, st, flg=0, tm=0, noe=0, pnt=0, btm[50]={0}, tt, wt;

float att, awt;

int main(){

cout<<"ROUND ROBIN ALGO : INPUT 5 PROCESSES\n";

for(int x=0;x<5;x++){

cout<<"\nProcess "<<x+1;

cout<<"\nArrival Time : ";

cin>>at[x];

cout << "\nSerivice Time : ";

cin>>bt[x];

btm[x]=bt[x];}

cout<<"\nEnter time quantum: ";

cin>>qt;


cout<<endl<<"GANTT CHART"<<endl<<at[0];

do{

if(flg==0){

st=at[0];

//---ReduceBT

if(btm[0]<=qt){

tm=st+btm[0];

btm[0]=0;

SearchStack01(pnt,tm);}

else{

btm[0]=btm[0]-qt;

tm=st+qt;

SearchStack01(pnt,tm);

AddQue(pnt);}

}//if

else{

pnt=rqi[0]-1;

st=tm;

//---DeleteQue

for(int x=0;x<noe && noe!=1;x++){

rqi[x]=rqi[x+1];}

noe--;

//---ReduceBT

if(btm[pnt]<=qt){

tm=st+btm[pnt];

btm[pnt]=0;

SearchStack02(pnt, tm);}

else{

btm[pnt]=btm[pnt]-qt;

tm=st+qt;

SearchStack02(pnt, tm);

AddQue(pnt);}

}//else

//AssignCTvalue

if(btm[pnt]==0){

ct[pnt]=tm;

}//if

flg++;

cout<<"]-P"<<pnt+1<<"-["<<tm;

}while(noe!=0);

cout<<"\n\nPROCESS\t Arrival Time: \t Service Time: \t Completion Time: \t Turn Around Time \t Wait Time\n";

for(int x=0;x<5;x++){

tt=ct[x]-at[x];

wt=tt-bt[x];

cout<<"P"<<x+1<<" \t\t\t "<<at[x]<<" \t\t\t "<<bt[x]<<" \t\t\t "<<ct[x]<<" \t\t\t "<<tt<<" \t\t\t "<<wt<<"\n";

awt=awt+wt;

att=att+tt;

}//for

cout<<"\nAVERAGE TT: "<<att/5<<"\nAVERAGE WT: "<<awt/5;

return 0;

}//main

void SearchStack01(int pnt,int tm){

for(int x=pnt+1;x<5;x++){

if(at[x]<=tm){

rqi[noe]=x+1;

noe++;}

}//for

}//void

void SearchStack02(int pnt, int tm){

for(int x=pnt+1;x<5;x++){

//---CheckQue

int fl=0;

for(int y=0;y<noe;y++){

if(rqi[y]==x+1){

fl++;}}

if(at[x]<=tm && fl==0 && btm[x]!=0){

rqi[noe]=x+1;

noe++;}

}//for

}//void

void AddQue(int pnt){

rqi[noe]=pnt+1;

noe++;

}//void

output:

ROUND ROBIN ALGO : INPUT 5 PROCESSES

Process 1
Arrival Time : 0

Serivice Time : 9

Process 2
Arrival Time : 4

Serivice Time : 5

Process 3
Arrival Time : 8

Serivice Time : 7

Process 4
Arrival Time : 14

Serivice Time : 7

Process 5
Arrival Time : 14

Serivice Time : 4

Enter time quantum: 4

GANTT CHART
0]-P1-[4]-P2-[8]-P1-[12]-P3-[16]-P2-[17]-P1-[18]-P4-[22]-P5-[26]-P3-[29]-P4-[32

PROCESS Arrival Time: Service Time: Completion Time: Turn AroundTime Wait Time
P1 0 9 18 18 9
P2 4 5 17 13 8
P3 8 7 29 21 14
P4 14 7 32 1811
P5 14 4 26 128

AVERAGE TT: 16.4
AVERAGE WT: 10

Add a comment
Know the answer?
Add Answer to:
Fill out both charts ROUND ROBIN TQ = 4 process number arrival time service time response...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT