Operating Systems
A-Level Computer Science Topic 5 21:00 English narration · English + 中文 subtitles burned in
Chapters
Transcript
You have never seen it, and you never will — yet it is always there.
你从没见过它,也永远不会见到——可它一直都在。
Behind every app you open, every file you save, every tap on the screen, an invisible manager is hard at work.
在你打开的每一个应用、保存的每一个文件、 在屏幕上的每一次点触背后,一位看不见的管理者都在忙碌。
Which program gets the processor next?
下一个该轮到哪个程序用处理器?
Where does each one's memory begin and end?
每个程序的内存从哪里开始、到哪里结束?
How does a keypress reach the right window?
一次按键怎样送到正确的窗口?
It decides all of it, thousands of times a second.
这一切都由它来决定, 每秒钟成千上万次。
That manager is the operating system — and without it, your computer is just silicon that can count.
这位管理者就是操作系统——没有它,你的计算机不过是一块会计数的硅片。
The operating system is the software that runs everything else.
操作系统是运行其他一切软件的软件。
Today: the jobs it manages, how it shares the hardware safely, the translators that turn your code into machine code, program libraries, and the IDE you write in.
今天:它所管理的各项工作、它如何安全地共享硬件、 把你的代码变成机器码的翻译器、程序库,以及你用来写代码的集成开发环境。
Let's begin.
让我们开始吧。
The operating system has five big jobs.
操作系统有五项大工作。
Process management: loading programs, and deciding which one runs on the CPU, and when.
进程管理:加载程序,并决定哪一个在 CPU 上运行、什么时候运行。
Memory management: giving each program its own space, and stretching it with virtual memory.
内存管理:给每个程序它自己的空间,并用虚拟内存把它撑大。
File management: organising your files and folders on disk.
文件管理: 在磁盘上组织你的文件和文件夹。
Device management: talking to the keyboard, screen and printer through drivers.
设备管理:通过驱动程序与键盘、屏幕和打印机交谈。
And security: accounts, permissions, and keeping intruders out.
还有安全管理:账户、权限,以及把入侵者挡在门外。
Start with what the OS is FOR, because "it manages resources" alone is too vague to score.
先讲清楚操作系统是干什么的,因为只说"它管理资源"太笼统,拿不到分。
Hardware on its own can only fetch and run instructions — it knows nothing about files, programs, networks or users.
硬件本身只会取指令、执行指令——它对文件、程序、网络和用户一无所知。
The operating system is the software layer that does four things.
操作系统是那一层软件,它做四件事。
It manages the hardware — processor, memory, input-output, storage — for the running programs.
它为正在运行的程序管理硬件—— 处理器、内存、输入输出、存储。
It provides services such as the file system, networking and user accounts, through a clear interface, so programs need not talk to the hardware directly.
它通过清晰的接口提供文件系统、 网络和用户账户这些服务,于是程序不必直接跟硬件打交道。
It provides a user interface: command line, graphical, or touch.
它提供用户界面:命令行、图形界面,或者触摸。
And it lets several programs share the hardware safely, each getting fair CPU time and kept out of the others' memory.
而且它让若干程序安全地共享硬件,各自获得公平的处理器时间, 又互不侵入对方的内存。
Without an OS, every program would need its own drivers, and only one program could safely run at a time.
没有操作系统,每个程序都得自带驱动, 而且同时只能安全地运行一个程序。
When the question says describe the purpose of an operating system for five marks, it wants five different points, and "it runs the computer" earns none of them.
当题目说「描述操作系统的作用」给五分时,它要的是五个不同的点, 「它运行计算机」一分都拿不到。
One: it provides an interface between the user and the hardware.
第一:它在用户和硬件之间提供接口。
Two: it hides the complexity of the hardware from the user and from the application programs.
第二:它对用户和应用程序隐藏硬件的复杂性。
Three: it manages the hardware resources — processor time, memory, storage, input and output — and shares them between programs.
第三:它管理硬件资源——处理器时间、内存、存储、输入输出——并在程序之间分配。
Four: it loads application software into memory and runs it, giving every program the same platform.
第四:它把应用软件装入内存并运行,给每个程序同样的运行平台。
Five: it lets several programs run at once — multitasking — while keeping them and the users' data secure.
第五:它让多个程序同时运行——也就是多任务处理——同时保证程序和用户数据的安全。
Name the tasks — this is exactly what an exam asks for.
把这些任务的名字说出来——这正是考试要的。
Process management: load programs, schedule them on the CPU, switch between them, and kill misbehaving ones; a running program is a process.
进程管理:加载程序、 把它们调度到处理器上、在它们之间切换、并终止行为异常的程序; 正在运行的程序就是一个进程。
Memory management: give memory to processes, keep them apart, and use virtual memory and paging so the working set can exceed physical RAM.
内存管理:给进程分配内存、让它们彼此隔离, 并使用虚拟内存和分页,让工作集可以超过物理内存的容量。
File management: organise files and folders on secondary storage, control permissions, prevent write corruption.
文件管理:在辅助存储器上组织文件和文件夹、控制权限、防止写入损坏。
Device management: handle input-output and peripherals through device drivers, buffer data, manage interrupts, and present a uniform interface.
设备管理:通过设备驱动处理输入输出和外设、缓冲数据、管理中断, 并提供统一的接口。
Security management: accounts, permissions, firewall, encryption.
安全管理:账户、权限、防火墙、加密。
Plus the user interface and networking.
再加上用户界面和网络。
Two of the five deserve their exam words.
五项里有两项要用考试的原话。
File management keeps the directory structure and a record of where every file physically sits on the disk, and it enforces access rights — read, write, execute — for each user.
文件管理维护目录结构,并记录每个文件在磁盘上的实际位置, 而且为每个用户执行访问权限——读、写、执行。
Security management is where authentication lives: user accounts and passwords, plus encryption of stored data, a firewall, automatic updates, and a log of who did what.
安全管理就是身份验证所在的地方:用户账户和密码, 再加上存储数据的加密、防火墙、自动更新,以及谁做了什么的日志。
Here is what "keeping processes apart" actually looks like.
"让进程彼此隔离"具体是什么样子,就在这里。
Memory is divided into blocks, one for the operating system and one for each application, separated by boundary addresses.
内存被划分成一个个块, 操作系统占一块,每个应用程序各占一块,块与块之间由边界地址隔开。
An access inside a process's own block is allowed.
进程访问自己块内的地址是允许的。
An access that strays past a boundary is blocked — the hardware and the OS together refuse it.
越过边界的访问会被阻止—— 硬件和操作系统一起拒绝它。
Two consequences worth stating.
有两个后果值得说出来。
A crashing program cannot corrupt another program's data or the OS itself.
一个崩溃的程序无法破坏另一个程序的数据,也无法破坏操作系统本身。
And a malicious program cannot simply read another program's memory to steal what is in it.
而一个恶意程序也无法直接读取另一个程序的内存,把里面的东西偷走。
Memory protection is what makes running several programs at once safe rather than merely possible.
内存保护正是让同时运行多个程序不只是可能、而且安全的原因。
Two of those jobs keep many programs running at once, safely.
这五项工作里有两项,让许多程序能同时安全地运行。
The scheduler hands each process a slice of CPU time, switching between them so fast it looks simultaneous.
调度器给每个进程分一小片 CPU 时间, 在它们之间飞快地切换,快到看上去像是同时进行。
And memory protection gives each program its own block of RAM, with strict boundaries: stray outside your block, and the OS blocks you — so one crashing program cannot corrupt another.
而内存保护给每个程序它自己的一块 RAM, 有着严格的边界:越出你自己的块,操作系统就拦住你——这样一个崩溃的程序就不会破坏另一个。
Need more memory than you have?
需要的内存比你有的还多?
Virtual memory pages the least-used parts out to disk.
虚拟内存就把最不常用的部分换页到磁盘上去。
That pairing is a four-mark favourite: how memory and process management support multitasking.
这一对是四分题的常客:内存管理和进程管理如何支撑多任务处理。
Memory management loads several programs into memory at the same time, each in its own protected area, and keeps track of which addresses belong to which.
内存管理把多个程序同时装入内存,每个放在自己受保护的区域, 并记录哪些地址属于哪个程序。
Process management shares the processor between them — each process runs for a time slice, the OS saves its state and switches to the next — and the switching is fast enough that they appear to run together.
进程管理在它们之间分配处理器——每个进程运行一个时间片, 操作系统保存它的状态然后切换到下一个——切换快到它们看起来像在同时运行。
Interrupts are what let the OS take the processor back whenever a device needs attention: the interrupt handler saves the state of the running process, deals with the interrupt, then restores the process exactly where it was.
中断是操作系统随时把处理器收回来的手段: 中断处理程序保存正在运行的进程的状态,处理完中断,再把进程恢复到原来的位置。
You write code in a high-level language, but the CPU only runs machine code.
你用高级语言写代码,但 CPU 只运行机器码。
A translator bridges the gap.
翻译器架起这座桥。
A compiler translates the whole program once, up front, into a stand-alone executable — fast to run, but you must recompile for each platform.
编译器把整个程序一次性、 提前地翻译成一个独立的可执行文件——运行快,但你必须为每个平台重新编译。
An interpreter translates and runs one line at a time, every time — slower, but easy to fix and to port.
解释器则每次都一行一行地翻译并运行——慢一些,但容易修改、容易移植。
And an assembler turns low-level assembly into machine code, one instruction to one.
而汇编器把低级的汇编语言翻译成机器码,一条指令对一条。
Most operating systems include utility programs to maintain the system, and you should be able to name several.
大多数操作系统都自带一些实用程序来维护系统,你应当能说出好几个。
The disk tools: a disk formatter prepares a disk by setting up its file system, and related tools copy, move and delete files; disk contents analysis and disk repair software checks integrity and fixes file-system errors and bad sectors.
磁盘工具:磁盘格式化程序通过建立文件系统来准备一块磁盘, 相关的工具还负责复制、移动和删除文件;磁盘内容分析与磁盘修复软件检查磁盘完整性, 修复文件系统错误和坏扇区。
Defragmentation software moves the pieces of fragmented files together on a hard disk to cut seek time — and note the qualifier, it is NOT useful on an SSD, which has no seek time to save.
碎片整理软件把碎片化文件的各个片段 在硬盘上挪到一起,以减少寻道时间——注意那个限定条件, 它对固态硬盘没有用,因为那里根本没有寻道时间可省。
Back-up software copies user data elsewhere so it can be recovered.
备份软件把用户数据复制到别处,以便日后恢复。
A virus checker scans for malware and quarantines threats.
杀毒软件扫描恶意软件并隔离威胁。
A firewall filters network traffic by rules.
防火墙按规则过滤网络流量。
Plus file compression, a system monitor and updates.
再加上文件压缩、系统监视器和更新程序。
Bundling these with the OS saves the user installing each one separately.
把这些和操作系统打包在一起,省得用户一个一个去装。
Three of those carry exam wording worth having.
其中三项的考试措辞值得记住。
A virus checker compares code against a database of known virus signatures and also watches for suspicious behaviour.
杀毒软件把代码和已知病毒签名的数据库做比对,同时也监视可疑行为。
Backup software makes a full copy and then incremental backups of only what has changed since — and backup is the only real recovery from ransomware.
备份软件先做一次完整拷贝,之后只对变化的部分做增量备份—— 而且遇到勒索软件时,备份是唯一真正的恢复手段。
And the three-mark defragmentation answer is this: over time a file is stored in blocks scattered across the disk, so reading it needs many head movements; the defragmenter rearranges the blocks so each file is stored contiguously and the free space is gathered together, so files load faster and new files are not fragmented.
三分的碎片整理答案是这样的: 时间久了,一个文件被存在磁盘上分散的块里,读它就需要磁头多次移动; 碎片整理程序把这些块重新排列,让每个文件连续存放,并把空闲空间聚到一起, 于是文件加载更快,新文件也不会一开始就碎片化。
It is not needed on an S S D, which has no moving head.
固态硬盘不需要它,因为它没有会移动的磁头。
A program library is pre-written code — subroutines, classes, modules — that programs reuse instead of writing it themselves.
程序库是预先写好的代码——子程序、类、模块——供程序复用,而不必自己重写。
Three benefits: it saves time, it is reliable because it is well-tested and widely used, and it is standardised, giving consistent behaviour.
它有三个好处:省时间;可靠,因为它经过充分测试、被广泛使用; 以及标准化,行为一致。
Now the distinction that gets examined.
现在说那个会被考到的区别。
A static library is copied INTO the executable at compile time: the program then stands alone, but it is larger, and updating the library means rebuilding the program.
静态库在编译时被复制进可执行文件里:程序因此可以独立运行, 但体积更大,而且要更新这个库就必须重新编译程序。
A dynamic library — a DLL on Windows, a dot-so on Linux — stays a separate file loaded at RUN time: executables are smaller, one copy is shared by many programs, and updating it once updates it for all of them.
动态库——在 Windows 上是 DLL,在 Linux 上是点 so 文件—— 作为独立的文件保留下来,在运行时才加载:可执行文件更小, 一份副本被许多程序共享,更新它一次,所有程序就都更新了。
The examiner's benefit list, for the developer, is worth learning as a list.
考官那份「对开发者的好处」清单值得当成一张表来背。
The library routines are already written and tested, so development is faster and cheaper; they are reliable and, being used by many programs, largely error-free; the developer needs no expertise in that area — graphics, encryption, path-finding; the program is easier to maintain because common code lives in one place; and a whole team can call the same routines and get consistent results.
库例程已经写好并测试过,所以开发更快也更便宜; 它们可靠,而且因为被很多程序使用,基本上没有错误; 开发者不需要在那个领域有专长——图形、加密、寻路; 程序更容易维护,因为公共代码集中在一个地方; 而且整个团队可以调用同样的例程,得到一致的结果。
Drawbacks, equally: a routine may not do exactly what you need and you cannot change it; your program depends on the library being available, correct and secure, so a bug or a security hole in the library is a bug in your program; and you have to learn how to call it.
缺点同样成列:例程可能并不完全符合你的需要,而你又改不了它; 你的程序依赖这个库是可用的、正确的、安全的, 所以库里的一个缺陷或者安全漏洞,就是你程序里的缺陷; 另外你还得先学会怎么调用它。
Dynamic Link Library files, once more precisely: a D L L is loaded into memory only when a program calls it, at run time, and stays a separate file rather than being copied into the executable.
再说一遍动态链接库文件:DLL 只在程序调用它的时候才被装入内存, 也就是在运行时,而且它始终是一个单独的文件,不会被复制进可执行文件。
The benefits are a smaller executable, one copy in memory shared by several running programs, and an update that fixes a bug without recompiling the programs that use it.
好处是可执行文件更小、多个运行中的程序共享内存里的同一份、 更新 DLL 不需要重新编译用到它的程序。
The drawbacks: the program will not run if the D L L is missing, moved or the wrong version, and a fake one put in its place runs with the program's own rights.
缺点是 DLL 丢失、被移动或者版本不对,程序就跑不起来。
Programmers rarely start from scratch.
程序员很少从零开始。
A program library is ready-made, well-tested code — for maths, graphics, networking — that any program can reuse.
程序库是现成的、经过充分测试的代码——用于数学、图形、网络—— 任何程序都能重用它。
A static library is copied right into your program when it is built: self-contained, but bigger.
静态库在程序构建时就被直接复制进你的程序里:自成一体,但更大。
A dynamic library stays a separate shared file, loaded only when needed — smaller programs, and one update fixes them all.
动态库则保持为一个独立的共享文件,只在需要时才加载——程序更小,而且一次更新就能修好所有用到它的程序。
And your OS bundles utility software too: antivirus, backup, compression, defragmenter.
你的操作系统还打包了实用程序:杀毒、备份、压缩、碎片整理。
You write source code; the computer runs machine code; a translator converts between them.
你写的是源代码;计算机运行的是机器码;翻译器在两者之间转换。
Three kinds.
有三种。
An assembler translates assembly language into machine code, one instruction per instruction — used for low-level work like embedded systems and drivers.
汇编器把汇编语言翻译成机器码,一条指令对一条指令—— 用于嵌入式系统和驱动这类底层工作。
A compiler translates a whole high-level program into machine code ONCE, before it runs: it reports all errors at compile time, and once clean it produces a standalone executable that runs WITHOUT the compiler installed and can be run many times.
编译器在程序运行之前, 把整个高级语言程序一次性翻译成机器码:它在编译时报告所有错误, 一旦通过,就产生一个独立的可执行文件,不需要装编译器就能运行, 而且可以运行很多次。
It is generally faster at run time, but it is tied to one CPU and OS, so you recompile for each platform.
它的运行速度通常更快, 但它绑定在某一种处理器和操作系统上,换平台就要重新编译。
An interpreter translates and runs one line at a time, producing no executable: it reports an error when it REACHES that line and stops, which is good for development, but the interpreter must be installed to run the program, and it is generally slower because every run re-translates.
解释器一次翻译并运行一行,不产生可执行文件: 它在走到那一行时才报告错误并停下,这对开发很有利, 但要运行这个程序就必须装解释器,而且通常更慢,因为每次运行都要重新翻译一遍。
Say those two descriptions in the mark scheme's own words.
这两段描述要用评分标准自己的话说。
A compiler translates the whole high-level program into machine code — the object code — before it is run, produces an executable file, and reports all the syntax errors together as a list at the end of translation; it does not run the program.
编译器在程序运行之前,把整个高级语言程序翻译成机器码——也就是目标代码—— 生成一个可执行文件,并在翻译结束时把所有语法错误一起列成清单报告出来; 它并不运行这个程序。
An interpreter translates one statement of the high-level program at a time and executes it immediately before moving on to the next; it produces no executable file, and it stops at the first error it meets and reports that one.
解释器一次翻译高级语言程序的一条语句,并立即执行它,然后再看下一条; 它不生成可执行文件,而且遇到第一个错误就停下来,只报告那一个。
So which do you choose?
那么该选哪一个?
Use a compiler when run-time speed matters, because there is no translation happening while the program runs.
当运行速度重要时用编译器,因为程序运行时不再有翻译发生。
When distributing to users who do not have developer tools installed, because the executable stands alone.
当要分发给没有装开发工具的用户时用编译器,因为可执行文件可以独立运行。
And when the program will be run many times, so the one-off translation cost is amortised.
当程序要被运行很多次时用编译器,这样一次性的翻译开销就被摊薄了。
Use an interpreter when you want fast edit-run cycles, because there is no compile step between a change and a test.
当你想要快速的"改一改、跑一跑"循环时用解释器, 因为从修改到测试之间没有编译这一步。
When writing cross-platform scripts, since the same source runs anywhere the interpreter runs.
当要写跨平台脚本时用解释器, 因为同一份源代码在任何装了解释器的地方都能跑。
When the program is small or run only once.
当程序很小、或者只运行一次时用解释器。
And when teaching beginners, because an error is reported at the line where it happened.
以及在教初学者时用解释器,因为错误会在它发生的那一行被报出来。
Java source is compiled to bytecode, which a JVM then interprets.
Java 源代码被编译成字节码,再由 Java 虚拟机来解释。
Why use both, instead of compiling straight to machine code?
为什么要用两者,而不是直接编译成机器码?
A compiler produces machine code for ONE processor and operating system, so a program compiled on one machine will not run on another.
编译器产生的是针对某一种 处理器和操作系统的机器码,所以在一台机器上编译出来的程序, 在另一台上跑不起来。
Java's compiler instead targets a VIRTUAL machine, so the bytecode it produces is identical everywhere; each platform then supplies its own JVM to interpret that bytecode into its own native instructions.
而 Java 的编译器针对的是一台虚拟的机器, 于是它产生的字节码在哪里都完全相同;再由每个平台提供自己的虚拟机, 把这些字节码解释成它自己的本地指令。
One compiled file therefore runs anywhere a JVM exists — write once, run anywhere.
因此一个编译好的文件, 在任何有虚拟机的地方都能运行——一次编写,到处运行。
The price is speed: interpreting bytecode is slower than running native code, which is why a real JVM also uses JIT — just-in-time — compilation to turn frequently-run bytecode into native code while the program runs.
代价是速度:解释字节码比直接运行本地代码慢, 这正是真实的虚拟机还要用即时编译、 在程序运行过程中把频繁执行的字节码转成本地代码的原因。
Name BOTH sides — the marks are for portability bought at the cost of speed.
两方面都要说出来——分数给的是"用速度换来的可移植性"。
The syllabus phrase for this is partially compiled and partially interpreted.
考纲对这件事的说法是「部分编译、部分解释」。
The compiler stage catches the syntax errors and produces compact, portable bytecode; the interpreting stage lets that one bytecode file run on any machine that has a virtual machine, at the cost of some speed.
编译阶段抓出语法错误,产出紧凑、可移植的字节码; 解释阶段让这同一个字节码文件在任何装有虚拟机的机器上运行,代价是损失一些速度。
Java in console mode — a text program run from the command line — is the syllabus's own example.
考纲自己举的例子是控制台模式下的 Java——也就是从命令行运行的文本程序。
If you are asked why use both instead of compiling straight to machine code, name both sides: portability, bought at the cost of speed.
如果题目问「为什么要两者都用,而不直接编译成机器码」,两边都要说到: 可移植性,是用速度换来的。
Finally, where you write it all: an integrated development environment — an IDE.
最后,你在哪里把这一切写出来:一个集成开发环境——IDE。
It gathers every tool into one place.
它把每一样工具都聚到一处。
A smart editor, with syntax highlighting and auto-complete.
一个聪明的编辑器,带有语法高亮和自动补全。
One button to compile and run.
一个按钮就能编译并运行。
And a debugger — the real prize — that lets you set a breakpoint, pause the program mid-run, step through it line by line, and watch every variable change.
还有一个调试器——真正的宝贝——它让你设置断点,在程序运行中途暂停,一行一行地单步执行, 并盯着每一个变量的变化。
Write, run, debug, fix — all without leaving the window.
写、运行、调试、修复——全都不用离开这个窗口。
An IDE brings the tools to write, test and debug code into one application, and a question wants the features named.
集成开发环境把编写、测试和调试代码的工具都装进一个应用里, 而题目要的是把这些功能一一说出来。
A source code editor with syntax highlighting — keywords, strings and comments in different colours — plus auto-indent and bracket matching.
带语法高亮的源代码编辑器—— 关键字、字符串和注释用不同颜色显示——外加自动缩进和括号匹配。
Auto-complete, which suggests names and shows function parameters as you type.
自动补全,在你打字时提示名称并显示函数参数。
Translator integration: compile and run with one keystroke, with errors shown inline against the line that caused them.
翻译器集成:一个按键就能编译并运行,错误就标在引发它的那一行旁边。
The debugger — and this is the one most worth detail: set breakpoints to pause execution, step through line by line, and inspect variables while the program is stopped.
调试器——这一个最值得展开:设置断点让程序暂停、逐行单步执行, 并在程序停下时检查变量的值。
And then version control integration, project management, a help system, refactoring tools for safe renaming, and unit test integration.
此外还有版本控制集成、项目管理、 帮助系统、用于安全重命名的重构工具,以及单元测试集成。
The syllabus sorts the features into four groups, and questions ask you to sort them, so learn which belongs where.
考纲把这些功能分成四组,而且题目会要你把它们归类,所以要记清哪个属于哪一组。
For coding: context-sensitive prompts, which pop up the identifiers, keywords or parameters that fit at that point in the code, plus auto-complete, automatic indentation and bracket matching.
用于编码的:上下文相关提示,会弹出在当前位置合适的标识符、关键字或者参数, 再加上自动补全、自动缩进和括号匹配。
For initial error detection: dynamic syntax checks, which underline a mistake as you type, before the program is translated.
用于初步查错的:动态语法检查,你一边输入它就一边给错误画下划线, 在程序被翻译之前就提示。
For presentation: prettyprint — keywords, strings and comments in different colours with consistent indentation — and the ability to expand and collapse code blocks so you see the outline.
用于呈现的:代码美化——关键字、字符串和注释用不同颜色显示,缩进保持一致—— 以及展开和折叠代码块,让你能看到整体结构。
For debugging: breakpoints, single stepping, a window showing the current values of variables and expressions as they change, and a report window listing errors, warnings and output.
用于调试的:断点、单步执行、 一个随时显示变量和表达式当前值的窗口, 以及一个列出错误、警告和输出的报告窗口。
Prettyprint and collapsing blocks are presentation, not debugging: that is the sorting the examiner is testing.
代码美化和折叠代码块属于呈现,不属于调试:这正是考官在考的那个分类。
The debugger workflow is worth walking through, because describing it is a common question.
调试器的工作流程值得走一遍,因为描述它是一道常见的题。
Set a breakpoint on the line you are suspicious of.
在你怀疑的那一行上设置一个断点。
Run the program normally.
像平常一样运行程序。
When execution reaches that line it PAUSES — it does not stop, it waits — and now you can inspect the variables and see their actual values at that moment.
当执行到达那一行时,程序会暂停——不是停止,而是等着—— 这时你可以检查各个变量,看到它们在那一刻的实际值。
From there you either step a line at a time, watching the values change, or continue running to the next breakpoint.
从这里开始,你要么一行一行地单步执行,看着这些值变化; 要么继续运行到下一个断点。
That is why a debugger beats scattering print statements: you see every variable at once, and you can decide what to look at after the program has already stopped.
这正是调试器胜过到处插打印语句的原因: 你能一次看到所有变量,而且可以在程序已经停下之后,再决定要看什么。
A definition question is marked against fixed wording, so learn these exactly and give one answer only.
定义题是按固定措辞给分的,所以要背准,而且只给一个答案。
An operating system is software that manages the computer's hardware and resources and provides an interface between the user, the application programs and the hardware.
操作系统,是管理计算机硬件和资源、并在用户、应用程序和硬件之间提供接口的软件。
Utility software is system software that performs a specific task to maintain, optimise or protect the computer.
实用程序,是执行某一项特定任务来维护、优化或者保护计算机的系统软件。
A program library is a collection of pre-written, tested routines that a program can use instead of writing its own.
程序库,是一组预先写好、测试过的例程,程序可以直接使用,不必自己再写。
A D L L is a program library whose routines are loaded into memory only when the program calls them, at run time, and are shared between programs.
动态链接库,是这样一种程序库:它的例程只在程序调用时才被装入内存,也就是在运行时, 而且在多个程序之间共享。
An assembler converts an assembly language program into machine code, one machine instruction for each assembly instruction.
汇编器,把汇编语言程序转换成机器码,一条汇编指令对应一条机器指令。
A compiler converts the whole of a high-level program into machine code before it is run, producing an executable file.
编译器,在程序运行之前把整个高级语言程序转换成机器码,并生成一个可执行文件。
An interpreter translates and executes a high-level program one statement at a time.
解释器,一次翻译并执行高级语言程序的一条语句。
And the answers that lose marks every year.
再说每年都在丢分的那些答法。
Writing that the OS manages resources, with no named task: each mark is one named task and what it does.
写「操作系统管理资源」却不点名任何一项任务:每一分对应的是一项被点名的任务和它做的事。
Saying an interpreter compiles line by line: an interpreter translates and executes each statement, and it never produces an executable.
说解释器「逐行编译」:解释器是翻译并执行每一条语句,而且它从不生成可执行文件。
Saying the compiler runs the program: it only translates, and the executable runs later, without it.
说编译器运行程序:它只做翻译,可执行文件是之后运行的,而且运行时不需要它。
Putting a DLL inside the executable: that is a static library — a DLL stays a separate file, loaded at run time.
把动态链接库说成在可执行文件「里面」:那是静态库—— DLL 始终是一个单独的文件,在运行时装入。
Saying defragmentation deletes or compresses files, or that an SSD needs it: it only moves blocks so each file is contiguous.
说碎片整理会「删除」或者「压缩」文件,或者说固态硬盘需要它: 它只是移动块,让每个文件连续存放。
And filing prettyprint under debugging: prettyprint and collapsing blocks are presentation features; debugging is breakpoints, single stepping, watching variables and the report window.
还有把美化打印归到调试里:美化打印和折叠代码块是呈现功能; 调试是断点、单步执行、监视变量和报告窗口。
Three marks to secure.
三个要拿稳的分。
First, name the OS's jobs — process, memory, file, device and security management — not just "manages resources".
第一,把操作系统的各项工作说出名字——进程、内存、文件、设备和安全管理—— 而不是只说"管理资源"。
Second, a compiler translates once into an executable and reports all errors up front; an interpreter translates line by line, every run.
第二,编译器一次性翻译成可执行文件,并把所有错误提前报出来; 解释器则每次运行都一行一行地翻译。
Third, an IDE bundles editor, translator and debugger, with breakpoints and variable inspection.
第三,IDE 把编辑器、翻译器和调试器打包在一起, 带有断点和变量查看。
Master these, and operating systems are yours.
掌握这些,操作系统就是你的了。