操作系统实验处理机调度C语言实现.docxVIP

  • 9
  • 0
  • 约4.28千字
  • 约 9页
  • 2021-03-10 发布于天津
  • 举报
#in cludestdio.h #in cludestdlib.h #in elude coni o.h #in cludemath.h #defi ne N 20 #defi ne MAX 100 typedef struct PCB 〃pcb 进程控制块定义 { int num[N]; //进程序号 char name[10]; // 进程名 char state; //进程状态 int tijiaotime; II进程到达时间 int run time; II进程开始时间 int fini shtime; II进程结束时间 int needtime; II 服务时间 int pro;II进程优先级 struct PCB *n ext; II链接指针 指向下个作业的 }pcb; struct PCB *head_i nput; struct PCB *head_ru n; struct PCB *head_r un _pre; un sig ned long curre nt; II 记录系统当前时间的变量 int time=10000, n; II 计时器 pcb *head=NULL,*p,*q; void get In fo() II 创建进程 { int num; printf(\n请输入要建立的进程个数:”); scan f(%d, n); for(num=0;numn;nu m++) { p=(pcb *)malloc(sizeof(pcb)); if(head==NULL) {head=p;q=p;} printf(依次输入:\n进程号 进程名 到达时间 服务时间 \n); scan f(%s\t%s\t%d\t%d,p- num, p- name,p-tijiaotime,p- needtime); if(p-tijiaotime time) time=p-tijiaotime; q_n ext=p; p-r un time=0; p-fi ni shtime=0; } } p- next=NULL; p-state=W; q=p; } } // ********************* 1. 先来先服务调度算法 ******************************* void run_fcfo(pcb *p1)〃 定义先来先到服务的算法 { time = p1-tijiaotime time? p1-tijiaotime:time; p1-r un time=time; printf(\n现在时间是%d开始运行进程%s\n,time,p1-name); time+=p1- n eedtime; p1-state=F: p1-fi ni shtime=time; printf(进程名 开始时间 所需时间 结束时间\n); %dprin tf(%s %d %d %d ,p1- n ame,p1-r un time,p1- n eedtime,p1-fi ni shtime); } void fcfo()//定义运行进程函数 { int i,j,t; for(j=0;j n;j++) { p=head; t=10000; for(i=0;i n;i++) //找到当前未完成的进程 { if(p-tijiaotimet p-state==W) { t=p-tijiaotime; q=p; II标记当前未完成的进程 } p=p-n ext; *********************** *2. *********************** *2. run _fcfo(q); } } // 优先级调度服务算法 ************************************ int readydata() { //建立就绪队列 if(head_ in put- n ext==NULL) { return 0; } struct PCB *p1= head_input-next,*pmax,*p2; int maxpro=0xffff; pmax=p1; p2=head_ in put; while(p1!=NULL) { if(p1-promaxpro) { maxpro=p1-pro; head_r un _pre=p2; pmax=p1; } p2=p1; p1=p1- n ext; } head_r un=pmax; head_r un_pre-n ext=head_r un-n ext; return 1; } void runprocess() //运行进程函数 { head_r un-run time-=10; head_r un-pro++; struct PCB *p1,

文档评论(0)

1亿VIP精品文档

相关文档