操作系统与内核 Computer Science

6 个科学问题 · 计算机 Computer Science

本页目录

操作系统进行线程上下文切换时,主要开销来自哪些方面?

What are the main sources of overhead when the operating system performs a thread context switch?

切换的核心开销在于保存与恢复寄存器、程序计数器、栈指针等执行上下文;同进程内的线程切换无需更换地址空间,只有切换到其他进程的线程时才需要更新页表并刷新 TLB。此外切换会使 CPU 缓存、流水线与分支预测器状态失效,频繁切换会让大量时间耗在簿记上而降低吞吐量。
The main cost is saving and restoring the execution context such as registers, the program counter, and the stack pointer; switching threads within the same process needs no address-space change, while only switching to a thread of another process requires updating the page table and flushing the TLB. The switch also invalidates CPU caches, the pipeline, and branch-predictor state, so frequent switching spends much time on bookkeeping and lowers throughput.
难度 专业 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-11-02
来源 · Source

A. Tanenbaum《现代操作系统》第2章 (机械工业出版社)

A. Tanenbaum, Modern Operating Systems, 4th ed., Chapter 2 (Processes and Threads)

#上下文切换 #TLB #调度开销

写时复制(Copy-on-Write)在操作系统创建进程时如何降低开销?

How does copy-on-write reduce overhead when the operating system creates a new process?

当父进程通过 fork 创建子进程时,内核并不立即复制整个地址空间,而是让父子共享同一组只读物理页并标记为只读。任一进程试图写入某页时触发写保护异常,内核才为该页复制一份私有副本,从而把复制成本推迟并只复制到真正被修改的页面。
When a parent forks a child, the kernel does not immediately copy the whole address space but lets both share the same read-only physical pages marked as read-only. When either process writes to a page, a protection fault occurs and the kernel copies that single page into a private copy, deferring and limiting the copy cost to only pages actually modified.
难度 专业 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-11-02
来源 · Source

A. Tanenbaum《现代操作系统》第2章 (机械工业出版社)

R. Love, Linux Kernel Development, 3rd ed., Chapter 3 (Process Management)

#写时复制 #fork #内存优化

虚拟内存中的分页机制是如何把虚拟地址转换为物理地址的?

How does the paging mechanism in virtual memory translate a virtual address into a physical address?

系统将虚拟地址拆分为页号与页内偏移,先用页号查询页表得到对应的物理页帧号,再把页帧号与页内偏移拼接成物理地址。若页表项的有效位为 0,则触发缺页中断,由操作系统将所需页面从磁盘换入内存并更新页表。
The system splits a virtual address into a page number and a page offset, uses the page number to look up the page table for the corresponding physical frame number, and concatenates that frame number with the offset to form the physical address. If the valid bit of the page-table entry is zero, a page fault occurs and the operating system loads the required page from disk into memory and updates the table.
难度 专业 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source

《操作系统》(汤子瀛, 西安电子科技大学出版社) 第3章 内存管理

A. Tanenbaum, Modern Operating Systems, 4th ed., Chapter 3 (Memory Management)

#虚拟内存 #分页 #页表

信号量和互斥锁在同步控制上的主要区别是什么?

What is the main difference between a semaphore and a mutex in synchronization control?

互斥锁用于保护临界区,强调同一时刻只有一个线程持有且通常由持有者释放;信号量是一个可计数的同步原语,可用于线程间发信号或限制同时访问资源的线程数量。互斥锁可视为初值为 1 的二值信号量的特例,但二者在所有权语义上并不相同。
A mutex protects a critical section and emphasizes exclusive ownership by one thread that should release it, while a semaphore is a counting synchronization primitive usable for signaling between threads or limiting how many may access a resource. A mutex is a special case of a binary semaphore initialized to one, but the ownership semantics differ.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source

《操作系统》(汤子瀛, 西安电子科技大学出版社) 第2章 进程同步

A. Tanenbaum, Modern Operating Systems, 4th ed., Chapter 2 (Processes and Threads)

#信号量 #互斥锁 #同步

时间片轮转调度算法的基本工作方式是什么?

How does the round-robin scheduling algorithm work at a basic level?

时间片轮转把所有就绪进程按到达顺序排成队列,调度器依次给每个进程分配一个固定长度的时间片来使用 CPU。若进程在时间片用完前未完成,就被剥夺 CPU 并重新排到队尾等待下一轮。
Round-robin keeps ready processes in a FIFO queue and the scheduler gives each process a fixed-length time slice of CPU in turn. If a process does not finish within its slice, it is preempted and moved to the back of the queue for the next round.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source

《操作系统》(汤子瀛, 西安电子科技大学出版社) 第2章 进程调度

A. Tanenbaum, Modern Operating Systems, 4th ed., Chapter 2 (Processes and Threads)

#调度 #时间片 #轮转

进程和线程在操作系统中最核心的区别是什么?

What is the most fundamental difference between a process and a thread in an operating system?

进程是资源分配的基本单位,拥有独立的地址空间和系统资源;线程是 CPU 调度的基本单位,同一进程内的多个线程共享该进程的地址空间与打开的文件等资源。创建线程的开销通常远小于创建进程,因为线程无需复制整个地址空间。
A process is the basic unit of resource allocation and owns an independent address space and system resources, whereas a thread is the basic unit of CPU scheduling, and multiple threads within the same process share that process's address space and open files. Creating a thread is usually far cheaper than creating a process because the thread does not require copying the entire address space.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-10-04
来源 · Source

《操作系统》(汤子瀛, 西安电子科技大学出版社) 第2章 进程管理

A. Silberschatz, P. Galvin, G. Gagne, Operating System Concepts, 10th ed., Chapter 3 (Processes) and Chapter 4 (Threads)

#进程 #线程 #调度