operating-system - 发生上下文切换时PC和CPU寄存器?

标签 operating-system context-switch

根据这个问题:Storing and retrieving process control block

PCB包含大量信息,由内核管理(以避免用户访问)。

但是我对 PC 和 CPU 寄存器有疑问。内核是在每次执行指令时保存这些值还是仅在上下文切换过程中保存这些值?

PCB 是链表吗?

最佳答案

实际上,CPU寄存器的值是根据指令的运行顺序来修改的。

也就是说,指令指针指向下一条要执行的指令,堆栈指针如果处于事件状态,则会将最后一个程序请求的地址存储在堆栈中。等等。这些基本上都是CPU寄存器!

PCB has one of the part Processor state data,which are those pieces of information that define the status of a process when it's suspended, allowing the OS to restart it later and still execute correctly. This always includes the content of the CPU general-purpose registers, the CPU process status word, stack and frame pointers etc. During context switch, the running process is stopped and another process is given a chance to run. The kernel must stop the execution of the running process, copy out the values in hardware registers to its PCB, and update the hardware registers with the values from the PCB of the new process. // (Taken from Wikipedia)

内核是在每次执行指令时保存这些值还是仅在上下文切换过程中保存这些值?

那么,您的问题可能已经解决了。内核只在上下文切换的情况下才关心保存硬件(CPU)寄存器的值,通常情况下不会。否则,它会将维护寄存器的负担留给进程本身!

另外,最后一个问题的答案是---PCB的实现“通常”是作为双向链表数据结构完成的!

关于operating-system - 发生上下文切换时PC和CPU寄存器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24452484/

相关文章:

c++ - RTOS 中第一个任务切换的代码

linux - 哪些进程写入/var/adm/messages

networking - 向连接到局域网的所有人发送消息

multithreading - 上下文切换中保存了什么?

linux - "vmstat"和 "perf stat -a"显示不同的上下文切换数字

windows - 每个线程如何拥有 CPU 寄存器

c - makecontext uc_link 给出段错误

CreateProcess 方法以错误结束

linux - 硬件定时器中断在哪里?

arm - Arm中的任务切换