处理机调度算法基于优先数调度算法实现

时间:2012-06-17 08:16:09
【文件属性】:

文件名称:处理机调度算法基于优先数调度算法实现

文件大小:258KB

文件格式:DOC

更新时间:2012-06-17 08:16:09

处理机调度算法,基于优先数调度算法实现,操作系统课程设计

3、详细设计(各个模块的算法实现,即各个用户自己的头文件) */首先定义头结点headnode来标志队首*/ #include #include #include 4、代码清单(包含头文件<用命令括进去即可#include……>和主函数) #include #include using namespace std; #define MAX 10 struct task_struct { char name[10]; /*进程名称*/ int number; /*进程编号*/ float come_time; /*到达时间*/ float run_begin_time; /*开始运行时间*/ float run_time; /*运行时间*/ float run_end_time; /*运行结束时间*/ int priority; /*优先级*/ int order; /*运行次序*/ int run_flag; /*调度标志*/ }tasks[MAX]; int counter; /*实际进程个数*/ int fcfs(); /*先来先服务*/ int ps(); /*优先级调度*/ int sjf(); /*短作业优先*/ int hrrn(); /*响应比高优先*/ int pinput(); /*进程参数输入*/ int poutput(); /*调度结果输出*/ int main() { int option; pinput(); printf("请选择调度算法(0~4):\n"); printf("1.先来先服务\n"); printf("2.优先级调度\n"); printf(" 3.短作业优先\n"); printf(" 4.响应比高优先\n"); printf(" 0.退出\n"); scanf("%d",&option); switch (option) { case 0: printf("运行结束。\n"); break; case 1: printf("对进程按先来先服务调度。\n\n"); fcfs(); poutput(); break; case 2: printf("对进程按优先级调度。\n\n"); ps(); poutput(); break; case 3: printf("对进程按短作业优先调度。\n\n"); sjf(); poutput(); break; case 4: printf("对进程按响应比高优先调度。\n\n"); hrrn(); poutput(); break; } } int fcfs() /*先来先服务*/ { float time_temp=0; int i; int number_schedul; time_temp=tasks[0].come_time; for(i=0;itasks[i].priority) { max_priority=tasks[j].priority; i=j; } j++; } /*查找第一个被调度的进程*/ /*对第一个被调度的进程求相应的参数*/ number_schedul=i; tasks[number_schedul].run_begin_time=tasks[number_schedul].come_time; tasks[number_schedul].run_end_time=tasks[number_schedul].run_begin_time+tasks[number_schedul].run_time; tasks[number_schedul].run_flag=1; temp_time=tasks[number_schedul].run_end_time; tasks[number_schedul].order=1; temp_counter=1; while (temp_countermax_priority) { max_priority=tasks[j].priority; number_schedul=j; } } /*查找下一个被调度的进程*/ /*对找到的下一个被调度的进程求相应的参数*/ tasks[number_schedul].run_begin_time=temp_time; tasks[number_schedul].run_end_time=tasks[number_schedul].run_begin_time+tasks[number_schedul].run_time; tasks[number_schedul].run_flag=1; temp_time=tasks[number_schedul].run_end_time; temp_counter++; tasks[number_schedul].order=temp_counter; }return 0; } int sjf() /*短作业优先*/ { float temp_time=0; int i=0,j; int number_schedul,temp_counter; float run_time; run_time=tasks[i].run_time; j=1; while ((jmax_respond_rate) { max_respond_rate=respond_rate; number_schedul=j; } } } /*找响应比高的进程*/ tasks[number_schedul].run_begin_time=temp_time; tasks[number_schedul].run_end_time=tasks[number_schedul].run_begin_time+tasks[number_schedul].run_time; temp_time=tasks[number_schedul].run_end_time; tasks[number_schedul].run_flag=1; temp_counter+=1; tasks[number_schedul].order=temp_counter; } return 0; } int pinput() /*进程参数输入*/ { int i; printf("please input the process counter:\n"); scanf("%d",&counter); for(i=0;i


网友评论

  • 不错的资料, 写得很详细. 谢谢
  • 对我的课设很有帮助
  • 很不错的资料,里面写得很详细,是很好的参考资料。刚好解救我的课程设计。