💡 I assume, you have read the previous two articles of this series before you start because I have used some of the jargon I explained in them frequently.
For sake of simplicity, assume we have only 1 CPU in a multiprogramming( preemptive or non-preemptive doesn't matter ) environment.
Whenever I use the term memory, I mean main memory or RAM until unless specified.
Need for PCB
In the previous article, we saw a program is a passive entity while a process is an active entity. Simply putting, the process is your program in execution.
It's the job of OS to dynamically assign CPU to the process which requires it because processes don't need CPU all the time, a good example might be when they go for I/O.
The question is how do you(as an OS) identify which process is which? I mean to say, there are dozens of processes that can exist at the same time in your system. For example, there can be an MS-Word process, pdf reader process, the browser process, and of course, the background processes all existing at the same time. Moreover, sometimes a process needs to be pulled out of the main memory for some other important process say, the task manager process in windows.
This is the reason, we need an identification card for every process that is created. And that identification card is what we call a Process Control Block(PCB).
💡 Commonly, PCB is also referred to as Context (of a process)
What is a PCB?
Whenever a process is created, OS also creates a data structure(a record) that contains important information about a process. This is called PCB.
Every process that comes into existence has a corresponding context or PCB associated with it. These PCBs are stored in the memory reserved for the operating system.
You can think of it as a dictionary having various keys(attribute or information name) and values(the information itself!).
Important Attributes or fields in a PCB
Process ID: A unique identification number for every process.
Program Counter: Address of the next instruction that is to be executed.
Process State: It contains the current state of the process. A process goes under various states like ready, running, wait, etc. throughout its execution. (Topic for next post)
Priority: A number specifying the importance of this process. (I will come to this when we discuss scheduling algorithms)
-
General Purpose Registers: It contains information about CPU registers used by the process.
- When a process is executing, data about it is stored in these so-called registers. When a process is preempted by OS to schedule some other process, this new process will override the old data present in these registers.
- Thus when our old process is scheduled again, we need its register information.
List of open files: It is self-explanatory; contains information about files that are opened by this process.
List of open devices: Again self-explanatory; contains information about opened devices say, printer.
And the list goes on...
I think you should appreciate the fact that OS exists otherwise just imagine doing process management manually!!
How are PCBs stored
These PCBs are organized in the form of LinkedList in the memory.
Summary
- PCBs are important data structures created by OS for controlling the execution of a process.
- Every process has a corresponding PCB associated with it.
- Also known as Context.
- Created in memory reserved for the operating system.
Top comments (0)