OS作业模拟进程分配与回收
OS的一个作业, 模拟进程的分配与管理
# initialize the memories and the process list(actually a dict)
total_memory = 110
os_memory = 10
process_memory = total_memory - os_memory
process = {}
sep_line_counter = 0
while 1:
# For the neatness of the output of the program
sep_line_counter += 1
print('----------------------Seperation Line %d--------------------------' % sep_line_counter)
# Input of choice, which is robustic here.
choice = input('Assign memory or recycle memory or quit?\nPlease enter--assgnment: 1, recycle: 2, quit: q\n:')
if not ( choice == 'q' or choice == '1' or choice == '2'):
print('Please enter the right choice.')
continue
if choice == 'q':
# Choose to quit
break
if int(choice) == 1:
# Choose to add a process
# Get name
cur_proc_name = input('Name of the process?\n:')
if cur_proc_name in process.keys():
# if name of current process has existed in the process list
print('The process you assigned has been created, no sharing of processes\' name.')
continue
# Get size
cur_proc_size = int(input('OK, and what about its size?\n:'))
if sum(process.values()) + int(cur_proc_size) > process_memory:
# With current process entering the process list, the list would overload
print('STOP ASSIGNMENT! Otherwise there\'s overload.')
print( 'The remaining memory: %d KB' % ( process_memory - sum(process.values()) ) )
print('The process list:', process)
continue
# No accidents, current process would be added into the process list
process[cur_proc_name] = cur_proc_size
print( 'The remaining memory: %d KB' % ( process_memory - sum(process.values()) ) )
print('The process list:', process)
continue
if int(choice) == 2:
# Choose to recycle a process
cur_proc_name = input('Name of the process?\n:')
if not cur_proc_name in process.keys():
# If you want to recycle some process that doesn't exist
print('No such process.')
continue
# No accidents, current process would be removed from the process list
del process[cur_proc_name]
print( 'The remaining memory: %d KB' % ( process_memory - sum(process.values() ) ) )
print('The process list:', process)
continue
本文版权归郑鹏(默盒)和博客园共有,原创文章,未经允许不得转载,否则保留追究法律责任的权利。
OS作业模拟进程分配与回收的更多相关文章
- OS作业模拟SJF和FCFS
一个OS的作业, 用于模拟短作业优先 和 先来先服务两种作业调度方式. #!/usr/bin/python3.5 ## Modify the SJF and FCFS algorithm in the ...
- 模拟linux的内存分配与回收
模拟linux的内存分配与回收 要求 通过深入理解内存分配管理的三种算法,定义相应的数据结构,编写具体代码. 充分模拟三种算法的实现过程,并通过对比,分析三种算法的优劣. (1)掌握内存分配FF,BF ...
- Erlang进程堆垃圾回收机制
原文:Erlang进程堆垃圾回收机制 作者:http://blog.csdn.net/mycwq 每一个Erlang进程创建之后都会有自己的PCB,栈,私有堆.erlang不知道他创建的进程会用到哪种 ...
- 图片系列(6)不同版本上 Bitmap 内存分配与回收原理对比
请点赞关注,你的支持对我意义重大. Hi,我是小彭.本文已收录到 GitHub · AndroidFamily 中.这里有 Android 进阶成长知识体系,有志同道合的朋友,关注公众号 [彭旭锐] ...
- Java深入 - Java 内存分配和回收机制
Java的GC机制是自动进行的,和c语言有些区别需要程序员自己保证内存的使用和回收. Java的内存分配和回收也主要在Java的堆上进行的,Java的堆中存储了大量的对象实例,所以Java的堆也叫GC ...
- 每个线程分配一个stack,每个进程分配一个heap;heap没有结构,因此寻址慢(转)
学习编程的时候,经常会看到stack这个词,它的中文名字叫做"栈". 理解这个概念,对于理解程序的运行至关重要.容易混淆的是,这个词其实有三种含义,适用于不同的场合,必须加以区分. ...
- 浅谈java内存分配和回收策略
一.导论 java技术体系中所提到的内存自动化管理归根结底就是内存的分配与回收两个问题,之前已经和大家谈过java回收的相关知识,今天来和大家聊聊java对象的在内存中的分配.通俗的讲,对象的内存分配 ...
- Android的内存分配与回收
想写一篇关于android的内存分配和回收文章的想法来源于追查一个魅族手机图片滑动卡顿问题,我们想了很多办法还是没有避免他不停的GC,所以就打算详细的看看内存分配和GC的原理,为什么会不断的GC,GC ...
- Java虚拟机垃圾回收:内存分配与回收策略 方法区垃圾回收 以及 JVM垃圾回收的调优方法
在<Java对象在Java虚拟机中的创建过程>了解到对象创建的内存分配,在<Java内存区域 JVM运行时数据区>中了解到各数据区有些什么特点.以及相关参数的调整,在<J ...
随机推荐
- 一个DOM元素同时拥有多个类名时的样式产生冲突时 属性取决于css样式表中后读取到的属性
如果一个DOM元素包含多个类名,其中的两个类名的属性产生冲突,并不是根据htnl中类名的顺序来决定DOM元素的属性, 而是根据css样式中的顺序来决定DOM元素的属性,它取决于css样式表中后读取到的 ...
- Ajax 向后台提交一个 JavaScript 对象数组?
var postArray= new Array(); var temp = new Object(); temp.id='1'; temp.name='test'; postArray.push(t ...
- 适合初学者的一个分布式环境搭建过程(spring boot + zookeeper + dubbo + mybatis + mysql)
本人也是才开始接触 阿里巴巴的开源分布式框架 dubbo,因为现在微服务框架 spring boot也非常的火,然后结合dubbo的官网搭建这个开发环境. 一.首先 zookeeper作为集群管理服务 ...
- Spark Standalone Mode Configuration
For currently popular distributed framework Spark, here is the intro and step to configure the spark ...
- 软考 程序员 下午考题 c语言 笔记
1. 数组名 是表示数组空间首地址的指针常量,程序中不允许对常量赋值. 如 int a[]; a就是数组名,表示数组控件首地址的指针常量 a = 0;是错误的,不允许对指针常量赋值 &a ...
- 架构之路 之 Nginx实现负载均衡
[前言] 在大型网站中,负载均衡是有想当必要的.尤其是在同一时间访问量比较大的大型网站,例如网上商城,新闻等CMS系统,为了减轻单个服务器的处理压力,我们引进了负载均衡这一个概念,将一个服务器的压力分 ...
- springJdbc like模糊查询,Spring namedParameterJdbcTemplate like查询
springJdbc like模糊查询,Spring namedParameterJdbcTemplate like查询, SpringJdbc命名参数like模糊查询,namedParameterJ ...
- vue vuex的用法
1.引入 vue.js vuex.js 文件 2.创建Store文件 var sSatte=new Vuex.Store({ state:{}, mutations:{}, actions:{ ...
- MongoDB 安装和配置
[前言] Mongodb是一款nosql数据库,关于nosql 以及 mongodb本文不进行介绍,在数据库的选型方面,本人说是在机缘巧合之下选择了mongodb,并且拟使用mongodb搭建日志系统 ...
- 51nod_1605:棋盘问题
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1605 题目中最有用的点其实还是x必为奇数 #include& ...