What happens to a PCB when the state of a process changes?


Process control block (PCB) is used by the operating system to store different information about the process including process state, registers, program counter, registers etc. It plays an important role when a context switching happens (the current process is pre-empted by another process with higher priority).

The important information stored in PCB includes the following −

  • Process Number (PID) − Used to uniquely identify each process.

  • Program counter − It stores the address of the next instruction which is to be executed.

  • Register Info − Includes different CPU registers such as base, accumulators and general purpose register.

  • State − State in the life cycle of the current executing process.

Given below is an example of a PCB −

Process state
Process number
Process counter
Register
Memory limits
List of open files
----------

Let us have a look at how the CPU switches from process to process.

Here,

  • During the context switch, OS must save the PCB contents of the currently executing process and then create a new PCB for the new process,

  • If the new process already existed, it will simply restore its PCB. The OS has a queue of PCBs, with each process having its own PCB.

  • All the processes and their PCB address are stored in a separate data structure called a process table.

  • PCB has all the necessary information for the OS to resume the execution of the process which is its main purpose.

Updated on: 01-Dec-2021

875 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements