
It's finally here:
>> The Road to Membership and Baeldung Pro.
Going into ads, no-ads reading, and bit about how Baeldung works if you're curious :)
Last updated: March 18, 2024
A computer system executes multiple programs simultaneously. This lets us achieve better throughput and user experience. The notion of running multiple programs is implemented by a process in the operating system.
In this tutorial, we’ll discuss the concept of a process control block (PCB), which contains useful information for a process to function.
A process is a program in execution. For instance, we can write a Java application and save it to the disk. This is considered a program and a passive entity. However, when we execute the program, the operating system creates a Java process. A process is an active entity while it’s under execution.
The preceding image represents a process with its components. On the left-hand side, we are displaying the memory – the text section starts from the lower memory offset. The heap and the stack section of the process can grow based on the memory requirement of the process.
The process control block represents a process in the operating system. A PCB is also known as a task control block. It’s a repository of information associated with a specific process.
It contains various pieces of information like:
The process state represents the state of the process in the operating system. A process can be in either of new, ready, running, waiting, or terminated status.
A process contains several instructions which are executed linearly by the CPU. A program counter (PC) indicates the address of the next instruction to be executed for this process.
A register is a tiny bit of memory which can contain state information of a process. Registers can vary in their size and type based on the computer architecture. They include accumulators, index registers, condition-code information, general-purpose registers, and stack pointers, to name a few.
A CPU register stores the state information of a process if interruptions occur in the running process. This allows the process to continue when the scheduler schedules it to run again.
A PCB plays a crucial role in the context switch of a process.
Sometimes, several factors such as interrupt signals or operating system calls interrupt a running process, and the process preempts its execution. When this happens, the operating system saves the current execution statistics in the PCB of the process. This ensures that the process execution resumes next time.
Let’s take a look at what happens during a context switch:
Let’s break this down:
In this article, we discussed the process control block of a process.
First, we introduced the concept of a process and the role of PCB in managing a process state in the operating system. Then, we talked about various components of a process control block and their roles.
Finally, we discussed the role of a process control block in the process context switch.