Process Control Block is the primary entity for the Operating System to achieve a higher degree of multiprogramming and it works as a key for the respective process to work on it and manipulates its data by Operating System.
Scope:
- We will discuss when PCB’s initialized and How it is represented at the code level.
- We will discuss How PCB’s work as a lookup for a process for its all life. PCB Initialization When the Operating System creates a Process it will create a corresponding Process Control Block which will serve as a descriptor for the whole runtime of the process. While doing this the Operating System will initialize all the necessary attributes in the Process control block.
PCB Representation
As we are aware of how Process Control blocks are stored In the Linux Operating System if we dig deeper, the Process Control Block can be represented as a C Structure task_structure in the source code directory of the kernel. This structure can consist of attributes necessary in Process Control Block so Inside the kernel, All active processes are connected as a doubly-linked list of Process Control blocks and Operating System maintains a pointer to Process Control Block which is in execution.
How does the PCB work?
As a part of the execution Operating System maybe manipulate information for Process Control Block in execution, Let's assume that Operating System would like to change the currently running state of the Process Control Block to another state. As we know Operating System has a current pointer pointing towards the process control block so its state can be changed as follows current -> process_state = new_state
To achieve a higher degree of multiprogramming and to make sure the CPU will not stay idle, the Operating System rapidly switches between multiple processes to keep the CPU busy. Process Control Block works here as a source of truth about the respective process.
Let's assume Operating System suspends current process P1 means it manipulates the Process Control Block of current Process P1, so details about the processor registers necessary for current Process execution are saved on the stack, and reference to that frame of the stack is stored in Process Control Block. Now the CPU is available for other processes which are ready to execute so one of the processes P2 starts executing and the Operating System points the current pointer to the Process Control Block of P2.
Now if Operating System wants to load process P1 again in CPU then it uses Process table to locate the Process Control Block of P1 and the Operating System locates related stack frame where all processor registers details are stored which will help the Operating System to restore Hardware state which is necessary for the execution of Process P1
Summary:
- Process Control Block will be initialized in Process creating phase
- Process Control Block represented as C structure in Linux operating system
- Process Control Block of process in execution is pointed by the current pointer of the Operating System.
- In the dormant state of Process, all details about the process are stored in the Process Control Block to restore when the process again comes into running state.
Author Bio
Akash Pawar is a Software Engineer and has a passion to write technical blogs with expertise in Data Structure and Algorithms,Operating System and has a great exposure to large Scale System Design.
Comments (0)