A process is essentially a running program. The execution of a process must proceed in a logical order.
There may be several processes in the system that demand the same resource at the same time. As a result, the operating system must handle all operations and resources in a convenient and efficient manner.
The operating system is in charge of Process Management, which also includes the allocation and de-allocation of resources to processes.
Process Deep Dive
When a program is put into memory and becomes a process, it is divided into four parts: stack, heap, text, and data.
Learn more about the memory layout of a program.
The Operating System uses the process attributes to generate the process control block (PCB) for each of them. This is also known as the process context. The next sections discuss the attributes that are saved on the PCB:
- Process ID: When a process is created, a unique id is issued to it, which is used for the process’s unique identification throughout the system.
- Program Counter: A programme counter maintains the address of the process’s last instruction before it was interrupted. When the execution of this process is resumed, the CPU utilises this address.
- Process State: From process’s beginning until its termination, the Process passes through several phases, including new, ready, operating, and waiting. The PCB also records the process’s state, which allows the CPU to resume the operation from where it was paused.
- Priority: Each process has its own priority. Among the processes, the one with the highest priority receives the CPU first. This data is likewise saved on the process control block.
- General Purpose Registers: Each process has its own set of registers that are used to store data created during the process’s execution.
- List of open files: During execution, each process makes use of files that must be present in main memory. The OS also keeps a list of open files on the PCB.
- List of open devices: The operating system also keeps a list of all open devices that are used throughout the process’s execution.
From start to finish, the process goes through several stages:
- New: A new process is a programme that will be loaded into main memory by the operating system.
- Ready: Ready state processes are processes that are ready for execution and exist in main memory. Many processes may be present in the ready stage.
- Running:A process that is executing on the CPU is referred to as being in the running stage.
- Block or Waiting: The CPU can also preempt a process based on the scheduling algorithm in use, and the process can be moved from the running to the blocked or waiting state. A process also preempts when they require to perform I/O operations.
- Completion or Termination: When a process has completed its execution, it enters the termination state. The process’s context (Process Control Block) will likewise be removed, and the process will be terminated by the operating system.
- Suspended ready: A process in the ready state that is transferred to secondary memory from main memory due to a shortage of resources (mostly primary memory) is referred to as being in the suspend ready state.
- Suspended wait: Rather than removing the process from the ready queue, it is preferable to delete the blocked process that is waiting for resources in main memory and thus is in suspended waiting stage.