📚 Operating Systems: Processes, Scheduling and Memory Management | 操作系统:进程、调度与内存管理
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. For A-Level Edexcel Computer Science, understanding how an OS handles processes, scheduling, and memory is essential. This article explains these core concepts, blending theory with practical examples.
操作系统(OS)是管理计算机硬件和软件资源的系统软件,并为计算机程序提供通用服务。对于 A-Level Edexcel 计算机科学,理解操作系统如何处理进程、调度与内存至关重要。本文将剖析这些核心概念,结合理论与实例。
1. Introduction to Operating Systems | 操作系统简介
An operating system acts as an interface between the user and the hardware. It hides the complexity of hardware by providing a convenient environment for program execution. Modern OSes are multitasking and multi-user, enabling concurrent execution of multiple processes.
操作系统充当用户与硬件之间的接口。它通过提供便捷的程序执行环境来隐藏硬件的复杂性。现代操作系统支持多任务和多用户,允许多个进程并发执行。
2. Functions of an OS | 操作系统的功能
Key functions of an operating system include: process management, memory management, file system management, I/O management, security and protection, and networking. Each function is critical for the stability and efficiency of a computing system.
操作系统的关键功能包括:进程管理、内存管理、文件系统管理、输入输出管理、安全与保护以及网络功能。每一个功能对计算系统的稳定性和效率都至关重要。
3. Process Management | 进程管理
A process is a program in execution. The OS is responsible for creating, scheduling, and terminating processes. Each process has its own address space and execution context. The OS maintains a process control block (PCB) for each process, storing its state, program counter, registers, and memory limits.
进程是正在执行的程序。操作系统负责创建、调度和终止进程。每个进程拥有自己的地址空间和执行上下文。操作系统为每个进程维护一个进程控制块(PCB),存储其状态、程序计数器、寄存器和内存限制。
4. Process States | 进程状态
A process can be in one of several states: new, ready, running, waiting, or terminated. Transitions occur due to events such as I/O requests or timer interrupts. The state diagram below illustrates these transitions.
进程可处于以下几种状态之一:新建、就绪、运行、等待或终止。状态转换由 I/O 请求或定时器中断等事件触发。下面的状态图展示了这些转换。
| Process State | Description | 中文说明 |
|---|---|---|
| New | Process is being created. | 进程正在被创建。 |
| Ready | Process is waiting to be assigned to the CPU. | 进程等待分配 CPU。 |
| Running | Instructions are being executed. | 指令正在执行。 |
| Waiting | Process is waiting for some event to occur (e.g. I/O completion). | 进程等待某个事件发生(如 I/O 完成)。 |
| Terminated | Process has finished execution. | 进程执行完毕。 |
5. Scheduling Algorithms | 调度算法
The OS uses scheduling algorithms to decide which process runs next. The goal is to maximise CPU utilisation and provide fair access. Common algorithms include First Come First Served (FCFS), Shortest Job First (SJF), Round Robin (RR), and priority-based scheduling.
操作系统使用调度算法决定下一个运行的进程。目标是最大化 CPU 利用率并提供公平访问。常见算法包括先来先服务(FCFS)、最短作业优先(SJF)、轮转调度(RR)和基于优先级的调度。
In Round Robin, each process is given a fixed time quantum (e.g. 20 ms). After the quantum expires, the process is preempted and moved to the back of the ready queue. This is widely used in time-sharing systems.
在轮转调度中,每个进程获得一个固定的时间片(例如 20 毫秒)。时间片用完后,进程被抢占并移至就绪队列尾部。这广泛用于分时系统。
6. Memory Management | 内存管理
Memory management involves allocating and deallocating memory spaces to processes. The OS must protect each process’s memory from others and efficiently use limited physical RAM. Techniques include partitioning, paging, and segmentation.
内存管理涉及为进程分配和释放内存空间。操作系统必须保护各进程的内存免受其他进程影响,并高效利用有限的物理内存。技术包括分区、分页和分段。
7. Paging and Segmentation | 分页与分段
Paging divides physical memory into fixed-size blocks called frames, and logical memory into pages of the same size. A page table maps logical pages to physical frames, enabling non-contiguous allocation. This eliminates external fragmentation.
分页将物理内存划分为固定大小的块称为帧,将逻辑内存划分为同样大小的页。页表将逻辑页映射到物理帧,实现非连续分配,从而消除了外部碎片。
Segmentation divides memory into variable-sized segments based on logical units such as functions or data structures. A segment table stores base addresses and limits. Hybrid schemes like paged segmentation combine both approaches.
分段根据逻辑单元(如函数或数据结构)将内存划分为可变大小的段。段表存储基址和界限。分页式分段等混合方案结合了两种方法。
8. Virtual Memory | 虚拟内存
Virtual memory allows the execution of processes that are not entirely in physical memory. The OS moves pages or segments between RAM and secondary storage (disk) using demand paging. This creates an illusion of a larger, contiguous address space.
虚拟内存允许执行不完全在物理内存中的进程。操作系统通过请求调页在 RAM 和二级存储(磁盘)之间移动页面或分段,创造出更大、连续的地址空间假象。
When a page is not in memory, a page fault occurs. The OS loads the required page from disk, possibly replacing an existing page using a page replacement algorithm such as Least Recently Used (LRU).
当所需页面不在内存中时,会发生缺页中断。操作系统从磁盘加载所需页面,并可能使用页面置换算法(如最近最少使用 LRU)替换现有页面。
9. Interrupts and I/O | 中断与输入输出
Interrupts are signals to the processor indicating an event that needs immediate attention. Hardware interrupts (e.g. from I/O devices) and software interrupts (traps) cause the CPU to suspend the current task, execute an interrupt service routine (ISR), and resume.
中断是发送给处理器的信号,表示需要立即关注的事件。硬件中断(例如来自 I/O 设备)和软件中断(陷入)使 CPU 暂停当前任务,执行中断服务程序(ISR),然后恢复。
The OS manages I/O through device drivers and buffering. Direct Memory Access (DMA) allows devices to transfer data directly to/from memory without CPU involvement for large blocks, reducing overhead.
操作系统通过设备驱动和缓冲管理 I/O。直接内存访问(DMA)允许设备直接与内存传输数据,无需 CPU 参与大量数据的搬运,从而降低开销。
10. Concurrency and Deadlock | 并发与死锁
Concurrency arises when multiple processes execute simultaneously. The OS must synchronise access to shared resources to prevent race conditions. Mechanisms like semaphores, mutex locks, and monitors enforce mutual exclusion.
并发在多个进程同时执行时出现。操作系统必须同步对共享资源的访问以防止竞态条件。信号量、互斥锁和管程等机制强制实现互斥。
A deadlock is a situation where two or more processes are each waiting for resources held by the other, resulting in a standstill. Four necessary conditions for deadlock (Coffman’s conditions) are mutual exclusion, hold and wait, no preemption, and circular wait. Prevention or avoidance strategies (e.g. Banker’s algorithm) are used.
死锁是指两个或多个进程各自等待对方持有的资源,导致系统停滞。死锁的四个必要条件(科夫曼条件)是互斥、持有并等待、不可抢占和循环等待。采用预防或避免策略(如银行家算法)应对。
11. OS Security | 操作系统安全
OS security involves authentication, authorisation, and encryption to protect data and resources. User accounts, file permissions, and access control lists (ACLs) restrict unauthorised access. Modern OSes also include firewalls and sandboxing for applications.
操作系统安全涉及身份验证、授权和加密,以保护数据和资源。用户账户、文件权限和访问控制列表(ACL)限制未授权访问。现代操作系统还包含防火墙和应用程序沙箱。
12. Real-world OS Examples | 现实操作系统示例
Popular operating systems like Windows, Linux, and macOS implement these concepts in different ways. Linux uses a monolithic kernel with loadable modules, supports preemptive multitasking, and employs the Completely Fair Scheduler (CFS). Windows uses a hybrid kernel and several scheduling priority classes.
流行的操作系统,如 Windows、Linux 和 macOS,以不同方式实现了这些概念。Linux 使用具有可加载模块的单体内核,支持抢占式多任务,并采用完全公平调度器(CFS)。Windows 使用混合内核和多种调度优先级类。
Understanding the theoretical framework of operating systems equips students to analyse and evaluate performance, reliability, and security in a variety of computing environments.
理解操作系统的理论框架,使学生能够分析和评估各种计算环境中的性能、可靠性和安全性。
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