⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sjf.m

📁 3个CPU调度算法的simulation. 分别是Short Job First,High Return Ration Next, Round Robin. 模拟得到R,U,S等重要指标。
💻 M
字号:
function [newP,QReady]=SJF(QReady,Qlen)
%It is SURE that there are processes in the queue now. now just to choose one
%The order is not important, so we can sort the queue first,then pick the
%first one. 
%But be CAREFUL if not full queue, should rule out the 0
%NOTE: newP is not newp!!!!!!!!!!!!

newP=-1; % if newp is -1 when return, we can find some problem because we can not access TB(-1)!!
QReady=sortrows(QReady,2);


[Y,Index]=min(QReady(:,2));    %find the first min TB,remember we sort it before
minIndex=Index;
newP=QReady(Index,1);

if Y==0
   for i=1:Qlen                 %find the first min TB that is larger than 0
       if QReady(i,2)>0
           newP=QReady(i,1);
           minIndex=i;
           break;
       end
       i=i+1;
   end
end

if newP<=0
    fprintf('Not good! newP=%d\n',newP);
end
    
QReady(minIndex,:)=0; %move it out from the Queue by set 0

QReady=sortrows(QReady,-2); %just make the p before the 0,nothing else







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -