📚 Operating Systems for IB OCR Computer Science | IB OCR 计算机:操作系统 考点精讲
An operating system (OS) is the fundamental software that manages computer hardware, software resources, and provides common services for computer programs. For IB and OCR computer science students, understanding the core principles of operating systems is essential, as it bridges the gap between hardware and application software. This revision guide covers key topics including process management, memory management, file systems, concurrency, interrupts, scheduling, and virtualisation, ensuring you are well-prepared for exam questions.
操作系统(OS)是管理计算机硬件、软件资源并为程序提供通用服务的基础软件。对于IB和OCR计算机科学学生,掌握操作系统的核心原理至关重要,它连接了硬件与应用软件。本考点精讲涵盖进程管理、内存管理、文件系统、并发、中断、调度和虚拟化等关键主题,确保你为考试做好充分准备。
1. What is an Operating System? | 什么是操作系统?
An operating system is a layer of software that acts as an intermediary between the user, application programs, and the computer hardware. It provides an environment in which a user can execute programs conveniently and efficiently. The OS hides the complexity of hardware by presenting a simpler, hardware-independent interface through system calls and APIs.
操作系统是位于用户、应用程序和计算机硬件之间的一层软件。它为用户方便高效地执行程序提供环境。OS通过系统调用和API隐藏硬件复杂性,呈现一个更简单且与硬件无关的接口。
The kernel is the core component of an OS, managing the system’s resources such as the CPU, memory, and I/O devices. The user interface, whether command-line or graphical, runs on top of the kernel. Key examples of modern operating systems include Microsoft Windows, Linux distributions, macOS, Android, and iOS.
内核是OS的核心组件,管理CPU、内存和I/O设备等系统资源。用户界面(无论是命令行还是图形界面)运行在内核之上。现代操作系统的主要示例包括Microsoft Windows、Linux发行版、macOS、Android和iOS。
2. Functions of an Operating System | 操作系统的功能
The OS performs several critical functions. Process management involves creating, scheduling, and terminating processes. Memory management keeps track of which parts of memory are in use and allocates space to processes. File system management organises data on storage devices into files and directories. I/O device management handles communication with peripherals through device drivers.
操作系统执行几个关键功能。进程管理包括创建、调度和终止进程。内存管理跟踪哪些内存正被使用并给进程分配空间。文件系统管理将存储设备上的数据组织成文件和目录。I/O设备管理通过设备驱动程序处理与外围设备的通信。
In addition, the OS ensures security and protection by controlling access to resources and providing user authentication. Networking enables processes to communicate across different machines using protocols such as TCP/IP. The OS also offers error detection and recovery, handling hardware failures and software crashes gracefully.
此外,OS通过控制资源访问和提供用户认证来确保安全与保护。网络功能使进程利用TCP/IP等协议跨机器通信。OS还提供错误检测与恢复,妥善处理硬件故障和软件崩溃。
3. Process Management | 进程管理
A process is a program in execution. It consists of the program code, program counter, registers, and associated data. The OS maintains a Process Control Block (PCB) for each process, which stores its state, priority, memory pointers, and accounting information. Processes can be in one of several states: new, ready, running, waiting, or terminated.
进程是正在执行的程序。它由程序代码、程序计数器、寄存器和相关数据组成。OS为每个进程维护一个进程控制块(PCB),其中存储其状态、优先级、内存指针和记账信息。进程可以处于以下几种状态之一:新建、就绪、运行、等待或终止。
Context switching is the mechanism by which CPU switches from one process to another. It involves saving the state of the current process into its PCB and loading the state of the next process. Although essential for multitasking, context switching incurs overhead because the CPU performs no useful work during the switch.
上下文切换是CPU从一个进程切换到另一个进程的机制。它涉及将当前进程的状态保存到其PCB中并加载下一个进程的状态。虽然对多任务处理至关重要,但上下文切换会产生开销,因为CPU在切换期间不执行有效工作。
4. Threads and Multithreading | 线程与多线程
A thread is a lightweight unit of execution within a process. Multiple threads within the same process share the same address space, code, and data, but possess their own stack and registers. Multithreading improves application responsiveness and resource utilisation because threads can run concurrently, especially on multicore processors.
线程是进程内的轻量级执行单元。同一进程内的多个线程共享相同的地址空间、代码和数据,但拥有各自的栈和寄存器。多线程可提高应用程序的响应速度和资源利用率,因为线程可以并发运行,尤其是在多核处理器上。
User-level threads are managed entirely by user libraries, so context switches between them avoid kernel intervention and are very fast. However, they do not benefit from true parallelism on multicore systems. Kernel-level threads, on the other hand, are scheduled directly by the OS kernel, allowing true concurrency but incurring higher management overhead.
用户级线程完全由用户库管理,因此它们之间的上下文切换避免了内核干预且速度非常快。但它们无法在多核系统上获得真正的并行性。相反,内核级线程由OS内核直接调度,可实现真正的并发,但会产生更高的管理开销。
5. CPU Scheduling | CPU调度
CPU scheduling determines which process gets the CPU when multiple processes are ready. The goal is to maximise CPU utilisation, throughput, and fairness while minimising turnaround time, waiting time, and response time. Scheduling algorithms can be preemptive, where the OS can take the CPU away from a running process, or non-preemptive, where a process holds the CPU until it voluntarily releases it.
CPU调度决定当多个进程就绪时哪个进程获得CPU。目标是最大化CPU利用率、吞吐量和公平性,同时最小化周转时间、等待时间和响应时间。调度算法可以是抢占式的,即OS可以从正在运行的进程夺走CPU,也可以是非抢占式的,即进程持有CPU直到其自愿释放。
Common algorithms include First Come First Served (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round Robin (RR). The table below summarises their key properties.
常见算法包括先到先服务(FCFS)、最短作业优先(SJF)、优先级调度和轮转调度(RR)。下表总结了它们的关键特性。
| Algorithm | Preemptive? | Advantage | Disadvantage |
|---|---|---|---|
| FCFS | No | Simple to implement | Convoy effect; long average wait |
| SJF | Both possible | Minimises average waiting time | Starvation of longer jobs |
| Priority | Both possible | Serves high-priority quickly | Starvation; priority inversion |
| Round Robin | Yes | Fair; low response time | High context switch overhead |
6. Memory Management | 内存管理
Memory management handles the allocation and deallocation of RAM among processes. In early systems, a single contiguous allocation model was used, but this led to fragmentation. Modern systems use paging, where logical memory is divided into fixed-size pages and physical memory into frames of the same size. The memory management unit (MMU) translates virtual addresses to physical addresses using a page table.
内存管理负责在进程之间分配和回收RAM。早期系统使用单一连续分配模型,但这导致了碎片。现代系统采用分页技术,逻辑内存被划分为固定大小的页,物理内存被划分为相同大小的帧。内存管理单元(MMU)使用页表将虚拟地址转换为物理地址。
Segmentation divides memory into variable-sized logical segments such as code, stack, and heap. Segmentation with paging combines both approaches, using segments that are internally paged. This provides the benefits of modularisation and efficient memory use, but adds complexity to address translation.
分段将内存划分为可变大小的逻辑段,如代码段、栈和堆。分段结合分页同时使用两种方法,内部采用分页的段。这提供了模块化和高效内存使用的优点,但增加了地址转换的复杂性。
7. Virtual Memory | 虚拟内存
Virtual memory is a technique that allows execution of processes that are not completely in main memory. It creates an illusion of a large, contiguous address space for each process, even if physical memory is limited. This is achieved by demand paging, where pages are loaded only when needed. If a required page is not in memory, a page fault occurs, and the OS fetches the page from secondary storage.
虚拟内存是一种允许执行不完全在主存中的进程的技术。它为每个进程创建了一个大而连续的地址空间的错觉,即使物理内存有限。这是通过请求分页实现的,仅当需要时页面才被加载。如果所需页面不在内存中,则发生缺页中断,OS会从二级存储器获取该页。
Page replacement algorithms decide which page to evict when memory is full. Common algorithms include FIFO (First In First Out), LRU (Least Recently Used), and the optimal algorithm. LRU replaces the page that has not been used for the longest time, which approximates optimal behaviour but is harder to implement efficiently.
页面置换算法决定当内存满时应淘汰哪个页面。常见算法包括FIFO(先进先出)、LRU(最近最少使用)和最优算法。LRU替换最长时间未使用的页面,接近最优行为但难以高效实现。
8. Interrupts and Interrupt Handling | 中断与中断处理
An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. Hardware interrupts come from devices like keyboards or network cards; software interrupts originate from executing instructions (e.g., division by zero) or system calls. Interrupts are fundamental to the operation of an OS as they allow it to respond to asynchronous events.
中断是硬件或软件向处理器发出的信号,表示需要立即关注的事件。硬件中断来自键盘或网卡等设备;软件中断源于执行指令(如除零)或系统调用。中断对OS运行至关重要,因为它使OS能够响应异步事件。
When an interrupt occurs, the processor saves the current state on the stack, disables further interrupts, and jumps to the appropriate Interrupt Service Routine (ISR). After the ISR executes, the original context is restored and execution resumes. The interrupt vector table stores the addresses of ISRs, indexed by interrupt number.
当中断发生时,处理器将当前状态保存在栈上,禁用进一步中断,并跳转到相应的中断服务程序(ISR)。ISR执行完毕后,恢复原始上下文并继续执行。中断向量表存储ISR的地址,按中断号索引。
9. Concurrency and Synchronisation | 并发与同步
Concurrency arises when multiple threads or processes execute simultaneously or in an interleaved fashion. Without proper synchronisation, race conditions can occur, where the outcome depends on the relative timing of events. The critical section problem describes the need to ensure that only one process executes the shared-resource access code at a time.
当多个线程或进程同时或以交错方式执行时,就出现了并发。若无适当同步,可能发生竞态条件,此时结果取决于事件的相对时序。临界区问题描述了确保每次只有一个进程执行共享资源访问代码的必要性。
Solutions include mutual exclusion mechanisms such as semaphores, mutex locks, and monitors. A binary semaphore acts like a lock, while a counting semaphore allows a set number of concurrent accesses. The producer-consumer and readers-writers problems are classic examples that illustrate the need for careful synchronisation.
解决方案包括信号量、互斥锁和管程等互斥机制。二元信号量类似于锁,而计数信号量允许指定数量的并发访问。生产者-消费者问题和读者-写者问题是说明需要仔细同步的经典示例。
Deadlock is another critical issue where a set of processes are blocked forever, each waiting for a resource held by another. Four necessary conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait. Prevention or avoidance strategies, such as Banker’s algorithm, are used to handle deadlocks.
死锁是另一个关键问题,即一组进程永远被阻塞,每个进程都在等待另一个进程持有的资源。死锁的四个必要条件为互斥、持有并等待、非抢占和循环等待。预防或避免策略,如银行家算法,用于处理死锁。
10. File Systems | 文件系统
A file system organises and stores files on storage devices. It provides a hierarchical directory structure, naming conventions, and access control. The OS provides file operations: create, open, read, write, seek, delete, and truncate. File attributes include name, type, size, protection, and timestamps.
文件系统在存储设备上组织并存储文件。它提供分层目录结构、命名规则和访问控制。OS提供文件操作:创建、打开、读、写、定位、删除和截断。文件属性包括名称、类型、大小、保护和时戳。
Common allocation methods are contiguous, linked, and indexed allocation. Contiguous allocation stores a file in consecutive blocks, allowing fast sequential access but causing external fragmentation. Indexed allocation uses an index block containing pointers to all data blocks, supporting both sequential and random access efficiently, as in UNIX’s inode structure.
常见的分配方法有连续分配、链接分配和索引分配。连续分配将文件存储在连续块中,允许快速顺序访问但会造成外部碎片。索引分配使用包含所有数据块指针的索引块,高效支持顺序和随机访问,例如UNIX的inode结构。
Block size is a critical parameter: smaller blocks reduce internal fragmentation but increase management overhead. Free space management uses approaches such as bitmaps or free lists to track available blocks. Directories are typically implemented as special files containing mappings.
块大小是关键参数:较小的块可减少内部碎片但增加管理开销。空闲空间管理使用位图或空闲列表等方法来跟踪可用块。目录通常实现为包含映射的特殊文件。
11. Security and Protection | 安全与保护
Protection mechanisms control access to resources by processes. The OS enforces access rights using models such as the access matrix, where rows represent domains (users or processes) and columns represent objects (files, devices). Each cell specifies the access rights (read, write, execute). Capability lists and access control lists (ACLs) are practical implementations.
保护机制控制进程对资源的访问。OS使用访问矩阵等模型强制执行访问权限,其中行表示域(用户或进程),列表示对象(文件、设备)。每个单元格指定访问权限(读、写、执行)。能力表和访问控制列表(ACL)是实际的实现方式。
Authentication verifies the identity of a user, typically through passwords, biometrics, or token-based systems. The OS stores password hashes rather than plaintext to enhance security. Modern systems employ salt and key derivation functions to resist brute-force and rainbow table attacks.
认证通过密码、生物识别或基于令牌的系统验证用户身份。OS存储密码哈希值而非明文以增强安全性。现代系统采用盐和密钥派生函数来抵抗暴力破解和彩虹表攻击。
Malware protection is also a concern; the OS may restrict execution of untrusted programs, enable memory protection (NX bits), and utilise address space layout randomisation (ASLR) to hinder exploitation of software vulnerabilities.
恶意软件防护也是关注点;OS可限制执行不可信程序、启用内存保护(NX位),并利用地址空间布局随机化(ASLR)来阻止软件漏洞利用。
12. Virtualisation | 虚拟化
Virtualisation allows multiple operating systems to run concurrently on a single physical machine. A hypervisor is a software layer that creates and manages virtual machines (VMs). Type 1 hypervisors run directly on hardware (bare-metal), such as VMware ESXi and Microsoft Hyper-V, providing high performance and isolation.
虚拟化允许多个操作系统在单台物理机上并发运行。虚拟机管理程序(hypervisor)是创建和管理虚拟机(VM)的软件层。类型1 hypervisor直接运行在硬件上(裸机),例如VMware ESXi和Microsoft Hyper-V,提供高性能和隔离性。
Type 2 hypervisors run on top of an existing OS, like VirtualBox or VMware Workstation. They are easier to set up but introduce additional overhead. Key benefits of virtualisation include server consolidation, improved resource utilisation, easier backup and migration, and the ability to test software in multiple environments.
类型2 hypervisor运行在现有OS之上,如VirtualBox或VMware Workstation。它们较易设置但会引入额外开销。虚拟化的主要优点包括服务器整合、提高资源利用率、易于备份和迁移,以及能在多种环境中测试软件。
Containerisation, such as Docker, provides a lightweight alternative by sharing the host OS kernel while isolating user spaces. Containers start faster and use less memory than full VMs, making them ideal for microservices and cloud deployment. Understanding the distinction between virtual machines and containers is increasingly important for modern computing.
容器化(如Docker)通过共享宿主机OS内核并隔离用户空间,提供轻量级替代方案。相比完整VM,容器启动更快、占用内存更少,因此非常适合微服务和云部署。理解虚拟机与容器之间的区别对现代计算日益重要。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply