资源简介

操作下系统的实验报告,第一个实验选的是那个设计一个先来先服务的调度算法

资源截图

代码片段和文件信息

#include
#include
//#include 
#define N 20 //进程名字最多支持20个字符

typedef struct pcb
{
char pname[N]; //进程名字
int runtime; //进程估计运行的时间
int arrivetime; //进程到达时间
char state; //进程状态
struct pcb *next;//连接指针
}PCB;

PCB head_input; //链表的头
PCB *queue_head*queue_end;//模拟队列的头和尾指针
//FILE *f; //文件保存
int sum_turnaroundtime=0;//总周转时间
int num; //总进程数目
static char R=‘r‘C=‘c‘;
unsigned long current; //系统当前时间,按秒计算
void inputprocess(); //创建进程的子函数,按照到达时间进入队列
void runreadyprocess(); //运行就绪的队列


void runreadyprocess()
{
int i=0timeruntime1;
PCB *p1;
while(queue_end!=NULL)
{
i++;
p1=queue_end;
while((unsigned long)p1->arrivetime>current)//如果到达时间大于当前时间,等待
current++;

printf(“NO. %3d process %s has started!\n“ip1->pname);
time=0;runtime1=p1->runtime;
while(p1->runtime>0)//运行进程,先来先服务,运行完先来的,再运行下一个
{
p1->runtime--;
time++;
current++;
printf(“NO. %3d process %s has run %ds  still has %ds to complete!\n“ip1->pnametimeruntime1-time);
}
p1->state=C;        //进程运行完,更改状态

printf(“NO. %3d process %s has completed!\n“ip1->pname);
printf(“NO. %3d process %s‘s turnaround_time is : %d\n“ip1->pnamecurrent-p1->arrivetime);
printf(“\n“);
sum_turnaroundtime+=current-p1->arrivetime;

queue_end=queue_head->next;
queue_head=queue_end;
}

}


void inputprocess()
{
PCB *p1*p2;

printf(“How many processes do you want to run: “);
//fprintf(f“How many processes do you want to run: “);
scanf(“%d“&num);
//fprintf(f“%d\n“&num);


p1=&head_input;
p2=p1;
p1->next=new PCB;
p1=p1->next;
for(int i=0;i {
printf(“NO. %3d processes input pname: “i+1);
//fprintf(f“NO. %3d processes input pname: “i+1);
scanf(“%s“p1->pname);
//fprintf(f“%s\n“p1->pname);

printf(“NO. %3d processes runtime: “i+1);
//fprintf(f“NO. %3d processes runtime: “i+1);
scanf(“%d“&(p1->runtime));
//fprintf(f“%d\n“&(p1->runtime));

printf(“NO. %3d processes arrivetime: “i+1);
//fprintf(f“NO. %3d processes arrivetime: “i+1);
scanf(“%d“&(p1->arrivetime));
//fprintf(f“%d\n\n“&(p1->arrivetime));
printf(“\n“);

p1->state=R;
p1->next=new PCB;
p2=p1;
p1=p1->next;
}
delete p1;
p1=NULL;
p2->next=NULL;
}

void main()
{
//f=fopen(“result.txt““w“);
current=0;
inputprocess();

queue_head=&head_input;
queue_end=queue_head->next;
queue_head=queue_end;

runreadyprocess();

printf(“The average turnaround_time of all the processes is :  %d\n“sum_turnaroundtime/num);
//system( “type result.txt“ ); 
}







 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2827  2010-03-26 14:34  12110703-20072844-张战友-操作系统模拟算法实验\ProcessFifo.cpp

     文件     134144  2010-03-26 14:48  12110703-20072844-张战友-操作系统模拟算法实验\操作系统实验报告-12110703-20072844-张战友.doc

     目录          0  2010-03-26 14:49  12110703-20072844-张战友-操作系统模拟算法实验

----------- ---------  ---------- -----  ----

               136971                    3


评论

共有 条评论