For each process, the operating system maintains the data structure, which keeps the complete information about that process. This record or data structure is called Process Control Block (PCB).
Whenever a user creates a process, the operating system creates the corresponding PCB for that process. These PCBs of the processes are stored in the memory that is reserved for the operating system.
The process control block has many fields that store the relative information about that process as you can see in the above figure. PCB contains Process-Id, Process State, Process Priority, Accounting Information, Program Counter, and also some other information which helps in controlling the operations of the process.
Here we will discuss the Process Control Block and its fields. So let us start.
Whenever a new process is created by the user, the operating system allots a number to that process. This number becomes the unique identification of that process and it also helps in distinguishing that process from all other processes existing in the system. This number is also called as process-id of the process.
As we know, the operating system sets a limit on the maximum number of the processes it can deal with at a time. So, let us suppose that there are n number of the processes in the system. Now, the process-id will take on the values between 0 to n-1.
The operating system will allocate the value 0 to the first process that arrives in the system, number 1 to the next process and continues till n-1. At this point when the n-1 value is allocated to some process, and a new process arrives, the operating system wraps around and allocates value 0 to the newly arrived process. Considering that the process with process-id 0, would have terminated.
Process-ids are not necessarily allocated in the ascending fashion. There is also another scheme to generated process-ids. Let us suppose, a PCB of a process requires x number of bytes and there are n number of processes in the system.
So, the operating system will reserve nx number of bytes for all the PCBs. And number the PCBs from 0 to n-1. Now, when a process is created a fee PCB slot is allocated to that process and the PCB number itself becomes the process-id of the process.
In this case, the operating system has to maintain the chain of free PCBs. If the chain is empty no new process will get created.
A process in its lifetime undergoes different states. Like, a process may be in waiting state, running state, ready state, blocked state, halted state, and so on.
The PCBs field, process state holds the current state of the respective process. For example, if the process is currently executing. So, the process state will hold the running state for that process.
The information in the process state field is kept in the codified fashion.
The priority of the process is a numeric value, lesser the value, greater is the priority of that process. The priority of the process can be assigned externally by the user or by the operating system itself.
The process is assigned the priority at the time of its creation. The priority of the process may get changed over its lifetime depending on the various parameter. The parameters for changing the priority of the process can be the age of that process, the resources it consumed and so on.
Process Accounting Information
This field of PCB gives the account/description of the resources used by that process. Like, the amount of CPU time, real-time used, connect time.
The program counter is the pointer to an instruction in the program or code that is to be executed next. This field contains the address of the instruction that will be executed next in the process.
List of Open Files
As you can see, this field is self-explanatory. It contains the information of all the files that is required by the program during its execution.
This information is also useful for the operating system. Because it helps the operating system to close the all opened files which are not closed explicitly at the termination of the program.
Process I/O status Information
Sometimes the process executing in the system require I/o devices. So, this field of PCB contains the list of all the I/O devices allocated to the process during its execution.
Whenever an interrupt occurs and there is a context switch between the processes, the temporary information is stored in the registers. So, that when the process resumes the execution it correctly gains from where it leaves. CPU registers are used to hold those temporary values or information.
In this field, the pointer has an address of the next PCB, whose process state is ready. In this way, the operating system maintains the hierarchy of all the processes so that a parent process could locate all the child processes it creates easily.
This field contains the information of the event for which the certain process is in block state. Whenever that event occurs the operating system identifies the process awaiting for this event using this field. If the event occurred match with this field the process changes its state from blocked to ready.
So these are the fields of PCBs which contains much information that is associated with the specific process.
- Process Control Block is a data structure that is maintained by the operating system.
- PCB maintains the specific information, about the process, which is helpful while its execution.
- As soon as the process is created it is the responsibility of the operating system to create a respective process control block for it.
- After a process terminates its corresponding PCB is also removed from the system.
- PCB contains many fields like process-id, process state, program counter, process priority, etc. these fields helps in controlling the operations of the corresponding process.
In short, we can state that the Process Control Block is an essential structure that the operating system maintains for controlling the execution of the process.