操作系统 Operating System
Overview
This is really a hard-core course.
The operating system manages the computer's hardware and software resources.
It mainly includes the following functions:
- Process Management:
- Memory Management
- File Management
一、Process Management
A process is a collection of running programs and related resources.
When you open a software, one or more processes are created.
A process has multiple threads, which can be regarded as lightweight process.
Threads of the process share the resources of the process
1. Process Scheduling
The main task of process management is to schedule different processes.
1) Three Levels of Scheduling
The CPU Scheduling is complicated.
It has three levels:
-
High Level Scheduling: The task of it is to select jobs submitted by the user, and allocate resources and convert the jobs into processes.
-
Medium Level Scheduling: The task of it is to control the number of processes in memory.
Sometimes we need to suspend some processes to make room for other processes.
Suspend means swap process out of memory.
-
Low Level Scheduling: Process scheduling. It is responsible for scheduling all processes in the system.
2) Three States of Process
We focus on process scheduling.
Simply put, a process has three states: Running, Ready, and Blocked.
- Running: The Process is running in CPU
- Ready: Ready to run, queuing
- Blocked: Not ready to run, waiting for assignment.
3) Scheduling Algorithms
So, how do we actually schedule the process?
For that we have different strategies.
-
First Come First Serve: Always serve the first process.
But when the first process requires a lot of time, the following processes needs to wait a long time. We call this phenomenon hunger.
-
Shortest Job First: Serve the short jobs first. But when there are lots of short processes, long ones may be hungry.
-
Prioritized Scheduling: Each process has its own priority. The CPU always serves high-priority processes.
-
Round-Robin/Time Slices: This is the most fair algorithm. We call a period of time, such as 1 ms, a time slice.
Each process gets a number of time slices per round.
When the process runs out of time slices, it has to be swapped to ready queue.
When the time slice is too long, it just degenerates into FCFS algorithm.
2. Deadlock
During the scheduling process, some unexpected situations may occur between processes with overlapping resource requirements. Such as deadlock.
For example: Process 1 holds the Resource 1, and is waiting for Resource 2, which is hold by Process 1. Process 2 is waiting for Resource 1 which is hold by Process 1.
They are all waiting for each other to make a compromise., which is impossible.
We use Banker Algorithm to prevent deadlock.
For example,
- when you take a loan from a bank
- the bank needs to determine whether you are able to repay the loan
- Meanwhile, the bank also needs to consider, after lending the money to you, whether it can meet the needs of other lenders
In scheduling, loan is resources, and bank is the OS.
二、Memory Management
The task of memory management:
- optimize memory usage
- and expand memory through virtual memory technology
1. Page Memory Allocation
We use Page Memory Allocation to optimize memory usage.
Basic Idea of PMA:
-
Divide the logical address space of the process into Pages with same size. Like 128 KB.
-
Divide the physical memory space into Page Frames with same size of page.
Therefore, logical address consists of page number and page offset.
We use Page Table to store the page number and its corresponding page frame. So that we can immediately find the physical data.
2. Demand Paging Mechanism
We know that when the process is running, it is in the memory.
But sometimes we don’t need all the data of the process.
So, in order to save memory, the demand paging mechanism is introduced.
- We see disk as a part of memory, and then store part of data we currently need in memory and the rest in the disk.
- When we need data in the hard disk, we swap the page into memory
- At the same time, unneeded page is swapped out of memory.
1) Process of demand paging
This function relies on hardware MMU. Its main function is address translation.
2) Page Fault Processing
When can't find the data we want in memory, there is a page fault.
This is how we deal with it:
3) Elimination Algorithms
- Fist In First Out: Always eliminate pages that came first.
- Least Recently Used: Always eliminate pages least recently used.
三、File Management
The file management system is convenient for users to store and view files.
It mainly includes:
- Directory Hierarchy
- File Space Management
1. Directory Hierarchy
Commonly used hierarchy is tree.
2. Disk Space Management
We need to manage the storage space of disk.
Here are some methods:
1) Bitmap
Bitmap is like a matrix. Each bit stands for one physical block of disk.
1 means the block is occupied. 0 means free.
2) Free Block Table
We store informations of free blocks in a table, like its starting address and size.
When we need to allocate a file, we just scan the table and find the appropriate block.
3) Free Block Chain
All free blocks are chained together with a pointer to the first free block, and each free block contains a pointer to the next free block.
四、Curriculum Design
I wrote a program in Java to simulate a computer and OS, which implements the entire process of demand paging virtual memory management and three levels of scheduling.
1. Hardware
Hardware classes includes Clock, CPU, MMU, Hard Disk and Memory.
I use the free linked list method to manage disk space.
2. Software
For process scheduling, the scheduling algorithm I chose is Round-Robin with priority.
This OS also implements banker algorithm and deadlock management.
I use the LRU algorithm to implement page fault handling.
3. UI
I used Java Swing to design UI. User can create jobs and view the usage of memory and hard disk.
At the same time, there are two windows that display the scheduling details to the user in real time.
For example, the working process of the MMU, the pages allocated to the process.
原文地址:https://www.cnblogs.com/danielwong2021/p/15380770.html
- java虚拟机构造原理
- java造成内存泄露原因
- opensuse nginx+mono 2.8支持aspx环境的配置
- android-async-http详解
- java线程间通信
- android scrollview嵌套listview计算高度的问题
- 手把手教你安装深度学习软件环境(附代码)
- IntentService简介
- android 网络通信框架volly
- 仿iphone快速导航悬浮球
- WCF Data Service QuickStart
- 仿支付宝手势密码
- android仿iphone的地区选择
- WCF Data Service 的.NET Client 的不支持原生类型服务操作的解决方法
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- JavaWeb——ServletContext对象的使用及文件下载案例实战
- (最新 9000 字 )Spring Boot 配置特性解析
- JavaWeb——HTTP响应协议及Response对象使用方法一点通及案例实战(重定向、输出字符/字节数据到浏览器、验证码实现)
- drf序列化器之反序列化的数据验证
- yum仅下载不安装---保留rpm包
- Java——数据库编程JDBC之JDBCTemplate的使用简化数据库操作步骤(含增删改查练习实例源码)
- Java——数据库编程JDBC之数据库连接池技术(C3P0与Druid,提供了Druid的工具类)
- MySQL数据库——多表查询之内连接查询、外连接查询、子查询
- MySQL数据库——表的约束(非空约束、唯一约束、主键约束、外键约束)
- 如何取消rxjs Observable的订阅
- 使用Angular rxjs打印鼠标点击事件的x坐标之和
- js变量提升 和函数提升
- JavaWeb——HTTP请求协议及request对象使用方法一点通与request登录实战案例(含BeanUtils类的使用)
- redis学习(二十一)
- Linux下查看文件和文件夹大小