读书笔记系列 - 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.


目录
相关文章
|
3月前
|
人工智能 关系型数据库 MySQL
让 Agent 真正"记住"项目:从会话记忆到长期记忆
本文探讨AI Agent记忆技术的演进:从受限的上下文窗口、无状态的RAG,到具备自动记录与推理能力的Agent Memory,最终走向系统化管理的上下文数据库(ContextDB),旨在让Agent真正成为“记住项目”的智能队友。
421 0
|
SQL 存储
milvus的attu里查询SQL如何编写
【6月更文挑战第4天】milvus的attu里查询SQL如何编写
1793 4
|
5G 调度 UED
5G中的动态频谱共享(DSS):高效利用频谱资源,加速5G网络演进
5G中的动态频谱共享(DSS):高效利用频谱资源,加速5G网络演进
3365 4
|
安全 测试技术 虚拟化
VMware-三种网络模式原理
本文介绍了虚拟机三种常见网络模式(桥接模式、NAT模式、仅主机模式)的工作原理与适用场景。桥接模式让虚拟机如同独立设备接入局域网;NAT模式共享主机IP,适合大多数WiFi环境;仅主机模式则构建封闭的内部网络,适用于测试环境。内容简明易懂,便于理解不同模式的优缺点与应用场景。
1957 0
|
人工智能 自然语言处理 前端开发
OpenAI 12天发布会全解析 | AI大咖说
OpenAI近日宣布将在12个工作日内每天进行一场直播,展示一系列新产品和样品。首日推出GPT-o1正式版,性能大幅提升;次日展示Reinforcement Fine-Tuning技术,提高模型决策质量;第三天推出Sora,实现高质量视频生成;第四天加强Canvas,提升多模态创作效率;第五天发布ChatGPT扩展功能,增强灵活性;第六天推出ChatGPT Vision,实现多模态互动;第七天推出ChatGPT Projects,优化项目管理。这些新技术正改变我们的生活和工作方式。
2572 9
|
机器学习/深度学习 人工智能 测试技术
Qwen2.5-Max 发布,探索大规模 MoE 模型的智能
Qwen2.5-Max 发布,探索大规模 MoE 模型的智能
|
人工智能 编解码 文字识别
阿里国际AI开源Ovis1.6,多项得分超GPT-4o-mini!
阿里国际AI团队提出了一种名为Ovis (Open VISion)的新型多模态大模型的架构。
物联网:“定向卡”与“通用卡”的区别
在讨论“定向卡”与“通用卡”的区别时,我们首先要明确这两种卡通常是在不同背景下被提及的,比如在营销、金融服务、会员卡系统等领域。不过,为了提供一个通用的、跨领域的理解,我们可以从以下几个维度来探讨它们的区别:
|
存储 缓存 PyTorch
使用PyTorch从零构建Llama 3
本文将详细指导如何从零开始构建完整的Llama 3模型架构,并在自定义数据集上执行训练和推理。
908 1
|
存储 Linux 测试技术
在Linux中,如何实现文件系统的快照和克隆?
在Linux中,如何实现文件系统的快照和克隆?