xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡(jiǎn)介

進(jìn)程調(diào)度模擬程序:假設(shè)有10個(gè)進(jìn)程需要在CPU上執(zhí)行,分別用: ? 先進(jìn)先出調(diào)度算法; ? 基于優(yōu)先數(shù)的調(diào)度算法; ? 最短執(zhí)行時(shí)間調(diào)度算法 確定這10個(gè)進(jìn)程在CPU上的執(zhí)行過程。要求每次進(jìn)程調(diào)度時(shí)在屏幕上顯示: ? 當(dāng)前執(zhí)行進(jìn)程; ? 就緒隊(duì)列; ? 等待隊(duì)列

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?


struct?PCB //定義一個(gè)進(jìn)程結(jié)點(diǎn)數(shù)據(jù)域
{
int?name; //進(jìn)程名
int?run_time; //運(yùn)行時(shí)間
int?level; //優(yōu)先數(shù)
char?state; //運(yùn)行狀態(tài)
struct?PCB?*next; //指向下一個(gè)結(jié)點(diǎn)的指針
struct?PCB?*pre;????????????????//指向前一個(gè)節(jié)點(diǎn)的指針
};
struct?PCB?*PcbPoint[10];//申明指針
struct?PCB?*ReadyHead?*ReadyTail?*WaitHead?*WaitTail;

int?classNum;
void?displayProcess() //用于輸出當(dāng)前鏈表中各結(jié)點(diǎn)的狀態(tài)
{
struct?PCB?*temp;
temp?=?ReadyHead;
while?(temp?!=?0?)
{
printf(“??Ready?p?%d“?temp->name);???
temp?=?temp->next; //實(shí)現(xiàn)往后移
}
????temp?=?WaitHead;
printf(“?\n“);???
while?(temp?!=?0?)
{
printf(“??Wait?p?%d“?temp->name);???
temp?=?temp->next; //實(shí)現(xiàn)往后移
}
???printf(“?\n“);
}

struct?PCB?*?shedule()//根據(jù)優(yōu)先級(jí)調(diào)度
{??
struct?PCB?*retValue;
struct?PCB?*temp;
????retValue?=?ReadyHead;
temp?=?ReadyHead;
while?(temp?!=?0)
{
if?(temp->level?>?retValue->level)
{
retValue=temp;
}
temp=temp->next;
}
if?((retValue?==?ReadyHead)?&&?(retValue==ReadyTail))
{
ReadyTail->next=ReadyHead->next=ReadyTail->pre=ReadyHead->pre?=?NULL;
return?0;
}
if?(retValue?==?ReadyTail?&&?(retValue?!=?ReadyHead))
{
ReadyTail?=?retValue->pre;//調(diào)整隊(duì)列尾部
ReadyTail->next?=?NULL;
}
else?if?(retValue?==?ReadyHead?&&?(retValue?!=?ReadyTail)?)
{
ReadyHead=?retValue->next;
ReadyHead->pre?=?NULL;
}
else
{
retValue->pre->next=retValue->next;
retValue->next->pre=retValue->pre;
}
return?retValue;
}

int?carryOut?(struct?PCB?*p)
{
int?temp;
if?(NULL?==?p)
return?0;
???
????????printf(“?\n“);???
printf(“??Runing?process?%d“?p->name);???
printf(“??????run?time??%d“?p->run_time);???
????????printf(“??????level??%d\n“?p->level);???
?
?????temp?=?rand()%2;
?if?(temp?==?1)??//該隨機(jī)數(shù)為時(shí),將等待隊(duì)列中的第一個(gè)PCB加入就緒隊(duì)列的對(duì)尾;
?{
?if?(ReadyTail?!=NULL?&&?(WaitHead?!=?NULL))?
?{
???????????ReadyTail->next=WaitHead;
???if?(WaitHead?!=?NULL)
???WaitHead->pre?=?ReadyTail;
????????????ReadyTail=WaitHead;
?}

?if?(WaitHead?!=?NULL)
?????????WaitHead=WaitHead->next;

???????if?(ReadyTail?!=NULL)
?ReadyTail->next=NULL;

?};


?temp?=?rand()%20?+1;//表示執(zhí)行進(jìn)程已經(jīng)執(zhí)行的時(shí)間;約為50毫秒

?
?if?(temp?run_time)?//沒有執(zhí)行完
?{
?????????????p->run_time=p->run_time?-?temp;
????????temp?=?rand()%2;
????????if?(0?==temp?)?//?加到就緒隊(duì)列隊(duì)尾
????????{
??????ReadyTail->next=p;
??p->pre?=ReadyTail;
??????ReadyTail=p;
????????}
????????else???//?加到等待隊(duì)列隊(duì)尾
?? ????????{
WaitTail->next=p;
WaitTail=p;
????????};
?}
??????else//已經(jīng)執(zhí)行完了
?????????printf(“??process?%d?is?run?over\n“?p->name);

?if?(0==temp)
?ReadyTail->next=NULL;
?else
?WaitTail->next=NULL;
?????displayProcess();
?return?1;
};

void?creat() //創(chuàng)建一個(gè)函數(shù),用于返回一個(gè)鏈表
{
int?i?=?1;
for?(i?=?0;?i {
PcbPoint[i]?=?(struct?PCB?*)malloc(sizeof(struct?PCB)); //給PcbPoint指針分配內(nèi)存
????PcbPoint[i]->name=?i;
P

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????4183??2012-11-23?17:15??lab1.c

-----------?---------??----------?-----??----

?????????????????4183????????????????????1


評(píng)論

共有 條評(píng)論

相關(guān)資源