📚 Operating Systems: Concepts and Management | 操作系统:概念与管理
An operating system (OS) is the most fundamental software that runs on a computer. It acts as an intermediary between the user and the hardware, managing all resources and providing a stable, consistent environment for applications to execute. Without an operating system, a computer is just a collection of electronic components with no ability to coordinate tasks, handle input/output, or run multiple programs. This article covers the core concepts required for A-Level Edexcel Computer Science, including process management, scheduling, memory management, interrupts, and system security.
操作系统(OS)是计算机上运行的最基础软件。它充当用户与硬件之间的中介,管理所有资源并为应用程序的执行提供稳定、一致的环境。没有操作系统,计算机只是一堆电子元件的集合,无法协调任务、处理输入 / 输出或运行多个程序。本文涵盖 A-Level Edexcel 计算机科学所需的核心概念,包括进程管理、调度、内存管理、中断和系统安全。
1. What is an Operating System? | 什么是操作系统?
An operating system is system software that provides an interface between the user, application software, and the computer hardware. It hides the complexity of the hardware and offers services such as file management, memory allocation, and task scheduling. Common examples include Windows, macOS, Linux, and Android. The OS is loaded into memory when the computer boots up and remains resident, constantly managing resources and responding to events.
操作系统是一种系统软件,它提供用户、应用软件和计算机硬件之间的接口。它隐藏了硬件的复杂性,并提供文件管理、内存分配和任务调度等服务。常见的例子包括 Windows、macOS、Linux 和 Android。操作系统在计算机启动时加载到内存中并常驻,持续管理资源并响应事件。
The OS kernel is the core component that handles the most critical operations, such as process scheduling and memory management. Other parts, like the user interface (shell), allow users to interact with the kernel through commands or graphical elements. System programs and libraries provide further functionality for developers and end-users.
操作系统内核是处理最关键操作(如进程调度和内存管理)的核心组件。其他部分,如用户界面(shell),允许用户通过命令或图形元素与内核交互。系统程序和库为开发人员和最终用户提供了更多功能。
2. Functions of an Operating System | 操作系统的功能
The main functions of an operating system can be categorised into resource management, process management, memory management, file management, I/O management, security, and user interface provision. Resource management involves allocating CPU time, memory space, and I/O devices efficiently among competing processes. The OS must also provide mechanisms for synchronisation and communication between processes.
操作系统的主要功能可分为资源管理、进程管理、内存管理、文件管理、I/O 管理、安全和用户界面提供。资源管理涉及在竞争进程之间高效分配 CPU 时间、内存空间和 I/O 设备。操作系统还必须提供进程间同步与通信的机制。
Memory management ensures each process has adequate memory and is protected from interference by other processes. File management organises data into files and directories on storage devices, handling read/write operations and access permissions. I/O management standardises communication with peripheral devices through device drivers, hiding hardware specifics from applications.
内存管理确保每个进程拥有足够的内存并免受其他进程的干扰。文件管理将数据组织成存储设备上的文件和目录,处理读写操作和访问权限。I/O 管理通过设备驱动程序标准化与外设的通信,对应用程序隐藏硬件细节。
3. Types of Operating Systems | 操作系统的类型
Operating systems can be classified based on their capabilities and usage scenarios. A single-user, single-task OS allows only one user to run one program at a time, such as early MS-DOS. A single-user, multi-tasking OS is what most modern personal computers use, enabling one user to run several applications concurrently. Multi-user operating systems, like UNIX servers, allow multiple users to access the system simultaneously through terminals or network connections.
操作系统可以根据其功能和用途分类。单用户单任务操作系统只允许一个用户一次运行一个程序,例如早期的 MS-DOS。单用户多任务操作系统是现代个人电脑最常使用的类型,允许一个用户同时运行多个应用程序。多用户操作系统(如 UNIX 服务器)允许多个用户通过终端或网络连接同时访问系统。
Real-time operating systems (RTOS) are designed for applications that require strict timing guarantees, such as embedded systems in vehicles, medical devices, or industrial robots. Distributed operating systems manage a group of independent computers as a single coherent system, often used in cloud computing or cluster computing. Mobile operating systems, optimised for smartphones and tablets, focus on touch interfaces, power efficiency, and connectivity.
实时操作系统(RTOS)专为需要严格时间保证的应用而设计,如汽车嵌入式系统、医疗设备或工业机器人。分布式操作系统将一组独立的计算机作为一个统一的系统管理,常用于云计算或集群计算。移动操作系统针对智能手机和平板电脑优化,侧重于触摸界面、功耗和连接性。
4. Process Management | 进程管理
A process is a program in execution, consisting of the program code, current activity, stack, heap, and allocated resources. The OS is responsible for creating, scheduling, and terminating processes. Each process has a unique process identifier (PID) and a process control block (PCB) that stores its state, program counter, register contents, and memory limits. Modern operating systems support multiprogramming and multitasking by rapidly switching the CPU between processes.
进程是执行中的程序,包含程序代码、当前活动、栈、堆和已分配的资源。操作系统负责创建、调度和终止进程。每个进程有一个唯一的进程标识符(PID)和一个进程控制块(PCB),其中存储其状态、程序计数器、寄存器内容和内存限制。现代操作系统通过快速在进程间切换 CPU 来支持多道程序设计和多任务处理。
Process management also involves inter-process communication (IPC) and process synchronisation. IPC mechanisms, such as pipes, message queues, and shared memory, allow processes to exchange data. Synchronisation ensures that concurrent processes do not interfere when accessing shared resources, often using semaphores or mutex locks to prevent race conditions.
进程管理还涉及进程间通信(IPC)和进程同步。IPC 机制(如管道、消息队列和共享内存)允许进程交换数据。同步确保并发进程在访问共享资源时不会相互干扰,通常使用信号量或互斥锁来防止竞争条件。
5. Process States and Transitions | 进程状态和转换
During its lifetime, a process transitions through several states: new, ready, running, waiting (blocked), and terminated. When a process is created, it enters the new state. Once admitted by the long-term scheduler, it moves to the ready state, where it waits for CPU allocation. The short-term scheduler (CPU scheduler) selects a ready process and dispatches it to the running state.
进程在其生命周期中经历多个状态:新建、就绪、运行、等待(阻塞)和终止。进程创建时进入新建状态。一旦被长期调度器接纳,它进入就绪状态,等待 CPU 分配。短期调度器(CPU 调度器)选择一个就绪进程并将其分派到运行状态。
A running process may be preempted and returned to the ready state if its time slice expires, or it may voluntarily enter the waiting state when it requests an I/O operation or an event. Once the event occurs, it moves back to the ready state. Finally, when the process completes or is terminated by the OS, it enters the terminated state and its resources are released. The following state diagram illustrates these transitions:
运行中的进程如果时间片用完,可能会被抢占并返回就绪状态;或者当它请求 I/O 操作或事件时,自愿进入等待状态。一旦事件发生,它回到就绪状态。最后,当进程完成或被操作系统终止时,它进入终止状态,资源被释放。下面的状态图展示了这些转换:
New → Ready ⇌ Running → Waiting → Ready; Running → Terminated
6. Scheduling Algorithms | 调度算法
CPU scheduling decides which process in the ready queue gets the CPU next. Scheduling algorithms can be preemptive (the OS can forcibly take the CPU away) or non-preemptive (a process keeps the CPU until it voluntarily releases it). The goals include maximising CPU utilisation, minimising turnaround time, and providing fairness. Common algorithms include First-Come, First-Served (FCFS), Shortest Job Next (SJN), Round Robin (RR), and Priority Scheduling.
CPU 调度决定就绪队列中哪个进程下一个获得 CPU。调度算法可以是抢占式(操作系统可以强制取走 CPU)或非抢占式(进程保留 CPU 直到自愿释放)。目标包括最大化 CPU 利用率、最小化周转时间并提供公平性。常见算法有先来先服务(FCFS)、最短作业优先(SJN)、轮转(RR)和优先级调度。
Round Robin gives each process a fixed time quantum; if a process does not finish within that time, it is placed at the end of the ready queue and the next process runs. This is suitable for interactive systems. Priority Scheduling assigns a priority to each process; the CPU is given to the highest-priority ready process. To prevent starvation, aging can be used to gradually increase the priority of waiting processes. A comparison of features is given below:
轮转调度给每个进程一个固定的时间片;如果进程在该时间内未完成,则将其放到就绪队列末尾,运行下一个进程。这适合交互式系统。优先级调度为每个进程分配优先级;CPU 分配给优先级最高的就绪进程。为防止饥饿现象,可以使用老化技术逐步增加等待进程的优先级。下面给出特性的比较:
| Algorithm | Preemptive | Starvation Possible |
|---|---|---|
| FCFS | No | No |
| SJN | Both possible | Yes |
| Round Robin | Yes | No |
| Priority | Yes | Yes (without aging) |
7. Memory Management | 内存管理
Memory management is the process of controlling and coordinating computer memory, assigning blocks to various running programs to optimise overall system performance. The OS must keep track of which parts of memory are in use and which are free, allocate memory to processes when requested, and deallocate it when they terminate. Protection mechanisms prevent one process from accessing the memory space of another without permission, ensuring system stability.
内存管理是控制和协调计算机内存的过程,将内存块分配给各个运行的程序以优化系统整体性能。操作系统必须跟踪哪些内存正在使用、哪些空闲,在请求时为进程分配内存,并在它们终止时回收。保护机制防止一个进程未经许可访问另一个进程的内存空间,确保系统稳定性。
Two basic approaches are contiguous allocation (where each process occupies a single block of consecutive memory addresses) and non-contiguous allocation (where a process can be scattered across different locations). Contiguous allocation leads to external fragmentation – free memory is broken into small pieces that are not large enough for new processes. Compaction can solve this but is expensive. Non-contiguous allocation avoids this through paging or segmentation.
两种基本方法是连续分配(每个进程占据一块连续的内存地址)和非连续分配(进程可以分散在不同位置)。连续分配会导致外部碎片 —— 空闲内存被分割成小块,无法满足新进程的需求。紧凑技术可以解决这个问题,但代价高昂。非连续分配通过分页或分段避免了碎片问题。
8. Virtual Memory and Paging | 虚拟内存与分页
Virtual memory is a technique that allows the execution of processes that are not completely in physical memory. It separates logical memory from physical memory, enabling a program to use more memory than is physically available by using disk space as an extension of RAM. This is implemented via demand paging, where pages are loaded into memory only when they are needed (page fault occurs).
虚拟内存是一种允许执行不完全在物理内存中的进程的技术。它将逻辑内存与物理内存分离,通过将磁盘空间作为 RAM 的扩展,使程序能够使用比物理内存更多的内存。这通过按需分页实现,即只有当页面被需要时才加载到内存中(发生缺页错误)。
Paging divides physical memory into fixed-sized blocks called frames, and logical memory into blocks of the same size called pages. The page table maps each page to a frame. When a page fault occurs, the OS selects a frame to replace using a page replacement algorithm, such as FIFO or Least Recently Used (LRU). The performance of virtual memory depends on the page fault rate; too many faults cause thrashing, where the system spends more time swapping than executing processes.
分页将物理内存划分为固定大小的块,称为帧;将逻辑内存划分为相同大小的块,称为页面。页表将每个页面映射到一个帧。当发生缺页错误时,操作系统使用页面置换算法选择一个要替换的帧,例如先进先出(FIFO)或最近最少使用(LRU)。虚拟内存的性能取决于缺页率;过多的缺页会导致系统抖动,即系统花费在交换上的时间多于执行进程的时间。
Effective Access Time = (1 − p) × memory access time + p × page fault time
有效访问时间 = (1 − p) × 内存访问时间 + p × 缺页处理时间
9. Interrupts and Interrupt Handling | 中断与中断处理
An interrupt is a signal sent to the processor that causes it to temporarily stop its current execution and transfer control to a special piece of code called an interrupt service routine (ISR). Interrupts can be generated by hardware (keyboard, disk, timer) or by software (system calls, exceptions). They allow the OS to respond promptly to events and provide the illusion of concurrency on a single CPU.
中断是发送给处理器的信号,使其暂时停止当前执行并将控制权转移给称为中断服务例程(ISR)的特殊代码。中断可以由硬件(键盘、磁盘、定时器)或软件(系统调用、异常)产生。它们使得操作系统能够快速响应事件,并在单个 CPU 上提供并发的假象。
When an interrupt occurs, the processor saves the current state (program counter, registers) onto the stack, then determines the type of interrupt via an interrupt vector table, which contains addresses of ISRs. After the ISR completes execution, the processor restores the saved state and resumes the interrupted process. Interrupts have priorities; a high-priority interrupt can preempt a lower-priority ISR. Proper handling ensures smooth I/O operations, multitasking, and system reliability.
当中断发生时,处理器将当前状态(程序计数器、寄存器)保存到栈中,然后通过中断向量表(其中包含 ISR 的地址)确定中断类型。ISR 执行完成后,处理器恢复保存的状态并恢复被中断的进程。中断具有优先级;高优先级中断可以抢占低优先级的 ISR。正确处理可确保 I/O 操作顺畅、多任务处理和系统可靠性。
10. Input/Output Management | 输入/输出管理
I/O management provides a uniform interface for applications to interact with a wide range of peripheral devices. Device drivers are OS modules that handle the specifics of each device, translating generic I/O requests into device-specific commands. This abstraction allows programmers to write code that sends data to a file without worrying about whether the destination is a hard disk, SSD, or network location.
I/O 管理为应用程序与各种外设交互提供了统一接口。设备驱动程序是处理每个设备细节的操作系统模块,将通用的 I/O 请求转换为设备特有的命令。这种抽象允许程序员编写代码将数据发送到文件,而无需担心目标是硬盘、SSD 还是网络位置。
I/O can be performed using programmed I/O (CPU polls the device status), interrupt-driven I/O (device interrupts CPU when ready), or direct memory access (DMA) where a controller transfers data directly between device and memory without CPU intervention. DMA is efficient for large data transfers. The OS also manages buffering, caching, and spooling to balance speed differences between CPU and devices. Spooling is used particularly for printers, where print jobs are queued on disk.
I/O 可以通过程序控制 I/O(CPU 轮询设备状态)、中断驱动 I/O(设备就绪时向 CPU 发中断)或直接存储器访问(DMA)执行,其中控制器直接在设备和内存之间传输数据,无需 CPU 干预。DMA 对于大数据传输很有效。操作系统还管理缓冲、缓存和假脱机,以平衡 CPU 与设备之间的速度差异。假脱机特别用于打印机,将打印作业在磁盘上排队。
11. Security and User Management | 安全与用户管理
Operating systems provide security mechanisms to protect system resources from unauthorised access and malicious damage. User authentication (login passwords, biometrics) ensures that only legitimate users can access the system. Access control lists (ACLs) and permissions (read, write, execute) are assigned to files and directories to control what users and processes can do. The OS also isolates processes, preventing direct access to each other’s memory spaces.
操作系统提供安全机制,以保护系统资源免受未经授权的访问和恶意破坏。用户身份验证(登录密码、生物识别)确保只有合法用户才能访问系统。访问控制列表(ACL)和权限(读、写、执行)分配给文件和目录,以控制用户和进程可以执行的操作。操作系统还隔离进程,防止直接访问彼此的内存空间。
In multi-user systems, the OS manages user accounts and groups, enforcing privileges. Encryption can be used to protect data at rest and in transit. Audit logs record security-relevant events for later analysis. Modern OS also implement firewalls and secure update mechanisms to defend against network-based attacks. User management also involves resource quotas, limiting the amount of disk space or CPU time a user can consume.
在多用户系统中,操作系统管理用户账户和组,强制执行权限。加密可用于保护静态和传输中的数据。审计日志记录与安全相关的事件以供后续分析。现代操作系统还实现防火墙和安全更新机制以防御基于网络的攻击。用户管理还包括资源配额,限制用户可以使用的磁盘空间或 CPU 时间。
12. The Kernel and System Calls | 内核与系统调用
The kernel is the heart of the operating system, running in a privileged mode (kernel mode) with full access to hardware. Applications run in user mode, restricted from executing dangerous instructions. To request services such as file operations, process creation, or network communication, user programs must make system calls. A system call is an interface that transitions the processor from user mode to kernel mode using a software interrupt or trap.
内核是操作系统的核心,以特权模式(内核态)运行,可完全访问硬件。应用程序在用户模式下运行,限制执行危险指令。为了请求文件操作、进程创建或网络通信等服务,用户程序必须进行系统调用。系统调用是一种接口,通过软件中断或陷阱使处理器从用户模式切换到内核模式。
Common categories of system calls include process control (fork, exit), file management (open, read, write), device management, information maintenance, and communication. When a system call is executed, the OS validates parameters, accesses hardware on behalf of the process, and returns results. The separation of kernel mode and user mode is fundamental to operating system stability and security, forming a protection boundary.
常见的系统调用类别包括进程控制(fork、exit)、文件管理(open、read、write)、设备管理、信息维护和通信。执行系统调用时,操作系统验证参数,代表进程访问硬件并返回结果。内核态与用户态的分离是操作系统稳定性和安全性的基础,形成了保护边界。
Published by TutorHao | Computing Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply