Introduction to Operating Systems | 操作系统入门

📚 Introduction to Operating Systems | 操作系统入门

An operating system (OS) is the most important piece of system software in a computer. It manages hardware resources, provides a user interface, and acts as a platform for running application programs. Without an operating system, a computer would be a collection of electrical components with no way to coordinate tasks or interact with users. In A-Level programming, understanding the OS helps you write better software and grasp concepts such as concurrency, file handling, and memory allocation.

操作系统是计算机中最重要的系统软件。它管理硬件资源、提供用户界面,并充当运行应用程序的平台。没有操作系统,计算机就只是一堆电子元件的集合,无法协调任务或与用户交互。在 A-Level 编程学习中,理解操作系统有助于编写更优质的软件,并掌握并发、文件处理和内存分配等概念。


1. What is an Operating System? | 什么是操作系统?

An operating system is a set of programs that control the execution of application software and act as an interface between the user and the computer hardware. It hides the complexity of hardware components, such as the CPU, memory, and I/O devices, behind a consistent and user-friendly environment.

操作系统是一组程序,负责控制应用软件的执行,并充当用户与计算机硬件之间的接口。它将 CPU、内存和输入输出设备等硬件组件的复杂性隐藏在统一且用户友好的环境之后。

Examples of popular operating systems include Microsoft Windows, macOS, Linux distributions, and mobile OSs like Android and iOS. Each OS provides core functions but may implement them differently depending on the target device.

流行的操作系统示例包括 Microsoft Windows、macOS、Linux 发行版,以及 Android 和 iOS 等移动操作系统。每个操作系统都提供核心功能,但根据目标设备的不同,实现方式可能有所差异。


2. Key Functions of an Operating System | 操作系统的关键功能

Every operating system must perform several fundamental tasks: process management, memory management, file management, I/O management, and security handling. These functions ensure that the system runs efficiently, securely, and can support multiple applications simultaneously.

每个操作系统都必须执行几项基本任务:进程管理、内存管理、文件管理、输入输出管理和安全处理。这些功能确保系统高效、安全地运行,并能够同时支持多个应用程序。

In addition, a modern OS provides networking capabilities, power management, and a user interface, which may be graphical or command-line based. Together, these functions form the backbone of all computing devices.

此外,现代操作系统还提供网络功能、电源管理以及用户界面(可以是图形界面或命令行界面)。这些功能共同构成了所有计算设备的基础。


3. Process Management | 进程管理

A process is an instance of a program in execution. The OS is responsible for creating, scheduling, and terminating processes. It allocates CPU time to processes using scheduling algorithms, allowing the system to appear to run many tasks at once even on a single-core CPU.

进程是正在执行的程序实例。操作系统负责创建、调度和终止进程。它通过调度算法为进程分配 CPU 时间,使系统即使在单核 CPU 上也能看似同时运行许多任务。

Process management also involves inter-process communication (IPC) and synchronisation. The OS must prevent conflicts when processes share resources, using techniques such as semaphores and mutexes.

进程管理还涉及进程间通信和同步。操作系统必须使用信号量和互斥锁等机制,防止进程在共享资源时发生冲突。


4. Process Scheduling Algorithms | 进程调度算法

Scheduling algorithms determine the order in which processes access the CPU. Common strategies include First Come First Served (FCFS), Shortest Job First (SJF), Round Robin (RR), and Priority-based scheduling. Each has strengths and weaknesses in terms of throughput, waiting time, and fairness.

调度算法决定进程访问 CPU 的顺序。常见策略包括先来先服务、最短作业优先、轮转调度和基于优先级的调度。每种策略在吞吐量、等待时间和公平性方面都有优缺点。

  • FCFS is simple but can cause the convoy effect where short processes wait behind long ones.
  • FCFS 简单,但可能产生护送效应,即短进程在长进程之后等待。
  • Round Robin allocates a fixed time slice to each process in a cyclic order, improving response time in interactive systems.
  • 轮转调度按循环顺序为每个进程分配固定的时间片,从而改善交互式系统的响应时间。

5. Memory Management | 内存管理

The OS manages the main memory (RAM) by keeping track of which blocks are in use and which are free. It allocates memory to processes when they need it and deallocates it once they finish. Effective memory management prevents memory leaks and fragmentation.

操作系统通过跟踪哪些内存块正在使用、哪些是空闲的来管理主存。它在进程需要时为其分配内存,并在进程结束后回收。有效的内存管理可以防止内存泄漏和碎片化。

Techniques such as paging and segmentation are used to map logical addresses to physical addresses. Paging divides memory into fixed-size pages and physical memory into frames, simplifying allocation and reducing external fragmentation.

操作系统使用分页和分段等技术将逻辑地址映射到物理地址。分页将内存划分为固定大小的页面,物理内存划分为帧,从而简化分配并减少外部碎片。


6. Virtual Memory | 虚拟内存

Virtual memory is a memory management technique that allows a computer to compensate for a shortage of physical RAM by temporarily transferring data to disk storage. The OS moves inactive pages from RAM to a swap file or swap partition, providing the illusion of a larger main memory.

虚拟内存是一种内存管理技术,它通过将数据暂时转移到磁盘存储,来弥补物理 RAM 的不足。操作系统将不活动的页面从 RAM 移至交换文件或交换分区,从而营造出更大主存的假象。

