📚 Edexcel A-Level Computer Science: Operating Systems (OPS) | Edexcel A-Level 计算机科学:操作系统(OPS)
Operating systems are the backbone of every computing device, managing hardware resources and providing services for application programs. For Edexcel A-Level Computer Science, understanding the principles of operating systems, particularly process management, scheduling, and memory allocation, is essential. This article explores key concepts, from process states to virtual memory, ensuring you are well-prepared for the exam.
操作系统是每台计算设备的核心,管理硬件资源并为应用程序提供服务。对于 Edexcel A-Level 计算机科学,理解操作系统的基本原理,尤其是进程管理、调度和内存分配至关重要。本文深入探索从进程状态到虚拟内存的关键概念,助你从容应对考试。
1. What is an Operating System? | 什么是操作系统?
An operating system (OS) is system software that acts as an intermediary between the user and the computer hardware. It provides an environment in which a user can execute programs conveniently and efficiently. The OS manages the processor, memory, storage, and input/output devices, ensuring that multiple programs can run without interfering with each other.
操作系统(OS)是一种系统软件,充当用户与计算机硬件之间的中介。它提供一个环境,使用户能够方便高效地执行程序。操作系统管理处理器、内存、存储器和输入输出设备,确保多个程序运行时互不干扰。
Common examples include Microsoft Windows, macOS, Linux, and real-time operating systems (RTOS) used in embedded devices.
常见例子包括 Microsoft Windows、macOS、Linux 以及用于嵌入式设备的实时操作系统(RTOS)。
2. The Roles and Functions of an OS | 操作系统的角色与功能
The primary functions of an operating system include process management, memory management, file system management, device management, security and access control, and providing a user interface. It abstracts the underlying hardware complexities, making it possible for application software to run on different machines without modification.
操作系统的主要功能包括进程管理、内存管理、文件系统管理、设备管理、安全与访问控制,以及提供用户界面。它抽象了底层硬件的复杂性,使应用软件无需修改即可在不同机器上运行。
In process management, the OS handles the creation, scheduling, and termination of processes. Memory management ensures each process receives sufficient memory and prevents one from accessing another’s address space.
在进程管理中,操作系统负责进程的创建、调度和终止。内存管理确保每个进程获得足够的内存,并防止一个进程访问另一个进程的地址空间。
3. Processes and Process States | 进程与进程状态
A process is an instance of a program in execution. Unlike a static program stored on disk, a process has its own memory space, registers, and resources. The OS maintains a process table containing information about all active processes.
进程是正在执行的程序实例。与存储在磁盘上的静态程序不同,进程拥有自己的内存空间、寄存器和资源。操作系统维护着一个进程表,其中包含所有活动进程的信息。
Processes transition through several states: New (being created), Ready (waiting for CPU), Running (using CPU), Blocked/Waiting (waiting for I/O or event), and Terminated (finished execution). The state diagram is a cornerstone of A-Level exams.
进程会经历多个状态:新建(正在创建)、就绪(等待 CPU)、运行(正在使用 CPU)、阻塞/等待(等待 I/O 或事件)和终止(执行完毕)。状态图是 A-Level 考试的核心内容。
New → Ready ↔ Running → Terminated
新建 → 就绪 ↔ 运行 → 终止
When a process is waiting for an I/O operation, it moves from Running to Blocked. Once the I/O completes, it returns to the Ready queue.
当进程等待 I/O 操作时,它从运行状态转为阻塞状态。完成 I/O 后,它又回到就绪队列。
4. The Process Control Block (PCB) | 进程控制块
The Process Control Block (PCB) is a data structure in the OS kernel that contains all the information needed to manage a particular process. Each PCB stores the process ID (PID), program counter, CPU registers, memory limits, list of open files, and the process state.
进程控制块(PCB)是操作系统内核中的数据结构,包含管理特定进程所需的所有信息。每个 PCB 存储进程标识符(PID)、程序计数器、CPU 寄存器、内存限制、打开文件列表以及进程状态。
During a context switch, the OS saves the current process’s PCB and loads the next process’s PCB, allowing smooth multitasking. Understanding the PCB helps clarify how the OS isolates processes and recovers from interrupts.
在上下文切换期间,操作系统保存当前进程的 PCB 并加载下一个进程的 PCB,从而实现顺畅的多任务处理。理解 PCB 有助于弄清操作系统如何隔离进程并从中断中恢复。
5. Scheduling: Long, Medium, Short Term | 调度:长程、中程、短程
Operating systems employ three levels of scheduling. Long-term scheduler (job scheduler) selects which jobs are admitted into the system from the spool queue to become processes. It controls the degree of multiprogramming. Medium-term scheduler swaps processes out of main memory to reduce contention and later swaps them back in (swapping).
操作系统采用三级调度。长程调度器(作业调度器)从后台池中选择哪些作业进入系统成为进程,它控制着多道程序的并发度。中程调度器将进程从主存中换出以降低争用,稍后再将它们换入(交换技术)。
Short-term scheduler (CPU scheduler) decides which ready process gets the CPU next. It executes frequently, selecting processes based on a scheduling algorithm. In many modern systems, the medium-term scheduler handles swapping, while the short-term scheduler handles CPU allocation.
短程调度器(CPU 调度器)决定下一个获得 CPU 的就绪进程。它执行频繁,基于调度算法选择进程。在许多现代系统中,中程调度器处理交换,短程调度器负责 CPU 分配。
6. Scheduling Algorithms | 调度算法
Several CPU scheduling algorithms are examined at A-Level: First-Come, First-Served (FCFS) simply executes processes in arrival order. Shortest Job First (SJF) picks the process with the smallest next CPU burst, potentially non-preemptive or preemptive (Shortest Remaining Time First). Priority scheduling assigns a priority number, and Round Robin (RR) gives each process a time quantum.
A-Level 考试涉及多种 CPU 调度算法:先到先服务(FCFS)按到达顺序执行;最短作业优先(SJF)选择下次 CPU 突发最短的进程,可以是非抢占式或抢占式(最短剩余时间优先);优先级调度分配优先级号;轮转调度(RR)给每个进程分配时间片。
| Algorithm | Type | Starvation? |
|---|---|---|
| FCFS | Non-preemptive | No |
| SJF | Non-preemptive | Yes (long jobs) |
| Round Robin | Preemptive | No |
| Priority | Preemptive/Non | Yes (low priority) |
Calculating average waiting time and turnaround time is a common exam requirement. For example, given processes P1, P2, P3 with burst times 5, 3, 8 and arrival times 0, 1, 2, you may need to compute metrics using FCFS or RR with time quantum 4.
计算平均等待时间和周转时间是考试常见要求。例如给定进程 P1、P2、P3 的突发时间分别为 5、3、8,到达时间为 0、1、2,你可能需要用 FCFS 或时间片为 4 的轮转算法计算指标。
7. Interrupts and Context Switching | 中断与上下文切换
Interrupts are signals sent to the CPU indicating an event that needs immediate attention, such as I/O completion, hardware errors, or timer interrupts (quantum expiry). When an interrupt occurs, the CPU finishes the current instruction, then saves the program counter and registers onto the stack or PCB, and jumps to the interrupt service routine (ISR).
中断是发送给 CPU 的信号,指示需要立即处理的事件,如 I/O 完成、硬件错误或定时器中断(时间片到期)。发生中断时,CPU 完成当前指令,然后将程序计数器和寄存器保存到栈或 PCB 中,并跳转到中断服务例程(ISR)。
Context switching is the mechanism of switching the CPU from one process to another. It involves saving the state of the old process and loading the saved state of the new process. Context switching is pure overhead; the CPU does no useful work while switching. The frequency must be balanced against responsiveness.
上下文切换是将 CPU 从一个进程切换到另一个进程的机制。它涉及保存旧进程的状态并加载新进程的已保存状态。上下文切换纯属开销,切换期间 CPU 不做有用功。需在切换频率与响应性之间取得平衡。
8. Memory Management: Paging and Segmentation | 内存管理:分页与分段
Memory management ensures efficient use of RAM and isolation between processes. Two classic techniques are paging and segmentation. Paging divides physical memory into fixed-sized blocks called frames, and logical memory into pages of the same size. The page table maps virtual pages to physical frames, supporting discontinuous allocation.
内存管理确保高效使用 RAM 并隔离进程。两种经典技术是分页和分段。分页将物理内存划分为大小固定的块(称为帧),逻辑内存划分为相同大小的页。页表将虚拟页映射到物理帧,支持非连续分配。
Segmentation divides memory into variable-sized segments based on logical divisions (code, data, stack). Each segment has a base and limit. Segments can be shared and protected. Both techniques can be combined in segment-page schemes.
分段根据逻辑划分(代码、数据、栈)将内存划分为大小可变的段。每个段都有基址和界限。段可以共享和保护。两种技术可组合为段页式方案。
Internal and external fragmentation are key disadvantages. Paging suffers internal fragmentation (unused space within a page), while segmentation suffers external fragmentation (free memory broken into small chunks). These are frequently assessed.
内部碎片和外部碎片是主要缺点。分页有内部碎片(页内未用空间),分段有外部碎片(空闲内存被分成小块)。这些经常被考核。
9. Virtual Memory | 虚拟内存
Virtual memory allows execution of processes that are not completely in physical memory. The OS keeps only the necessary parts of a process in RAM, while the rest remains on disk. When a required page is not in memory (page fault), the OS loads it from disk, possibly replacing an existing page using page replacement algorithms like LRU or FIFO.
虚拟内存允许执行不完全在物理内存中的进程。操作系统仅将进程的必要部分保留在 RAM 中,其余部分留在磁盘上。当所需页面不在内存中(缺页异常)时,操作系统从磁盘加载它,并可能使用页面置换算法(如 LRU 或 FIFO)替换现有页。
Thrashing occurs when the system spends more time swapping pages than executing processes, due to insufficient frames. The working set model and page fault frequency are methods to control thrashing.
当系统花费在交换页面上的时间多于执行进程时,就会发生抖动,原因是帧不足。工作集模型和缺页频率是控制抖动的方法。
Virtual memory uses demand paging, where pages are loaded only when needed. This allows large programs to run on systems with limited physical memory, an essential concept for A-Level operating systems.
虚拟内存使用按需调页,即仅在需要时加载页面。这使得大型程序可在物理内存有限的系统上运行,是 A-Level 操作系统的重要概念。
10. Concurrency and Deadlock | 并发与死锁
Concurrency arises when multiple processes execute simultaneously. Without proper synchronization, race conditions can occur where shared data becomes inconsistent. Mutexes, semaphores, and monitors are synchronization mechanisms used to enforce mutual exclusion.
多个进程同时执行时产生并发。如果没有适当的同步,可能出现竞争条件,导致共享数据不一致。互斥锁、信号量和管程是用于实现互斥的同步机制。
Deadlock is a state where a set of processes are each waiting for resources held by another member of the set. Four necessary conditions (Coffman conditions) must hold: mutual exclusion, hold and wait, no preemption, and circular wait. Breaking any one of these can prevent or resolve deadlock.
死锁是一组进程中的每一个都在等待该组中另一个成员持有的资源的状态。必须同时满足四个必要条件(科夫曼条件):互斥、持有并等待、非抢占和循环等待。破坏其中任何一个条件都可以预防或解决死锁。
The resource allocation graph and banker’s algorithm are ways to handle deadlock, though for Edexcel A-Level conceptual understanding of conditions and prevention strategies is typically sufficient.
资源分配图和银行家算法是处理死锁的方法,不过对于 Edexcel A-Level,概念性地理解死锁条件及预防策略通常就足够了。
11. File Management and I/O | 文件管理与输入输出
The OS provides a file system to store, retrieve, and manage data on disks. Files are organized in a directory hierarchy, with access control lists (ACLs) to manage permissions. File allocation methods include contiguous, linked, and indexed allocation (e.g., inode in Unix).
操作系统提供文件系统,用于在磁盘上存储、检索和管理数据。文件按目录层次结构组织,访问控制列表(ACL)用于管理权限。文件分配方法包括连续分配、链接分配和索引分配(如 Unix 中的 inode)。
I/O management involves device drivers that translate generic OS requests into hardware-specific commands. Buffering, caching, and spooling improve performance. Direct Memory Access (DMA) allows devices to transfer data directly to memory, bypassing the CPU.
I/O 管理涉及设备驱动程序,将通用操作系统请求转换为硬件特定命令。缓冲、缓存和假脱机可提高性能。直接内存访问(DMA)允许设备直接将数据传送到内存,绕过 CPU。
12. User Interfaces and System Calls | 用户接口与系统调用
The user interface (UI) is the layer through which users interact with the OS. It can be a command-line interface (CLI) or a graphical user interface (GUI). A CLI requires typed commands, while a GUI provides windows, icons, menus, and pointers (WIMP).
用户界面(UI)是用户与操作系统交互的层。它可以是命令行界面(CLI)或图形用户界面(GUI)。CLI 需要输入命令,而 GUI 提供窗口、图标、菜单和指针(WIMP)。
System calls provide the programming interface to the services of the OS. When a program needs to open a file, create a process, or allocate memory, it makes a system call that switches the CPU to kernel mode to execute privileged instructions. The API (e.g., POSIX) hides the details of system calls.
系统调用提供了操作系统服务的编程接口。当程序需要打开文件、创建进程或分配内存时,它会发起系统调用,将 CPU 切换到内核模式以执行特权指令。API(如 POSIX)隐藏了系统调用的细节。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导