Round Robin Scheduling algorithm
조회 수: 16 (최근 30일)
이전 댓글 표시
Could anyone help me with Matlab code to find the turnaround time using the roundrobin algorithm. This is my code to find the waiting time and the total CPU time. Moreover the waiting time obtained is in negative. I wanna make sure is negative waiting time is possible in round robin?
{ numOfJobs=5
CPUTime=randperm(20)
CPUTime_copy=CPUTime;
CPUTime_copy2=CPUTime;
quantum=5;
totalCPUtime= sum(CPUTime)
total_temp=totalCPUtime;
while (total_temp ~= 0)
for i=1:1:numOfJobs
if CPUTime(i)>0
if(CPUTime(i)>quantum)
CPUTime(i)=CPUTime(i)-quantum;
total_temp=total_temp-quantum;
else CPUTime(i)=CPUTime(i)-quantum;
total_temp=total_temp-quantum;
complete_RR(i)=totalCPUtime-total_temp;
end
end
start(i)=i;
wait_time(i)=totalCPUtime-total_temp-CPUTime_copy(i);
end
break
end }
댓글 수: 0
답변 (2개)
Jamal Nasir
2018년 5월 11일
편집: Jamal Nasir
2018년 5월 11일
%%% this MATLAB code for calculate Average waiting time for Round Robin CPU Scheduling %%% %%% edited by Jamal Nasir %%%%% Unversity of Almustansiryah
clc clear all close all j=3; job=randperm(10,j); jobi=job; flag=job>0; Quant=2; tw=sum(job); job1=[]; x=1:j; x1=[]; n=0; f1=[]; while tw>0 n=n+1; job1=[job1,job]; for i=1:j if flag(i)>0 if job(i)>Quant job(i)=job(i)-Quant; else job(i)=0; flag(i)=0; end end end tw=sum(job); x1=[x1,x]; f1=[f1,flag]; end
k=length(f1); for m=1:j to=0;wt=0; for i=1:k if x1(i)~=m if job1(i)>=Quant t=Quant; else t=job1(i); end wt=wt+t; else if job1(i)>=Quant t1=Quant; else t1=job1(i); end if t1<job1(i) to=to+t1; else break; end end end wait(m)=wt; end AvWaitTime=mean(wait) AvTurnAroundTime=mean(wait+jobi)
댓글 수: 0
Dr R SANJEEV KUMAR
2021년 8월 18일
clc clear all close all j=3; job=randperm(10,j); jobi=job; flag=job>0; Quant=2; tw=sum(job); job1=[]; x=1:j; x1=[]; n=0; f1=[]; while tw>0 n=n+1; job1=[job1,job]; for i=1:j if flag(i)>0 if job(i)>Quant job(i)=job(i)-Quant; else job(i)=0; flag(i)=0; end end end tw=sum(job); x1=[x1,x]; f1=[f1,flag]; end
k=length(f1); for m=1:j to=0;wt=0; for i=1:k if x1(i)~=m if job1(i)>=Quant t=Quant; else t=job1(i); end wt=wt+t; else if job1(i)>=Quant t1=Quant; else t1=job1(i); end if t1<job1(i) to=to+t1; else break; end end end wait(m)=wt; end AvWaitTime=mean(wait) AvTurnAroundTime=mean(wait+jobi)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!