Steps in Context Switching

前端 未结 4 1080
感情败类
感情败类 2020-12-12 10:05

I am asked to describe the steps involved in a context switch (1) between two different processes and (2) between two different threads in the same process.

  1. Du
4条回答
  •  被撕碎了的回忆
    2020-12-12 11:00

    1. In a switch, the state of process currently executing must be saved somehow, so that when it is rescheduled, this state can be restored.
    2. The process state includes all the registers that the process may be using, especially the program counter, plus any other operating system specific data that may be necessary. This is usually stored in a data structure called a process control block (PCB) or switchframe.
    3. The PCB might be stored on a per-process stack in kernel memory (as opposed to the user-mode call stack), or there may be some specific operating system defined data structure for this information. A handle to the PCB is added to a queue of processes that are ready to run, often called the ready queue.
    4. Since the operating system has effectively suspended the execution of one process, it can then switch context by choosing a process from the ready queue and restoring its PCB. In doing so, the program counter from the PCB is loaded, and thus execution can continue in the chosen process. Process and thread priority can influence which process is chosen from the ready queue (i.e., it may be a priority queue).

    (Source: Context switch)

提交回复
热议问题