資源簡介
實驗(一)多道程序、進程、分時系統模擬
1、 實驗目的
加深學生對多道系統中進程管理的理解,了解進程的各種狀態及其轉換過程,分時系統中時間片的設置及進程在時間片開始和結束時的調度過程。
2、 實驗內容
(1) 利用程序設計語言模擬分時系統中多個進程按時間片輪轉調度算法進行進程調度的過程;
(2) 假設有五個進程A,B,C,D,E,它們的到達時間及要求服務的時間分別為:
進程名 A B C D E
到達時間 0 1 2 3 4
服務時間 4 3 4 2 4
時間片大小為1,利用程序模擬A,B,C,D,E五個進程按時間片輪轉的調度及執行過程并計算周轉時間及帶權周轉時間。
(3) 時間片大小為2,利用程序模擬A,B,C,D,E五個進程按時間片輪轉的調度及執行過程并計算周轉時間及帶權周轉時間。
(4) 時間片大小為4,利用程序模擬A,B,C,D,E五個進程按時間片輪轉的調度及執行過程并計算周轉時間及帶權周轉時間。
3、 思考
時間片的大小對計算機的性能產生什么影響?

代碼片段和文件信息
#include?“stdio.h“
#include?“stdlib.h“
#include?“iostream.h“
??struct?process
??{
??char?name;
??int?arri_time;//arrived?time
??int?serv_time;//servered?time
??int?have_done_time;//已經運行時間
??int?done_time;//完成時間
??int?turn_around_time;//周轉時間
??float?wei_turn_around_time;//帶權周轉時間
??struct?process?*?next;
??};
int?time=-1;
int?time_slice=1
;//時間片初始值為1
Isempty(struct?process*?head)
{
if?(head->next==NULL)
return?true;
else?return?false;
}
void?pushline(struct?process*?headstruct?process*?rn)
{
if?(rn==NULL)
return;
struct?process*?x;
x=head;
while?(x->next!=NULL)
{
x=x->next;
}
x->next=rn;
}
void?popline(struct?process*?headstruct?process**?x)
{
if(!Isempty(head))
{
*x=head->next;
head->next=(*x)->next;
(*x)->next=NULL;
}
}
void?isnewcome(struct?process*?headstruct?process*?readyline)
{
struct?process*?x;
if?(head->next==NULL)
return;
if?(head->next->arri_time==time&&head->next!=NULL)
{
cout< popline(head&x);
pushline(readylinex);
}
}
??void?main()
?{
??struct?process*?head;
??struct?process*?newnode;
??struct?process*?tail;
??struct?process*?readyline;//隊列
??readyline=(struct?process*)malloc(sizeof(process));
??readyline->next=NULL;
??int?i;
??struct?process*?rightnow;
??struct?process*?p;
??/*struct?process*?n;*/
??
??head=(struct?process*)malloc(sizeof(process));
??
??if(!head)
??{
??cout<<“內存分配錯誤“< ??}
??head->next=NULL;
??tail=head;
??while?(1)?
??{
??newnode=(struct?process*)malloc(sizeof(process));
??cout<<“請輸入進程名“< ??cin>>newnode->name;
??if(newnode->name==‘#‘)
?break;
??cout<<“請輸入進程到達時間“< ??cin>>newnode->arri_time;
??cout<<“請輸入進程服務時間“< ??cin>>newnode->serv_time;
??newnode->done_time=0;
??newnode->turn_around_time=0;
??newnode->wei_turn_around_time=0.0;
??newnode->have_done_time=0;
?//?tail->next=newnode;
??newnode->next=NULL;
??//tail=newnode;?
??pushline(headnewnode);
??}
??p=head->next;
??while(p!=NULL)
??{
??cout<name<<“進程“< ??p=p->next;
??}
?
ss: ??while(time<200)
??{
??time++;
??//cout<<“當前TIME“< ??isnewcome(headreadyline);
??if?(time!=0)
?pushline(readylinerightnow);
??
??i=time_slice;
??//cout<<“i=“< ??while?(i!=0)
??{
??//cout<<“DANG?QIANG?TIME“< ??if?(i==time_slice)
??{
??i--;
??if(!Isempty(readyline))
??{
??popline(readyline&rightnow);
??rightnow->have_done_time++;
??rightnow->done_time=time;
??cout<<“run?“<name< ??if?(rightnow->have_done_time==rightnow->serv_time)
??{
??rightnow->turn_around_time=rightnow->done_time-rightnow->arri_time+1;
??rightnow->wei_turn_around_time=(float)rightnow->turn_around_time/rightnow->serv_time;
??cout<<“********************“<<
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5056??2010-05-25?10:30??分時系統\012.cpp
?????文件???????3365??2010-05-05?21:51??分時系統\012.dsp
?????文件????????512??2010-05-05?21:51??分時系統\012.dsw
?????文件??????41984??2010-05-25?10:33??分時系統\012.ncb
?????文件??????49664??2010-05-25?10:33??分時系統\012.opt
?????文件???????1100??2010-05-25?10:30??分時系統\012.plg
?????文件?????229413??2010-05-25?10:30??分時系統\Debug\012.exe
?????文件?????297568??2010-05-25?10:30??分時系統\Debug\012.ilk
?????文件??????13513??2010-05-25?10:30??分時系統\Debug\012.obj
?????文件?????274512??2010-05-25?10:18??分時系統\Debug\012.pch
?????文件?????549888??2010-05-25?10:30??分時系統\Debug\012.pdb
?????文件??????50176??2010-05-25?10:30??分時系統\Debug\vc60.idb
?????文件??????61440??2010-05-25?10:30??分時系統\Debug\vc60.pdb
?????文件??????51712??2010-04-29?17:31??分時系統\os實驗指導.doc
?????目錄??????????0??2010-05-25?10:30??分時系統\Debug
?????目錄??????????0??2010-05-25?10:33??分時系統
-----------?---------??----------?-----??----
??????????????1629903????????????????????16
- 上一篇:DATA1.MSI
- 下一篇:SJFFCFSHRRN
評論
共有 條評論