读书笔记系列 - Operating Systems: Three Easy Pieces - Virtualization - Chapter 4: Processes

简介: 读书笔记系列 - Operating Systems: Three Easy Pieces - Virtualization - Chapter 4: Processes

4. Processes

  1. The definition of a process, informally, is quite simple: it is a running program.
  2. The program itself is a lifeless thing: it just sits there on the disk, a bunch of instructions (and maybe some static data), waiting to spring into action.
  3. This basic technique, known as time sharing of the CPU, allows users to run as many concurrent processes as they would like; the potential cost is performance, as each will run more slowly if the CPU(s) must be shared.
  4. To implement virtualization of the CPU, and to implement it well, the OS will need both some low-level machinery and some high-level intelligence.
  5. We call the low-level machinery mechanisms; mechanisms are low-level methods or protocols that implement a needed piece of functionality.
  6. On top of these mechanisms resides some of the intelligence in the OS, in the form of policies. Policies are algorithms for making some kind of decision within the OS.


4.1 TheAbstraction: A Process

  1. A process is simply a running program; at anyinstant in time, we can summarize a process by taking an inventory of the different pieces of the system it accesses or affects during the course of its execution.
  2. Machine state: what a program can read or update when it is running. At any given time, what parts of the machine are important to the execution of this program?
  3. Memory; Registers.
  4. TIP: SEPARATE POLICY AND MECHANISM


4.2 Process API

  1. Create: An operating system must include some method to create new processes.
  2. Destroy: As there is an interface for process creation, systems also provide an interface to destroy processes forcefully.
  3. Wait: Sometimes it is useful to wait for a process to stop running; thus some kind of waiting interface is often provided.
  4. Miscellaneous Control: Other than killing or waiting for a process, there are sometimes other controls that are possible. For example, most operating systems provide some kind of method to suspend a process (stop it from running for a while) and then resume it (continue it running).
  5. Status: There are usually interfaces to get some status information about a process as well, such as how long it has run for, or what state it is in.

4.3 Process Creation: A Little More Detail

  1. Loading: From Program To Process
  2. The first thing that the OS must do to run a programis to load its code and any static data (e.g., initialized variables) into memory, into the address space of the process.
  3. Once the code and static data are loaded into memory, there are a few other things the OS needs to do before running the process. Some memory must be allocated for the program’s run-time stack (or just stack).
  4. The OS may also allocate some memory for the program’s heap.
  5. The OS will also do some other initialization tasks, particularly as related to input/output (I/O).
  6. By loading the code and static data into memory, by creating and initializing a stack, and by doing other work as related to I/O setup, the OS has now (finally) set the stage for program execution. It thus has one last task: to start the program running at the entry point, namely main(). By jumping to the main() routine (through a specialized mechanism that we will discuss next chapter), the OS transfers control of the CPU to the newly-created process, and thus the program begins its execution.


4.4 Process States

  1. In a simplified view, a process can be in one of three states:
  2. Running: In the running state, a process is running on a processor. This means it is executing instructions.
  3. Ready: In the ready state, a process is ready to run but for some reason the OS has chosen not to run it at this given moment.
  4. Blocked: In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes place. A common example: when a process initiates an I/O request to a disk, it becomes blocked and thus some other process can use the processor.
  5. Process: State Transitions
  6. Being moved from ready to running means the process has been scheduled; being moved from running to ready means the process has been descheduled. Once a process has become blocked (e.g., by initiating an I/O operation), the OS will keep it as such until some event occurs (e.g., I/O completion); at that point, the process moves to the ready state again (and potentially immediately to running again, if the OS so decides).

4.5 Data Structures

  1. The register context will hold, for a stopped process, the contents of its registers. When a process is stopped, its registers will be saved to this memory location; by restoring these registers (i.e., placing their values back into the actual physical registers), the OS can resume running the process. We’ll learn more about this technique known as a context switch in future chapters.
  2. Sometimes a system will have an initial state that the process is in when it is being created. Also, a process could be placed in a final state where it has exited but has not yet been cleaned up. This final state can be useful as it allows other processes (usually the parent that created the process) to examine the return code of the process and see if the just-finished process executed successfully (usually, programs return zero in UNIX-based systems when they have accomplished a task successfully, and non-zero otherwise). When finished, the parent will make one final call (e.g., wait()) to wait for the completion of the child, and to also indicate to the OS that it can clean up any relevant data structures that referred to the now-extinct process.


目录
打赏
0
0
0
0
6
分享
相关文章
【openstack】问题记录:实例创建失败?(未解决)
【openstack】问题记录:实例创建失败?(未解决)
1628 0
【openstack】问题记录:实例创建失败?(未解决)
Python代码覆盖率分析工具----Coverage
Python代码覆盖率分析工具----Coverage
484 0
改进的yolov5目标检测-yolov5替换骨干网络-yolo剪枝(TensorRT及NCNN部署)-2
改进的yolov5目标检测-yolov5替换骨干网络-yolo剪枝(TensorRT及NCNN部署)-2
改进的yolov5目标检测-yolov5替换骨干网络-yolo剪枝(TensorRT及NCNN部署)-2
GitHub爆赞!终于有大佬把《Python学习手册》学习笔记分享出来了
这份笔记的目标是为了给出一份比较精炼,但是又要浅显易懂的Python教程。《Python学习手册》中文第四版虽然比较简单,但是措辞比较罗嗦,而且一个语法点往往散落在多个章节,不方便读者总结。 我在做笔记时,将一个知识点的内容都统筹在一个章节里面,因此提炼性大大提高。而且还有《Python学习手册》中文第四版的翻译在某些章节(可能难度较大?)措辞可能前后矛盾。当知识点提炼之后就能够很快的找到一些难以理解的概念的上下文,方便吃透这些难点。
|
10月前
OpenStack技术栈-OpenStack环境初始化
文章介绍了如何配置网卡bond模式,搭建时间同步服务器,并提供了OpenStack环境初始化的步骤和建议。
140 1
OpenStack技术栈-OpenStack环境初始化
CentOS 7上安装 Jenkins 2.227 -- yum 方式
CentOS 7上安装 Jenkins 2.227 -- yum 方式
286 0
mongodb是怎么分库分表的
综上所述,MongoDB的分库分表实践是一门综合技术与业务洞察的艺术。从精确的分片键选择到集群的精心搭建,再到策略的灵活运用,每一步都需细致规划。提供的高性能云服务,可以更加便捷地搭建和维护这样的分布式数据库环境,为企业级应用带来前所未有的扩展性和可靠性。
293 0
Zabbix 5.0 LTS的web界面安装及修改zabbix web管理员的默认密码
这篇文章是关于如何安装Zabbix 5.0 LTS的web界面以及如何修改Zabbix web管理员默认密码的教程。
487 1
C# | 凸包算法之Andrew‘s,获取围绕一组点的凸多边形的轮廓点
这篇关于凸包算法的文章,本文使用C#和Andrew’s算法来实现凸包算法。 首先消除两个最基本的问题: 什么是凸包呢? 凸包是一个包围一组点的凸多边形。凸多边形是指多边形中的每个内角都小于180度的多边形。 凸包算法有什么用呢? 凸包算法的作用是找到这个凸多边形,并且使用最少的点来绘制出它的轮廓。凸包算法在计算机图形学、计算几何和机器学习等领域中有着广泛的应用。
302 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问