资源简介
操作下系统的实验报告,第一个实验选的是那个设计一个先来先服务的调度算法
代码片段和文件信息
#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
- 上一篇:OfficeLiteV4.1.7.txt.zip
- 下一篇:若水NPC破解版
相关资源
- Linux设备驱动
- Linux内存分配与回收
- 广东工业大学_数据结构内部排序算法
- 请求调页存储管理系统的模拟实现
- 哈夫曼编码译码实验报告
- 操作系统考研复习重点大全65页
- 《Linux环境编程》编程题答案及实验报
- 操作系统银行家算法两个
- 广工操作系统课程设计文档+代码+可执
- 磁盘调度先来先服务,最短寻道时间
- 处理机调度算法实现文档+代码
- 59分59秒计时器实验报告
- 实验2 Linux内核编译及系统调用添加
- 页面置换算法,操作系统实验
- 操作系统英语论文
- 支持VMWare Esxi6.7虚拟机操作系统,VM
- 数据结构实验报告---数制转换
- 东北大学操作系统大作业实验报告
- EDA实验报告 异步清除十进制加法计数
- 计算机组成原理实验报告8份
- 计算机操作系统(第三版)课后习题
- 多线程读者阅览室课程设计
- 操作系统期末考试试题含答案
- xv6操作系统整体报告
- 数据结构八皇后问题实验报告
- 进程调度算法包括先来先服务调度算
- 操作系统 内存管理课程设计报告
- 多级反馈队列进程调度Swing实现源代码
- PGP加密实验报告PGP加密
- PGP加密实验报告DOC版
评论
共有 条评论