The operating-system interface
導入済み| English | 意味 |
|---|---|
| process/ˈprəʊses/ | An instance of a program in execution together with its execution state and allocated resources. |
| thread | thread |
| file/faɪl/ | ファイル |
| context switch/ˈkɒntekst swɪtʃ/ | Saving one task's execution state and restoring another's so the processor can change which task it runs. |
| virtual memory/ˈvɜːtʃuːəl ˈmeməri/ | A memory-management system that maps virtual addresses to physical storage and may move pages between RAM and secondary storage. |
| page table/peɪdʒ ˈteɪbl/ | page table |
| TLB | TLB |
| page fault/peɪdʒ fɒlt/ | An exception raised when a memory access cannot be completed using the current page mapping, for example because the required page is not in physical memory. |
| system call | system call |
Many programs, one machine
- A laptop runs a browser, music and an editor at once on a few processor cores. None of them can read another's memory, and none talks to the disk directly.
- The operating system makes this possible. It shares the machine safely, and programs use it through a small set of services.
Processes and threads
- A process 进程 is a program plus its execution state: its own address space, registers, PC and open files.
- A thread 线程 runs inside a process and shares that process's memory. Two processes do not share memory unless they ask to.
Two threads of the same process share that process's memory.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Threads live inside one address space. Separate processes each get their own.
The context switch
- To share one core, the OS does a context switch 上下文切换: it saves the running process's registers and PC, switches the memory mapping, and loads the next process's state.
- The CPU caches are not saved. They are shared hardware, so after a switch they are simply cold for the new process.

A context switch does NOT save —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Caches are shared hardware and are just cold after a switch. The saved state is the registers, the PC and the mapping.
Virtual memory
- With virtual memory 虚拟内存, each process sees its own private addresses. Page tables 页表 map virtual pages to physical frames, and the TLB 快表 caches recent translations.
- It serves three needs: isolation (no process reads another's pages), the illusion of more memory than is installed, and fixed addresses for every program.
Virtual memory gives —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Three needs, one abstraction; page tables and the TLB do the mapping.
Page faults are normal
- A page fault 缺页 means the page is not in physical memory right now. The OS loads it from disk, updates the page table and runs the instruction again.
- This is demand paging, a normal part of operation. A crash comes from touching an address that is not mapped at all.
A page fault is usually —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
In demand paging the fault is the mechanism that brings data in.
Put the steps of a page fault in order.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
The program never notices, apart from the delay.
System calls
- A system call 系统调用 is how a program asks the kernel for help:
open,read,write,fork,execve. Each one traps into the kernel, runs with kernel privileges, then returns. - Files 文件 are named streams of bytes.
fd = open(path, O_RDONLY)thenread(fd, buf, 4096)reads the first 4 KiB, and Python'sopenwraps the same calls.
Match each system call to its job.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Each call crosses into the kernel and comes back.
Worked example: translating an address
- Pages are 4096 bytes. Virtual address 9000: page $= \lfloor 9000 / 4096 \rfloor = 2$, offset $= 9000 - 8192 = 808$.
- The page table maps page 2 to frame 5, so the physical address is $5 \times 4096 + 808 = 21288$.
Pages are 4096 bytes. Which page number holds virtual address 13000?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
13000 ÷ 4096 = 3.17, so page 3 (it starts at 12288).
Pages are 4096 bytes and page 3 maps to frame 2. What physical address does virtual address 13000 become?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Offset = 13000 − 12288 = 712. Physical = 2 × 4096 + 712 = 8904.
Three common slips
- Mixing up processes and threads. Processes have their own memory; threads share it.
- Thinking
malloctouches the disk. It hands out memory, not file space. - Reading every page fault as a crash. Most are the OS fetching a page, as designed.
Recap
- Process = program + state; a context switch saves registers and PC and switches the mapping.
- Virtual memory: page tables and the TLB map virtual to physical, for isolation, illusion and convenience.
- A page fault is a fetch, not a failure; system calls are the doorway into the kernel.