This mechanism relies on the concept of demand paging, where pages are only loaded when needed. A page fault occurs when a program tries to access a page not currently in RAM, triggering the OS to retrieve it from disk.

该机制依赖于请求调页的概念,即仅在需要时才加载页面。当程序尝试访问当前不在 RAM 中的页面时,就会发生缺页错误,从而触发操作系统从磁盘中将其取出。


7. File Management | 文件管理

The operating system organises data into files and directories, providing a logical view of physical storage. It handles file creation, deletion, reading, and writing, and enforces access rights to protect data. Users interact with the file system through pathnames and commands.

操作系统将数据组织为文件和目录,为物理存储提供逻辑视图。它处理文件的创建、删除、读取和写入,并强制执行访问权限以保护数据。用户通过路径名和命令与文件系统交互。

Common file systems include NTFS for Windows, ext4 for Linux, and APFS for macOS. Each differs in how it stores metadata, handles journaling, and supports features like encryption and compression.

常见的文件系统包括 Windows 使用的 NTFS、Linux 使用的 ext4 以及 macOS 使用的 APFS。它们在存储元数据、处理日志以及支持加密和压缩等功能方面各不相同。


8. I/O Device Management | 输入输出设备管理

The OS controls all input and output devices through device drivers, which are specialised programs that enable communication between the OS and hardware. This abstraction allows applications to perform I/O without needing to understand the specific details of each device.

操作系统通过设备驱动程序控制所有输入输出设备,驱动程序是使操作系统与硬件之间得以通信的专用程序。这种抽象使得应用程序无需了解每个设备的具体细节即可执行 I/O 操作。

Interrupt-driven I/O transfers control to the OS when a device is ready, reducing CPU idle time. The OS manages buffers and queues to coordinate data flow between fast processors and slower peripherals.

中断驱动的 I/O 在设备就绪时将控制权转交给操作系统,从而减少 CPU 的空闲时间。操作系统通过管理缓冲区和队列来协调快速处理器与较慢外设之间的数据流。


9. Security and Protection | 安全与保护

The OS ensures system security by authenticating users, controlling access to resources, and logging activity. It uses permission mechanisms, such as read, write, and execute bits in Unix systems, to enforce who can access files and directories.

操作系统通过验证用户身份、控制对资源的访问以及记录活动来确保系统安全。它使用权限机制(例如 Unix 系统中的读、写和执行位)来强制性地规定谁可以访问文件和目录。

Protection also extends to process isolation, where one process is prevented from interfering with another. Modern operating systems implement user and kernel modes to restrict sensitive operations to trusted kernel code.

保护还扩展到进程隔离,防止一个进程干扰另一个进程。现代操作系统通过实现用户模式和内核模式,将敏感操作限制在受信任的内核代码中执行。


10. The Kernel | 内核

The kernel is the core component of the operating system, loaded into memory at boot time and remaining resident while the system runs. It manages all hardware interactions and resources, providing low-level services such as thread scheduling and interrupt handling.

内核是操作系统的核心组件,在引导时加载到内存中,并在系统运行期间一直驻留。它管理所有硬件交互和资源,提供线程调度和中断处理等底层服务。

Design approaches include monolithic kernels, where all services run in kernel space, and microkernels, which minimise the kernel to basic IPC and scheduling, moving other services to user space. Hybrid kernels combine elements of both.

设计方法包括宏内核(所有服务在内核空间中运行)和微内核(将内核最小化为基本 IPC 和调度,将其他服务移至用户空间)。混合内核则结合了二者的元素。


11. Types of Operating System | 操作系统的类型

Operating systems can be classified as batch, interactive, real-time, multi-user, multi-tasking, or distributed. Batch OSs execute jobs in groups without user interaction, while real-time OSs guarantee response within strict time constraints, critical for systems like air traffic control.

操作系统可分为批处理、交互式、实时、多用户、多任务或分布式等类型。批处理操作系统以批处理方式执行作业,无需用户交互;而实时操作系统则保证在严格的时间限制内做出响应,这对于空中交通管制等系统至关重要。

Embedded operating systems, such as those in IoT devices, are stripped-down and optimised for specific hardware with limited resources. Server operating systems prioritise stability and throughput over graphical interfaces.

嵌入式操作系统(如物联网设备中的操作系统)经过精简并针对资源有限的特定硬件进行了优化。服务器操作系统则优先考虑稳定性和吞吐量,而非图形界面。


12. User Interface | 用户界面

The OS provides a user interface (UI) through which humans interact with the machine. The two primary forms are the command-line interface (CLI) and the graphical user interface (GUI). CLI allows direct text-based commands, offering power and scripting capabilities, while GUI makes interaction intuitive with windows, icons, menus, and pointers.

操作系统提供用户界面,使人类能够与机器进行交互。两种主要形式是命令行界面和图形用户界面。CLI 允许直接输入基于文本的命令,提供强大的功能和脚本编写能力;GUI 则通过窗口、图标、菜单和指针使交互变得直观。

Modern operating systems often include a touch interface and voice control, accommodating diverse hardware from smartphones to desktops. The choice of interface depends on user needs and technical requirements.

现代操作系统通常还包括触控界面和语音控制,以适应从智能手机到台式机的各种硬件。界面的选择取决于用户需求和技术要求。

Published by TutorHao | Programming Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading