資源簡介
(1)進程狀態至少有運行、就緒和阻塞,相應設置運行隊列、就緒隊列、等待隊列。
(2)設計創建進程、撤消進程、調度進程、阻塞進程、喚醒進程函數執行相應功能。
調度算法可選:時間片輪轉法、先來先服務、優先級等
(3)設計用戶界面(可視化界面或鍵盤命令),以交互式方式創建進程、撤消進程、調度進程、阻塞進程、喚醒進程等功能。
(4)能動態顯示每個隊列的每個進程的當前狀態。
(5)程序結構合理,運行穩定、界面友好、能檢查操作錯誤,并給出錯誤信息。
代碼片段和文件信息
//?process.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“stdio.h“
#include?“stdlib.h“
#include?“string.h“
#include?“iostream.h“
#include??//要用到格式控制符
//定義“空”
#define?null?0
//定義不再切割的剩余分區大小
#define?size?5
//定義內存總量大小
#define?memory_totalsize?100
//定義時間片
#define??TIME_PIECE?2
//定義優先級減少的數量
#define?PRIORITY?0
//定義進程結構體
struct?process
{
char?name[40];//進程名字
float?memory_need;//進程所需內存
char?state[10];?//進程狀態?
int?priorty;??//優先級
int?alltime;??//總共所需運行時間
int?cputime;??//該進程在CPU中運行的總時間
struct?process?*next;//指向下一個進程
}*process_ready?*process_blocked?*process_e;//將正在執行的進程設置為一全局變量
//定義內存分配結構體
struct?memory_allocation
{
struct?memory_allocation?*forward;//指向前一個空間
char?process_name[40];//進程名
float?start_address;//進程開始地址
float?memory_size;//進程占用內存大小
int?state;//內存占用狀態
struct?memory_allocation?*after;//指向后一個空間
}*free_chain;
//occupy_chain備用
//*occupy_chain
void?process_excute();
void?process_ready_delete();//在就緒隊列刪除一個進程
void?process_blocked_delete();//在阻塞隊列中刪除一個進程
struct?memory_allocation?*memory_largestselect();//
int?process_createjudge(struct?process?*process_temp);
void?memory_allo(struct?process?*temp_process);
void?memory_free(struct?process?*temp_process);
struct?memory_allocation?*memory_bestselect(struct?process?*temp_process);
void?process_display();//顯示系統中所有進程的信息
void?process_end();//終止正在運行的進程
void?sort_process_ready(process?*p);//按優先級把進程插入到就緒鏈表的適當位置
void?sort_process_block(process?*p);
//初始化內存
void?memory_init(){
free_chain?=?(struct?memory_allocation?*)malloc(sizeof(struct?memory_allocation));//分配空間
strcpy(free_chain->process_name?“null“);
free_chain->start_address?=?0;
free_chain->memory_size?=?memory_totalsize;
free_chain->state?=?0;
free_chain->forward?=?null;
free_chain->after?=?null;
}
//按優先級把進程插入到link鏈表的適當位置
void?sort_process_ready(process?*p)
{
process?*first?*second;??
int?insert=0;??
first=process_ready;??
second=first->next;
if((p->priorty)>(first->priorty))//p的優先級比process_ready鏈表中所有進程的優先級都高
{
p->next=first;
process_ready=p;//跟改頭結點
}
else{//
while(second!=NULL)??
{?
if((p->priorty)>(second->priorty))
{?
p->next=second;??
first->next=p;??
second=NULL;??
insert=1;??
}??
else?//Low?priority
{??
first=first->next;??
second=second->next;??
}??
}
if(insert==0)
{
first->next=p;?
}
}?
}??
void?sort_process_block(process?*p)
{
process?*first?*second;??
int?insert=0;??
first=process_blocked;??
second=first->next;
if((p->priorty)>(first->priorty))//p的優先級比process_blocked鏈表中所有進程的優先級都高
{
p->next=first;
process_blocked=p;//跟改頭結點
}
else
{//
while(second!=NULL)??
{??
if((p->priorty)>(second->priorty))
{?
p->next=second;??
first->next=p;??
second=NULL;??
insert=1;??
}??
else?//Low?priority
{??
first=first->next;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????451584??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.bsc
?????文件?????225356??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.exe
?????文件?????309336??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.ilk
?????文件??????52644??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.obj
?????文件?????203896??2008-11-12?22:47??操作系統進程管理模擬\Debug\process.pch
?????文件?????582656??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.pdb
?????文件??????????0??2008-11-13?18:16??操作系統進程管理模擬\Debug\process.sbr
?????文件???????2261??2008-11-12?22:47??操作系統進程管理模擬\Debug\StdAfx.obj
?????文件???????4073??2008-11-12?22:47??操作系統進程管理模擬\Debug\StdAfx.sbr
?????文件??????91136??2008-11-13?18:16??操作系統進程管理模擬\Debug\vc60.idb
?????文件?????118784??2008-11-13?18:16??操作系統進程管理模擬\Debug\vc60.pdb
?????文件??????29677??2008-11-13?18:16??操作系統進程管理模擬\process.cpp
?????文件???????4552??2008-11-12?23:08??操作系統進程管理模擬\process.dsp
?????文件????????539??2008-11-12?22:44??操作系統進程管理模擬\process.dsw
?????文件??????50176??2008-11-13?18:17??操作系統進程管理模擬\process.ncb
?????文件??????48640??2008-11-13?18:17??操作系統進程管理模擬\process.opt
?????文件???????2076??2008-11-13?18:16??操作系統進程管理模擬\process.plg
?????文件???????2506??2008-11-13?18:22??操作系統進程管理模擬\ReadMe.txt
?????文件????????294??2008-11-12?22:44??操作系統進程管理模擬\StdAfx.cpp
?????文件????????769??2008-11-12?22:44??操作系統進程管理模擬\StdAfx.h
?????目錄??????????0??2008-11-13?18:16??操作系統進程管理模擬\Debug
?????目錄??????????0??2008-11-13?18:17??操作系統進程管理模擬
-----------?---------??----------?-----??----
??????????????2180955????????????????????22
評論
共有 條評論