根据这个问题: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/