資源簡介
這是操作系統的全部實驗 內容豐富 外加源代碼 報告
歡迎下載

代碼片段和文件信息
//進程調度?時間片輪轉調度算法源代碼
#include
#include
#define?MAX?4???//進程數量
#define?RR?3???//時間片大小
/*時間片輪轉算法*/
struct?pro
{
int?num;
int?arriveTime;
int?burst;
int?rt;???//記錄進程被運行的次數
struct?pro?*next;
};
int?TOTALTIME;???//記錄所有進程的總時間
//函數聲明
struct?pro*?creatList();
void?insert(struct?pro?*headstruct?pro?*s);
struct?pro*?searchByAT(struct?pro?*headint?AT);
void?del(struct?pro*?p);
int?getCount(struct?pro?*headint?time);
struct?pro*?searchEnd(struct?pro?*head);
void?move(struct?pro?*headFstruct?pro?*headTint?n);?
struct?pro*?creatList()???//創建鏈表,按照進程的到達時間排列記錄所有進程的信息
{
struct?pro*?head=(struct?pro*)malloc(sizeof(struct?pro));
head->next=NULL;??
struct?pro*?s;
int?i;
TOTALTIME=0;
for(i=0;i {
???s=(struct?pro*)malloc(sizeof(struct?pro));
???printf(“請輸入進程名(用整數表示):\n“);
???scanf(“%d“&(s->num));
???printf(“請輸入到達時間:\n“);
???scanf(“%d“&(s->arriveTime));
???printf(“請輸入運行時間:\n“);
???scanf(“%d“&(s->burst));
???TOTALTIME+=s->burst;???//計算總時間
???s->rt=1;???//rt的初始值為1
???s->next=NULL;
???insert(heads);
}
return?head;???//到達隊列中的進程按照其到達時間的先后順序排列
}
void?insert(struct?pro?*headstruct?pro?*s)???//插入節點
{
struct?pro?*p=searchByAT(heads->arriveTime);
s->next=p->next;
p->next=s;
return;
}
struct?pro*?searchByAT(struct?pro?*headint?AT)???//查找第一個到達時間大于等于AT的節點,返回其前一個指針
{
struct?pro?*p*q;
p=head;
q=head->next;
while(q!=NULL&&q->arriveTime<=AT)
{
???p=q;
???q=q->next;
}
return?p;
}
void?del(struct?pro*?p)???//刪除p的下一個節點
{
struct?pro?*tmp;
tmp=p->next;
p->next=tmp->next;
free(tmp);
return;
}
int?getCount(struct?pro?*headint?time)???//察看在time之前到達但未移動到運行隊列的進程數量
{
int?count=0;
struct?pro?*s*t;
s=head;
t=s->next;
while(t!=NULL&&t->arriveTime<=time)
{
???s=t;
???t=t->next;?
???count++;???//count記錄當前時刻到達的進程數
}
return?count;
}
struct?pro*?searchEnd(struct?pro?*head)???//查找并返回循壞隊列的尾節點的前一個節點
{
struct?pro?*p*q;
p=head;
q=head->next;
while(q->next!=head)
{
???p=q;
???q=q->next;
}
return?p;
}
void?move(struct?pro?*headFstruct?pro?*headTint?n)???//將headF后的n個節點移動到循環隊列headT中
{
struct?pro?*r*s*t;
s=headF;
t=s->next;
r=t;???//r記錄要移動的第一個節點
while(n>1)
{
???t=t->next;
???n--;
}
s->next=t->next;???//以上完成從原隊列中摘除相關節點rt分別為第一個和最后一個節點?
s=searchEnd(headT);
t->next=s->next;
s->next=r;
}
void?run(struct?pro?*head)
{
int?time=0;???//記錄當前時間
int?newarrive;//新到達進程數
struct?pro?*runhead=(struct?pro*)malloc(sizeof(struct?pro));
runhead->next=runhead;???//創建新的循環鏈表,存放當前就緒隊列中的進程
struct?pro?*p*q;
p=runhead;??
q=p->next;???//q記錄當前應當運行的進程
while(time<=TOTALTIME)
{
???newarrive=getCount(headtime);
???if(newarrive>0)
????move(headrunheadnewarrive);???//將head后的newarrive個節點移動到runhead隊列中
???if(runhead->next==runhead)???//就緒隊列中沒有進程
????time++;
???else?if(q==runhead)
???{
????p=q;
????q=q->next;
???}
???else
???{
????printf(“進程名:%d\n“q->num);
????printf(“到達時間:%d\n“q->arriveTime);
????if(q->rt==1)
?????printf(“響應時間:%d\n“tim
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????31232??2010-03-10?15:56??操作系統實驗\操作系統實驗\反饋表.doc
?????文件?????833536??2010-03-10?15:56??操作系統實驗\操作系統實驗\報告.doc
?????文件?????311808??2009-12-22?13:33??操作系統實驗\操作系統實驗\實驗4\實驗4.exe
?????文件??????11595??2009-12-22?13:33??操作系統實驗\操作系統實驗\實驗4\實驗4源碼.cpp
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗\實驗4
?????文件??????12288??2009-12-22?13:19??操作系統實驗\操作系統實驗\實驗3\實驗3.exe
?????文件???????6941??2009-12-22?13:19??操作系統實驗\操作系統實驗\實驗3\實驗3源碼.cpp
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗\實驗3
?????文件??????72192??2009-12-22?13:17??操作系統實驗\操作系統實驗\實驗2\實驗2.exe
?????文件???????5657??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.cpp
?????文件???????3439??2010-05-07?16:39??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.dsp
?????文件????????543??2010-05-07?16:43??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.dsw
?????文件??????41984??2010-05-07?16:43??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.ncb
?????文件??????48640??2010-05-07?16:43??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.opt
?????文件????????765??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\實驗2源碼.plg
?????文件??????33792??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\vc60.idb
?????文件??????53248??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\vc60.pdb
?????文件?????184391??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\實驗2源碼.exe
?????文件?????191704??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\實驗2源碼.ilk
?????文件??????16469??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\實驗2源碼.obj
?????文件?????222240??2010-05-07?16:30??操作系統實驗\操作系統實驗\實驗2\Debug\實驗2源碼.pch
?????文件?????361472??2010-05-07?16:40??操作系統實驗\操作系統實驗\實驗2\Debug\實驗2源碼.pdb
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗\實驗2\Debug
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗\實驗2
?????文件??????71168??2009-12-22?13:59??操作系統實驗\操作系統實驗\實驗1\實驗1.exe
?????文件???????4099??2009-12-22?13:59??操作系統實驗\操作系統實驗\實驗1\實驗1源碼.cpp
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗\實驗1
?????目錄??????????0??2010-05-19?16:13??操作系統實驗\操作系統實驗
?????目錄??????????0??2010-05-19?16:13??操作系統實驗
-----------?---------??----------?-----??----
............此處省略2個文件信息
評論
共有 條評論