Skip to content
Self-Knowing

OSTEP

约 590 个字 预计阅读时间 2 分钟

认识操作系统

The primary way the OS does this is through a general technique that we call virtualization. That is, the OS takes a physical resource (such as the processor, or memory, or a disk) and transforms it into a more general, powerful, and easy-to-use virtual form of itself. Thus, we sometimes refer to the operating system as a virtual machine.

虚拟化:OS 把物理设备(处理器,内存,硬盘)转化为更通用的虚拟设备,所以我们称 operating system 为虚拟机器。

A typical OS, in fact, exports a few hundred system calls that are available to applications.

Because the OS provides these calls to run programs , access memory and devices and other related actions, we also sometimes say that the OS provides a standard libray to applications.

系统调用是提供给应用程序使用的,由 「用户态」 发出,进入 「内核态」 执行。

Indeed, that is exactly what is happening here as the OS is virtualizing memory. Each process accesses its own virtual address space(sometimes just called its address space), which the OS somehow maps onto the physical memory of the machine.

虚拟内存:允许 OS 将进程的 「虚拟地址」映射到 「物理地址」。

  • 每个进程都有自己的虚拟地址空间
  • 即使多个进程在 相同 的虚拟地址上分配内存,实际访问的物理地址也是不同的

You can think of a thread as a function running within the same memory space as other functions, with moew than one of them active at a time.

线程:

  • 同一个进程内的多个线程共享进程的内存空间
  • 多个线程可以在同一个进程中并发执行
  • 每个线程有各自独立的栈和寄存器状态,来保证执行不同的任务

「进程」是操作系统分配资源的最小单位;「线程」是 CPU 调度的基本单位。

如果多个线程同时执行同一个读写操作而没有适当的同步机制,就可能会出现竞争条件(race condition),导致结果不一致或错误。

So now u have some idea of what an OS actually does: it takes physical resources, such as a CPU, memory, or disk and virtualizes them. It handeles tough adn tricky issues related to concurrency, And it stores files persistently, thus making them safe over the long-term. Given that we want to build such a system, we want to have some goals in mind to help focus our design and implementation and make trade-offs as necessary; finding the right set of trade-offs is a key to building systems.

操作系统:

  • 接管物理设备,并虚拟化
  • 处理并发问题
  • 实现文件存储的持久化
  • 处理竞争问题,根据策略进行权衡。

Created: December 31, 2024
Last update: April 24, 2026

Discussion