操作系统页面调度算法
来源:互联网 发布:java反射的用途 编辑:程序博客网 时间:2024/06/06 03:39
算法由python实现
1.先进先出置换算法
该算法是置换最早出现在stack里的页面,是最简单的页面置换算法,没有考虑程序的局部性原理
在这里设置stack的大小为3,为了模拟删除和插入一个页面,用了pop和insert方法,可以直接用p[locate] = value
def FIFC(pageList): p = [] locate = 0 num = 0 for i in pageList: if i not in p: if len(p) < 3: p.append(i) else: print ('current pageStack content :', p) p.pop(locate) p.insert(locate,i) locate = (locate + 1) % 3 num += 1 print ('current pageStack content :', p) print ('中断次数: {},页面置换{}次, 缺页率{}'.format(num,num-3,num/len(pageList) * 100))
2.最近最久为使用算法
这个算法考虑了程序的局部性原理,用最近的过去,模拟未来.
函数f是一个辅助函数,在开始更改每一个页面的未被访问的时间时候,用for,需要两次,使用这函数,直接调用map,用times来记录当前stack里的页面多久未被访问,数字越大,就是越久未被访问
def f(enumVlaue): if enumVlaue[0] == INDEX: enumVlaue[1] = 0 else: enumVlaue[1] += 1 return enumVlaue[1]def LRU(pageList): p = [] times = [0 for i in range(3)] num = 0 for i in pageList: if i not in p: if len(p) < 3: p.append(i) for j in range(len(p)-1): times[j] += 1 else: global INDEX INDEX = times.index(max(times)) print ('current pageStack content :{} current times : {}'.format(p,times)) p.pop(INDEX) p.insert(INDEX,i) times = list(map(f,[list(i) for i in enumerate(times)])) num += 1 else: INDEX = p.index(i) times = list(map(f,[list(i) for i in enumerate(times)])) print ('current pageStack content :',p) print ('中断次数: {},页面置换{}次, 缺页率{}'.format(num,num-3,num/len(pageList) * 100))
3.最佳置换算法
这个算法只是理论上的,无法实践,不知道后面页面的序列,算法从未来考虑当前
def OPT(pageList): p = [] num = 0 times = [0 for i in range(3)] for i in pageStack: if i not in p: if len(p) < 3: p.append(i) else: s = 0 loc = pageList.index(i) for j in pageList[loc:]: if j in p: times[p.index(j)] = 1 s += 1 if s == 2: break locate = times.index(0) p.pop(locate) p.insert(locate,i) times = [0 for i in range(3)] print ('current pageStack: content :',p) num += 1 print ('中断次数: {},页面置换{}次, 缺页率{}'.format(num,num-3,num/len(pageList) * 100))页面调用是数字表示
附一张运行最近最久未使用置换算法 截图
输入的数据是: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
阅读全文
0 0
- 操作系统页面调度算法
- 操作系统中的页面置换算法和磁盘调度算法
- java实现操作系统中的页面置换算法、进程调度算法、磁盘调度算法
- 操作系统调度算法
- 操作系统调度算法
- 操作系统调度算法
- 操作系统进程调度算法
- 操作系统磁道调度算法
- 操作系统课程:调度算法
- 操作系统 调度算法实验
- 【操作系统】进程调度算法
- 操作系统--进程调度算法
- 操作系统典型调度算法
- 【操作系统】实时调度算法
- 操作系统调度算法分析
- 操作系统调度算法简介
- 操作系统调度算法
- 操作系统典型调度算法
- 利用Python从文件中读取字符串(解决乱码问题)
- JAVA 数组、排序 day5
- 手机浏览器与我的那些事(三)
- Swift3.0视频教程
- 【Excel】vs2015利用mfc读excel时的类型
- 操作系统页面调度算法
- Linux学习——磁盘管理、用户管理、权限管理命令
- “gjw” is of a model that is not supported by this version of Xcode. Please use a different device.
- Controller相关
- SpringMVC企业开发实战
- 减少广播接收延时
- 一步一步学习:2、Spring-boot中web支持
- Invalidate(TRUE)与Invalidate(FALSE)区别
- Sicily 1259. Sum of Consecutive Primes |