What Is Process Control Block
What Is Process Control Block
Process Control Block is a data structure that contains information of the process related to
it. The process control block is also known as a task control block, entry of the process table,
etc.
It is very important for process management as the data structuring for processes is done in
terms of the PCB. It also defines the current state of the operating system.
The process control stores many data items that are needed for efficient process
management. Some of these data items are explained with the help of the given diagram −
Process State
This specifies the process state i.e. new, ready, running, waiting or terminated.
Process Number
Program Counter
This contains the address of the next instruction that needs to be executed in the process.
Registers
This specifies the registers that are used by the process. They may include accumulators,
index registers, stack pointers, general purpose registers etc.
These are the different files that are associated with the process
The process priority, pointers to scheduling queues etc. is the CPU scheduling information
that is contained in the PCB. This may also include any other scheduling parameters.
The memory management information includes the page tables or the segment tables
depending on the memory system used. It also contains the value of the base registers, limit
registers etc.
This information includes the list of I/O devices used by the process, the list of files etc.
Accounting information
The time limits, account numbers, amount of CPU used, process numbers etc. are all a part
of the PCB accounting information.
The process control block is kept in a memory area that is protected from the normal user
access. This is done because it contains important process information. Some of the
operating systems place the PCB at the beginning of the kernel stack for the process as it is a
safe location.
Context switching.
Context Switching in OS (Operating System)
The Context switching is a technique or method used by the operating system to switch a
process from one state to another to execute its function using CPUs in the system. When
switching perform in the system, it stores the old running process's status in the form of
registers and assigns the CPU to a new process to execute its tasks. While a new process is
running in the system, the previous process must wait in a ready queue. The execution of
the old process starts at that point where another process stopped it. It defines the
characteristics of a multitasking operating system in which multiple processes shared the
same CPU to perform multiple tasks without the need for additional processors in the
system.
A context switching helps to share a single CPU across all processes to complete its
execution and store the system's tasks status. When the process reloads in the system, the
execution of the process starts at the same point where there is conflicting.
Following are the reasons that describe the need for context switching in the Operating
system.
1. The switching of one process to another process is not directly in the system. A
context switching helps the operating system that switches between the multiple
processes to use the CPU's resource to accomplish its tasks and store its context. We
can resume the service of the process at the same point later. If we do not store the
currently running process's data or context, the stored data may be lost while
switching between processes.
2. If a high priority process falls into the ready queue, the currently running process will
be shut down or stopped by a high priority process to complete its tasks in the
system.
3. If any running process requires I/O resources in the system, the current process will
be switched by another process to use the CPUs. And when the I/O requirement is
met, the old process goes into a ready state to wait for its execution in the CPU.
Context switching stores the state of the process to resume its tasks in an operating
system. Otherwise, the process needs to restart its execution from the initials level.
4. If any interrupts occur while running a process in the operating system, the process
status is saved as registers using context switching. After resolving the interrupts, the
process switches from a wait state to a ready state to resume its execution at the
same point later, where the operating system interrupted occurs.
Suppose that multiple processes are stored in a Process Control Block (PCB). One process is
running state to execute its task with the use of CPUs. As the process is running, another
process arrives in the ready queue, which has a high priority of completing its task using
CPU. Here we used context switching that switches the current process with the new
process requiring the CPU to finish its tasks. While switching the process, a context switch
saves the status of the old process in registers. When the process reloads into the CPU, it
starts the execution of the process when the new process stops the old process. If we do not
save the state of the process, we have to start its execution at the initial level. In this way,
context switching helps the operating system to switch between the processes, store or
reload the process when it requires executing its tasks.