操作系统原理 实验1、2

1、高响应比作业调度

代码示例

#include<malloc.h>
#include<stdio.h>
#include<string.h>
#define NULL 0
#define N 10
typedef struct table
{char name[8];
float in_well;
float begin_run;
float end_run;
float run_time;
float turnover_time;
}jobtable;
void init(jobtable job[],int n)
{int i,j;printf("input %d job information\n",n);printf("in_well run_time name\n");for(i=0;i<n;i++){scanf("%f %f %s",&job[i].in_well,&job[i].run_time,job[i].name);job[i].begin_run=0.0;job[i].end_run=0.0;job[i].turnover_time=0.0;}
}
void print(jobtable job[],int n)
{int i;
printf("name in_well  run_time   begin_run   end_run  turnover_time\n");
for(i=0;i<n;i++)
{printf("%s\t%0.1f\t%0.1f\t",job[i].name,job[i].in_well,job[i].run_time);
if(job[i].begin_run==0.0&&job[i].end_run==0.0&&job[i].turnover_time==0.0)
printf("                       \n");
else printf("%9.1f%9.1f\t%0.1f\n",job[i].begin_run,job[i].end_run,job[i].turnover_time);}
}
void swap(jobtable job[],int p,int q)
{float temp1;
char temp2[8];
strcpy(temp2,job[p].name);
strcpy(job[p].name,job[q].name);
strcpy(job[q].name,temp2);
temp1=job[p].in_well;
job[p].in_well=job[q].in_well;
job[q].in_well=temp1;
temp1=job[p].run_time;
job[p].run_time=job[q].run_time;
job[q].run_time=temp1;
}
float response_ratio(jobtable job[],int n)
{int i,j,temp;
float average_time,ratio1,ratio2;
job[0].begin_run=job[0].in_well;
job[0].end_run=job[0].begin_run+job[0].run_time;
job[0].turnover_time=job[0].end_run-job[0].begin_run;
average_time=job[0].turnover_time;
for(i=1;i<n;i++)
{if(job[i].in_well<=job[i-1].end_run)
{j=i+1;temp=i;
ratio1=1+(job[i-1].end_run-job[i].in_well)*1.0/job[i].run_time;
while(j<n&&job[i].in_well<=job[i-1].end_run)
{ratio2=1+(job[i-1].end_run-job[i].in_well)*1.0/job[j].run_time;
if(ratio2>ratio1)
temp=j;
j++;
}
if(temp!=i)
swap(job,i,temp);
}
job[i].begin_run=job[i-1].end_run;
job[i].end_run=job[i].begin_run+job[i].run_time;
job[i].turnover_time=job[i].end_run-job[i].in_well;
average_time=average_time+job[i].turnover_time;}
return(average_time/n);}
int main()
{int n;
float ave_turnover_time;
jobtable job[N];
printf("input job numbers\n");
scanf("%d",&n);
if(n<=N)
{printf("按照进入输入井的顺序的先后顺序初始化作业表\n");
init(job,n);
printf("init station\n");
print(job,n);
ave_turnover_time=response_ratio(job,n);
printf("termiajfi station\n");
print(job,n);
printf("ave_turnover_time is:%12.1f\n",ave_turnover_time);}
else printf("error!\n");
}

输出结果

2、时间片轮转进程调度

代码示例

#include<stdio.h>
#include<stdlib.h>
struct PCB
{int pid;
int rr;
int time;
char sta;
struct PCB *next;
};
struct PCB pcb1,pcb2,pcb3,pcb4,pcb5,*tail,*head,*rp;
void init()
{int time;pcb1.pid=1;pcb2.pid=2;pcb3.pid=3;pcb4.pid=4;pcb5.pid=5;pcb1.rr=pcb2.rr=pcb3.rr=pcb4.rr=pcb5.rr=0;pcb1.sta=pcb2.sta=pcb3.sta=pcb4.sta=pcb5.sta='w';printf("请输入p1");scanf("%d",&time);pcb1.time=time;printf("请输入p2");scanf("%d",&time);pcb2.time=time;printf("请输入p3");scanf("%d",&time);pcb3.time=time;printf("请输入p4");scanf("%d",&time);pcb4.time=time;printf("请输入p5");scanf("%d",&time);pcb5.time=time;pcb1.next=&pcb2;pcb2.next=&pcb3;pcb3.next=&pcb4;pcb4.next=&pcb5;pcb5.next=&pcb1;head=&pcb1;tail=&pcb5;
}
void printf1()
{printf("+----------------|----------------|---------------|-----------------+\n");
printf("|\tpid\t|\trr\t|\ttime\t|\tSTA\t|\n");
printf("|----------------|----------------|---------------|-----------------|\n");
}
void printf2()
{printf("processes p%d running\n",head->pid);
printf1();
printf("|\t%d\t|\t%d\t|\t%d\t|\t%c\t|\n",head->pid,head->rr,head->time,head->sta);
printf("|----------------|----------------|---------------|-----------------|\n");
rp=head;
while(rp!=tail)
{rp=rp->next;
printf("|\t%d\t|\t%d\t|\t%d\t|\t%c\t|\n",rp->pid,rp->rr,rp->time,rp->sta);
printf("|----------------|----------------|---------------|-----------------|\n");
}
}
void operation()
{int flag=1;
while(flag<=5)
{head->rr++;
if((head->rr==head->time)||(head->time==0))
{tail->sta='w';
head->sta='f';
printf2();
head=head->next;
tail->next=head;
flag++;
}
else
{tail->sta='w';
head->sta='r';
printf2();
tail=head;head=head->next;
}
}
}
void main()
{init();
printf2();
operation();
}

输出结果



操作系统原理 实验1、2相关推荐

  1. ZUCC_操作系统原理实验_Lab9进程的通信消息队列

    lab9进程的通信–消息队列 一.两个进程并发执行,通过消息队列,分别进行消息的发送和接收 1.代码: //接受消息 #include<stdio.h> #include<stdli ...

  2. ZUCC_操作系统原理实验_实验九 消息队列

    操作系统原理实验报告 课程名称 操作系统原理实验 实验项目名称 实验九 消息队列 实验目的 了解 Linux 系统的进程间通信机构 (IPC): 理解Linux 关于消息队列的概念: 掌握 Linux ...

  3. 操作系统原理实验-进程同步

    操作系统原理实验报告 实验题目 实验二进程同步 实验二.进程同步 1.1 实验目的 现代操作系统的核心是多道程序设计.多处理器和分布式处理器,这些方案和操作系统设计技术的基础都是并发.当多个进程并发执 ...

  4. 操作系统原理实验二(三)

    继续完成操作系统原理的实验 4.5(实验目的:熟悉Window线程创建过程)在windows环境下,利用高级语言编程环境(限定为VS环境或VC环境)调用CreateThread函数实现"并发 ...

  5. 操作系统原理实验(3):操作系统的基石中断与异常

    一.实验目的 中断.异常和陷阱指令(合称类中断)是操作系统的基石,现代操作系统就是由(类)中断驱动的.本实验的目的在于深刻理解(类)中断的原理和机制,掌握 CPU 访问设备控制器的方法,掌握 x86 ...

  6. 操作系统原理实验(5):内存管理

    一.实验目的 分页内存管理是内存管理的基本方法之一.本实验的目的在于全面理解分页式内存管理的基本方法以及访问页表,完成地址转换等的方法. 二.实验过程&错误 内容(一):设计不同的方式引发页错 ...

  7. 操作系统原理实验(四)深渊:竞争条件与死锁(硬件中断)

    硬件中断 中断控制器 启动中断 处理定时器中断 死锁 竞争条件 HLT指令 键盘输入 中断控制器 中断提供了一种从附加硬件设备通知CPU的方法.这个英特尔8259是1976年推出的可编程中断控制器(P ...

  8. ZUCC 操作系统原理实验 模拟考试

    由ZUCC INTERSECTION题库提供答案. 判断题 1.当同时需要用两个互斥信号量时,总是让它们以交错的顺序加锁,以避免死锁. 编号 选项 A T B F 2.由signal()注册的信号只是 ...

  9. 模拟进程创建、终止、阻塞、唤醒原语(操作系统原理实验)

    0

最新文章

  1. shell test命令
  2. cvc-complex-type.3.2.2: 元素 'constructor-arg' 中不允许出现属性 'name'
  3. Java学习笔记17
  4. Altium Protel PCB Layer
  5. 用共振频率去理解神经网络-将乙烯模型运行300次的数据
  6. linux命令系列-zip(压缩打包)
  7. Vue父组件向子组件传值
  8. labview 快捷键
  9. 配置linux danted socks服务
  10. java非主流火星文输入法_火星文输入法
  11. java整形数组的最大最小值
  12. windows7 内部版本7601,此windows副本不是正版
  13. Android Studio Gradle打包实践之多渠道+版本号管理
  14. 短文本分类:电力95598工单分类实现
  15. 【Gulimall+】第三方服务:对象存储OSS、短信验证、社交登录、支付宝支付
  16. php特性之intval学习小记
  17. Zabbix poller processes more than 75% busy报错解决方案
  18. SecoClient 警告:当前服务进程已退出或关闭,请尝试重新安装客户端!
  19. 京东长虹网店被组团薅羊毛:3小时抢拍20万单
  20. 钢材规格解读的软件_钢材重量计算软件下载-钢材重量手册2020版下载 v3.71免费版--pc6下载站...

热门文章

  1. Python实现商品价格监控,识破双十一的套路
  2. 黄仁勋:英伟达收购 ARM 是谣言,下周发布会有惊喜
  3. 流密码:线性同余生成器 LCG
  4. ShareSDK Android端分享与授权示例代码
  5. 在计算机网络中发送电子邮件遵循的协议是,运行在互联网上用于电子邮件发送的协议是...
  6. U递是一款App软件 和滴滴打车一样性质
  7. python中tuple、list以及array(numpy的数据格式)的相互转换
  8. IDEA Maven 多module项目导入 pom文件报错解决记录
  9. Git (代码托管)
  10. 计算机实战项目之 论文辩论PPT+源码等]精品微信小程序ssm培训机构管理系统+后台管理系统