⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 优先级.txt

📁 计算机操作系统进程调度优先级调度方法
💻 TXT
字号:

求助!操作系统中进程调度模拟程序!求编程高手!不甚感激!!!!!!!!!!! 搜索引擎   
 
 
 
实验:进程调度 
算法设计: 
1.系统初始化每个进程赋予一个needtime和初始pri.并按优先数入队. 
2.系统每次选定一个优先级最高的进程投入运行,进程每执行一次,优先数减2,并将他的进程占有的CPU时间加10,进程到完成还需要的时间减10. 
3.每个进程运行10秒后,系统根据他的NEEDTIME来判断他是否已经结束,若NEDTIME>0.那么他要重新进入就绪队列. 
4.如果系统中尚有进程没有运行完毕,那么转入2. 
5.要求运行后可以显示当前就绪队列和完成队列的进程名. 


#include<stdio.h> 
#include<malloc.h> 
#define LEN sizeof(struct PCB) 
#define NULL 0 
struct PCB 
{int pri; 
char name[10]; 
int needtime; 
int cputime; 
struct PCB *next; 
struct PCB *finish; 
}; 
struct PCB* p1; 
struct PCB* p2; 
int n; 


struct PCB* input(void) /*输入并排列进程队列*/ 
{struct PCB* head; 
struct PCB* p3; 
struct PCB* p4; 
int temp=0; 
int i; 
head=p1=p2=p3=p4=(struct PCB *)malloc(LEN); 
printf("input process1's pri,name and needtime\n"); 
scanf("%d%s%d",p1->pri,p1->name,p1->needtime); 
printf("the summer of the processes:\n"); 
scanf("%d",&n); 
for(i=2;i<=n;i++) 
{printf("input process %d\n"); 
p1=(struct PCB *)malloc(LEN); 
scanf("%d%s%d",p1->pri,p1->name,p1->needtime); 
temp+=1; 
if(temp==1) 
{if(p1->pri>p2->pri) 
{head=p1; 
p1->next=p2; 
p2->next=NULL; 
} 
else{p2->next=p1;p1->next=NULL;p2=p1;} 
} 
else{ 
if(p1->pri>head->pri) 
{p1->next=head;head=p1;} 
else if(p1->pri<p2->pri) 
{p2->next=p1;p1->next=NULL;p2=p1;} 
else 
{p3=head; 
while(p3->pri>=p1->pri) 
{p4=p3; 
p3=p3->next; 
}; 
p4->next=p1; 
p1->next=p3; 
} 
} 
}return(head); 
} 


struct PCB* print(struct PCB* head) /*输出函数*/ 
{struct PCB* p; 
p=head; 
do{printf("%s",p->name); 
p=p->next; 
}while(p!=NULL); 
return head; 
} 


void process(struct PCB* head) /*运行进程*/ 
{int i; 
int count=n; 
struct PCB* p3; 
struct PCB* p4; 
p3=head; 
do{for(i=0;i<10;i++) 
*head; 
printf("the process in run is:%s\n",head->name); 
head->cputime+=10; 
head->needtime-=10; 
head->pri-=2; 
printf("the ready processes are:\n"); 
print(head->next); 
if(head->needtime<=0) 
{head->finish=head; 
head=head->next; 
count--; 
}; 
print(head->finish); 
if(head->needtime>0) 
{if(head->pri>head->next->pri) 
head=head; 
else if(head->pri<p2->pri) 
{p2->next=head;p2=head;head=head->next;} 
else{p3=head; 
while(p3->pri>p1->next->pri) 
{p4=p3; 
p3=p3->next; 
}; 
p4->next=p1; 
p1->next=p3; 
} 
} 
}while(count>0); 
} 


void main() /*主函数*/ 
{struct PCB *head; 
head=input(); 
process(head); 
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -