單處理器程序排程演算法的模擬

2021-08-10 20:29:15 字數 2070 閱讀 8141

#include #include #include #include #include #include using namespace std;

const int max_process_number = 15;

class process

void set(int id, int arrival, int cpu, int end=0, int during = 0, int state = 0, double ratio=0, int cost=0)

//用於構造優先佇列,這裡比較的是優先順序,cputime越小優先順序越高

bool operator <(const process that) const

};process processes[max_process_number+1];

listrr;

//宣告函式

void fcfs_algorithm();

void rr_algorithm();

void spn_algorithm();

void srt_algorithm();

void hrrn_algorithm();

//hrrn演算法中的比較函式

struct cmp

};int main()

for (int i = 1; i <= max_process_number; i++)

//模擬rr排程

rr_algorithm();

//模擬srt最短剩餘時間

srt_algorithm();

//模擬fcfs先來先服務

fcfs_algorithm();

//模擬spn

spn_algorithm();

//模擬hrrn

hrrn_algorithm();

return 0;

}void fcfs_algorithm()

}void rr_algorithm()

if (++it == rr.end())

it = rr.begin();

++(it->cost);

if (it->cputime == it->cost)

temp->cost = 0;

rr.erase(temp);

} }}void spn_algorithm()

current.cost++;

if (current.cost == current.cputime)

else

break;

} } }

void srt_algorithm()

int cumulative_time = 0;

//總周轉時間

int during = 0;

process current;

current = processes[1];

current.cost = current.cputime;

int next = 2;

cout << "srt:" << endl;

priority_queuespn;

while (1)

current.cputime--;

if (current.cputime==0)

else

break;

} if (cumulative_time % 2 == 0 && next <= max_process_number)

} //這個演算法中的process中的cost的用法有點變化,cputime的用法也有變化。

for (int i = 1; i <= max_process_number; i++)

}void hrrn_algorithm()

current.cost++;

if (current.cost == current.cputime)

while (!temp.empty())

current = spn.top();

spn.pop();

}else

break;

} }}

處理器程序排程演算法

周轉時間用於比較同一作業流排程效能,而加權周轉時間用於比較不同作業流排程效能 簡介 根據作業新增到就緒佇列的順序進行排程。此演算法為非剝奪式,即乙個作業執行完畢,另乙個作業才會被排程到處理器。分析 作業名 作業一28 作業二9 作業三3 按此執行順序,平均周轉時間 28 28 9 28 9 3 3 ...

單處理器排程

面向使用者 周轉時間 指乙個程序從提交到完成之間的時間間隔。響應時間 對於乙個互動程序來說,這是指從提交乙個請求到開始接受響應之間的時間間隔。通常程序處理該請求的同時,就開始給使用者一些輸出。因此從使用者的角度看,相對於周轉時間這是一種更好的度量。面向處理器 吞吐量 排程策略應該試圖使得每乙個時間單...

處理器排程演算法

1 排程方式 排程方式是指當有更高優先順序的程序到來時如何分配cpu 分為可剝奪和不可剝奪兩種。2 排程演算法 先來先服務 時間片輪轉 優先順序排程和多級反饋排程演算法 2.1 先來先服務 fcfs 就是按順序進行排程,遵從 先來後到 的規矩。我不管你是誰,也不管你要理什麼頭型,都去排隊,按順序來。...