資源簡介
操作系統課請求分頁存儲管理模擬模擬程序,程序相對簡單,通過這個模擬程序能夠幫助學習者會更好的學習os,供有需要的人學習使用。
代碼片段和文件信息
#include
#include
#include?????//?時間函數time調用
#define?N?20???//?分頁數量
#define?P?3????//?內存物理塊數量
typedef?struct?DuLNode
{
int?data;
struct?DuLNode?*prior;
struct?DuLNode?*next;
}DuLNode;
?
int?page_FIFO[?N?+?1?];
int?front?=?0?rear??=?0;
int?page[?N?+?1?]?p_mem[?P?+?1];
int?mem_count??=??1;??//?內存塊計數
void?InitialMemory(??);??//?初始化函數
void?InitialPageUsing(??);
void?BookExemple(??);
int?InsertItem(?int?item?int?queue[?]?int?T?)?;?//?隊尾加入一個元素
int?RemoveItem(?int?*item??int?queue[?]?int?T?)?;?//?從隊首移走一個元素
void?InsertIntoMemory(?int?a[?]?int?b?int?n?);??//?內存插入一項
int?FindNumber(?int?a[?]?int?b?int?T?);??//?確定元素在數組中的序號
void?DisplayMemeryBlock(?);??//?顯示內存物理頁塊信息
void?DisplayPageString(?);??//?顯示頁面號引用串信息
?
int?main(?void?)
{
int?i?number?temp;
int?exchange?=?0;
DuLNode?*p?*q;
srand(?time(?NULL?)?);
p?=?(DuLNode*?)malloc(?sizeof(?DuLNode?)?);
p->prior?=?p;
p->next?=?p;
InitialMemory(??);
//BookExemple(?);??//??教材164頁例子
InitialPageUsing(??);??//??隨機產生例子??
printf(?“*****采用先進先出算法進行頁面置換。*****\n“?);
printf(?“內存物理塊數量:%d\n“?P?);
printf(?“給定引用串序列:\n“?);
DisplayPageString(?);
printf(?“\n“?);
for(?i?=?1;?i<=?N;?i++?)
{
number?=?FindNumber(?p_mem?page[?i?]?P?);
if(?number?>=?0?)
{
printf(??“%d已在頁中。“?page[?i?]?);
DisplayMemeryBlock(?);
}
else
{
if(?mem_count?<=?P?)
{
InsertIntoMemory(?p_mem?page[?i?]?mem_count?);
InsertItem(?page[?i?]?page_FIFO?N?);
printf(?“頁中未滿,%d被引用.?“page[?i?]?);
DisplayMemeryBlock(?);
}
else
{
RemoveItem(?&temp?page_FIFO?N?);
InsertIntoMemory(?p_mem?page[?i?]?FindNumber(?p_mem?temp?P?)?);
InsertItem(?page[?i?]?page_FIFO?N?);
printf(?“%d被引用%d被替換->出現第%d次置換!“page[?i?]?temp?++exchange?);
DisplayMemeryBl
評論
共有 條評論