📚 Operating Systems and Programming: From Source Code to Running Process | 操作系统与编程:从源代码到运行进程
In A-Level programming, it is tempting to focus only on the code you write. However, every instruction depends on the operating system to load, schedule, protect and terminate it correctly. This article links the programming content you see in Edexcel specifications with the operating system concepts that make execution possible.
在 A-Level 编程学习中,很多同学只关注自己写的代码。但实际上,每条指令都依赖操作系统正确地加载、调度、保护和终止运行。本文把 Edexcel 考纲中的编程内容与支撑程序执行的操作系统概念联系起来。
1. The Role of an Operating System | 操作系统的角色
An operating system (OS) is a layer of software that manages hardware resources and provides services to application programs. It hides the complexity of hardware behind a virtual machine interface, allowing programmers to use high-level operations such as opening files or creating threads.
操作系统是管理硬件资源、为应用程序提供服务的软件层。它把硬件复杂性隐藏在虚拟机接口后面,让程序员可以使用打开文件、创建线程等高级操作。
Key OS functions include process management, memory management, file management, device handling, and security. In Edexcel questions, you may be asked to explain how the OS allocates CPU time to a program or how it prevents one process from corrupting another.
操作系统的关键功能包括进程管理、内存管理、文件管理、设备处理和安全保护。在 Edexcel 考题中,可能会要求解释操作系统如何给程序分配 CPU 时间,或如何阻止一个进程破坏另一个进程。
- Resource abstraction
- CPU scheduling
- Memory protection
- File and I/O management
- User interface
资源抽象、CPU 调度、内存保护、文件与输入输出管理、用户界面。
2. Programming Languages and Translation | 编程语言与翻译
Programs are written in high-level languages such as Python, Java or C#. These languages are closer to human logic but cannot be executed directly by the CPU. The OS and language toolchain must translate source code into machine code or an intermediate form.
程序用 Python、Java 或 C# 等高级语言编写。这些语言更接近人的逻辑,但 CPU 无法直接执行。操作系统和语言工具链必须把源代码翻译成机器码或中间形式。
A translator can be a compiler, interpreter or assembler. The choice affects how the program is loaded and executed by the OS. For example, a compiled C program becomes a native executable, while Python code often runs inside an interpreter process.
翻译器可以是编译器、解释器或汇编器。选择会影响操作系统如何加载和执行程序。例如,编译后的 C 程序变成原生可执行文件,而 Python 代码通常在解释器进程内运行。
Understanding the translation process helps you explain why a program may fail at build time, load time or run time. Edexcel topic questions frequently link translators with error reporting and platform independence.
理解翻译过程有助于解释程序为何在构建时、加载时或运行时失败。Edexcel 主题题经常把翻译器与错误报告和平台独立性结合起来考查。
3. Compilers, Interpreters and IDEs | 编译器、解释器与集成开发环境
A compiler translates the whole source file into machine code before execution. An interpreter translates and executes line by line. An integrated development environment (IDE) combines editing, debugging, building and version control to speed up programming.
编译器在执行前把整个源文件翻译成机器码;解释器逐行翻译并执行。集成开发环境(IDE)把编辑、调试、构建和版本控制组合在一起,提高编程效率。
| Translator | When translation occurs | Execution speed | Examples |
|---|---|---|---|
| Compiler | Before execution | Fast | C++, Go |
| Interpreter | During execution | Slower | Python, Ruby |
| Assembler | Before execution | Fast | Assembly language |
翻译器类型:编译型、解释型、汇编型;分别对应编译时间、执行速度与常见语言。
Edexcel exams often ask for advantages and disadvantages of compilers and interpreters. A key point is that interpreted code is easier to debug but runs more slowly, while compiled code has better performance but requires a separate compilation step.
Edexcel 考试常问编译器和解释器的优缺点。关键点是解释执行容易调试但运行较慢,编译执行性能更好但需要单独的编译步骤。
An IDE typically includes a source editor, build automation tools, a debugger and version control integration. These features reduce context switching and help students follow the programming cycle more efficiently.
IDE 通常包含源代码编辑器、构建自动化工具、调试器和版本控制集成。这些功能减少了上下文切换,帮助学生更高效地遵循编程循环。
4. Linking and Loading Executables | 链接与加载可执行文件
After compilation, object files contain machine code but may refer to external library functions such as printf or System.out.println. A linker combines object files and resolves these references into a single executable or library.
编译后,目标文件包含机器码,但可能引用 printf 或 System.out.println 等外部库函数。链接器把目标文件组合,并将这些引用解析为单个可执行文件或库。
A loader is part of the OS that reads the executable from disk, allocates memory, sets up the stack and registers, and transfers control to the entry point. Dynamic linking defers some library resolution until runtime, which reduces file size but can cause dependency issues.
加载器是操作系统的一部分,它从磁盘读取可执行文件、分配内存、设置栈和寄存器,然后把控制权交给入口点。动态链接把部分库解析推迟到运行时,可减小文件大小,但也可能引发依赖问题。
In Edexcel programming projects, you are often asked to distinguish between static and dynamic linking. Static linking bundles all libraries into one file, making deployment simple but increasing executable size. Dynamic linking updates shared libraries separately, but requires the correct version at runtime.
在 Edexcel 编程项目中,经常要求区分静态链接和动态链接。静态链接把所有库打包进一个文件,部署简单但可执行文件变大。动态链接可单独更新共享库,但运行时需要正确版本。
5. Processes, Threads and Context Switching | 进程、线程与上下文切换
A process is a program in execution, with its own memory space, file descriptors and process control block (PCB). A thread is a lightweight unit of execution inside a process. Threads share the process memory, which makes communication fast but introduces race conditions.
进程是正在执行的程序,拥有独立的内存空间、文件描述符和进程控制块(PCB)。线程是进程内的轻量级执行单元。线程共享进程内存,通信速度快,但会引入竞态条件。
Context switching occurs when the OS saves the state of one process or thread and restores another. It involves saving registers, program counter and memory maps. Too many context switches reduce CPU efficiency, a common evaluation point in exams.
上下文切换发生在操作系统保存一个进程或线程状态并恢复另一个时。它需要保存寄存器、程序计数器和内存映射。过多的上下文切换会降低 CPU 效率,这是考试中常见的评估点。
| Feature | Process | Thread |
|---|---|---|
| Memory space | Separate | Shared with parent process |
| Creation time | Slower | Faster |
| Communication | Requires IPC mechanisms | Direct shared memory |
| Failure impact | Isolated | Can crash whole process |
进程与线程在内存空间、创建速度、通信方式和故障影响方面的对比。
In multi-threaded programs, a critical section is a code block that must not be executed by more than one thread at a time. You should be able to spot critical sections in short pseudocode extracts.
在多线程程序中,临界
Published by TutorHao | A-Level 编程 Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply