论文百事通 设为主页 会员登录 |  免费注册
代写论文 代发表论文 定制论文 毕业设计定制 期刊目录 黄金会员  
加入收藏 设为首页 |  收藏本站
首页 | 计算机 | 建筑工程 | 医药学 | 经济类 | 文学 | 英语 | 其它类别论文 | 计算机毕业设计 | 课程设计 | 毕业系统演示 | 投稿中心 | 下载中心 | 留言板
  查找论文

用C语言实现进程调度-操作系统课程设计

作者:论文百事通  来源:lwbst.com    【2006-09-19】    编辑:Admin


实验要求:编写并调试一个模拟的进程调度程序,采用“最高优先数优先”调度算法对五个进程进行调度

设计思想:
“最高优先数优先”调度算法的基本思想是把cpu分配给就绪队列中优先数最高的进程。采用动态优先数,即优先数在创建进程时给定一个初始值,当进程获得一次cpu后其优先数就减少1。

运行界面和过程如下:

进程调度实验结果1
进程调度实验结果2
进程调度实验结果3
进程调度实验结果4
进程调度实验结果5
进程调度实验结果6
进程调度实验结果7

源程序如下:
#include "stdio.h"
#define getpcb(type)(type*)malloc(sizeof(type))
#define NULL 0

struct pcb
{
char name[10];
char state;
int super;
int ntime;
int rtime;
struct pcb*link;
} *ready=NULL,*p;
typedef struct pcb PCB;

main()
{
int len,h=0;
char c;
input();
len=space();
while( (len!=0)&&(ready!=NULL) )
{
c=getchar();
h++;
printf("\nthe execute number:%d\n",h);
p=ready;
ready=p->link;
p->link=NULL;
p->state='R';
check();
running();
printf("\npress any key to continue...");
c=getchar();
}
printf("\n\n the process has been finished.\n");
c=getchar();
}

 

input ()
{
int i,num;
char k;
clrscr();
printf("\ninput process number?");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\ninput the process No.%d:\n",i);
p=getpcb(PCB);
printf("\nthe name of Process:");
scanf("%s",p->name);
printf("\nthe super of Process:");
scanf("%d",&p->super);
printf("\nthe time need:");
scanf("%d",&p->ntime);
printf("\n");
p->rtime=0;
p->state='W';
p->link=NULL;
sort();
}
}

int space()
{
int l=0;
PCB *pr=ready;
while(pr!=NULL)
{
l++;
pr=pr->link;

}
return(l);
}

check()
{
PCB *pr;
printf("\n***Now the process running is:%s",p->name);
disp(p);
pr=ready;
printf("\n***Now the ready quenue is:\n");
while(pr!=NULL)
{
disp(pr);
pr=pr->link;
}

}

disp(pr)
PCB *pr;
{
printf("\nqname\tstate\tsuper\tdtime\truntime\n");
printf("%s\t",pr->name);
printf("%c\t",pr->state);
printf("%d\t",pr->super);
printf("%d\t",pr->ntime);
printf("%d\t",pr->rtime);
printf("\n");
}

 

destory()
{
printf("\nprocess[%s] has finished:\n",p->name);
free(p);
}

  本课程设计包含完整源程序、可执行程序、设计文档。

 上一篇:编译原理设计报告
 下一篇:两台pc机之间的通讯-接口与通讯课程设计
本文版权归本站所有,欢迎转载。转载该文章时,请注明“来源:论文百事通 Http://www.lwbst.com”。
 
Copyright (C) 2008 Lwbst.com, All Rights Reserved 版权所有 论文百事通