Process States in Operating System
What is Process States in Operating System
Process is the execution of a program that performs the actions specified in that program. It can be defined as an execution unit where a program runs. The OS helps you to create, schedule, and terminates the processes which is used by CPU. A process created by the main process is called a child process.
Process operations can be easily controlled with the help of PCB(Process Control Block). You can consider it as the brain of the process, which contains all the crucial information related to processing like process id, priority, state, CPU registers, etc.
What is Process Management ?
Process management involves various tasks like creation, scheduling, termination of processes, and a dead lock. Process is a program that is under execution, which is an important part of modern-day operating systems. The OS must allocate resources that enable processes to share and exchange information. It also protects the resources of each process from other methods and allows synchronization among processes. It is the job of OS to manage all the running processes of the system. It handles operations by performing tasks like process scheduling and such as resource allocation.
Process memory is divided into four sections for efficient working. Below is the architecture diagram of Process.
- Stack: The Stack stores temporary data like function parameters, returns addresses, and local variables. The Stack is used for local variables. Space on the stack is reserved for local variables when they are declared.
- Heap: Allocates memory, which may be processed during its run time. The Heap is used for the dynamic memory allocation and is managed via calls to new, delete, malloc, free, etc.
- Data: It contains the variable. The Data section is made up of the global and static variables, allocated and initialized prior to executing the main.
- Text: Text Section includes the current activity, which is represented by the value of the Program Counter. The Text section is made up of the compiled program code, read in from non-volatile storage when the program is launched.
States of a Process
During the execution of a process, it undergoes a number of states. So, in this section of the blog, we will learn various states of a process during its lifecycle.
- New State: This is the state when the process is just created. It is the first state of a process.
- Ready State : After the creation of the process, when the process is ready for its execution then it goes in the ready state. In a ready state, the process is ready for its execution by the CPU but it is waiting for its turn to come. There can be more than one process in the ready state.
- State : After the creation of the process, when the process is ready for its execution then it goes in the ready state. In a ready state, the process is ready for its execution by the CPU but it is waiting for its turn to come. There can be more than one process in the ready state.
- Ready Suspended State : There can be more than one process in the ready state but due to memory constraint, if the memory is full then some process from the ready state gets placed in the ready suspended state.
- Running State : Amongst the process present in the ready state, the CPU chooses one process amongst them by using some CPU scheduling algorithm. The process will now be executed by the CPU and it is in the running state.
- Waiting or Blocked State : During the execution of the process, the process might require some I/O operation like writing on file or some more priority process might come. In these situations, the running process will have to go into the waiting or blocked state and the other process will come for its execution. So, the process is waiting for something in the waiting state.
- Waiting Suspended State : When the waiting queue of the system becomes full then some of the processes will be sent to the waiting suspended state.
- Terminated State : After the complete execution of the process, the process comes into the terminated state and the information related to this process is deleted.
In the above image, you can see that when a process is created then it goes into the new state. After the new state, it goes into the ready state. If the ready queue is full, then the process will be shifted to the ready suspended state. From the ready sate, the CPU will choose the process and the process will be executed by the CPU and will be in the running state. During the execution of the process, the process may need some I/O operation to perform. So, it has to go into the waiting state and if the waiting state is full then it will be sent to the waiting suspended state. From the waiting state, the process can go to the ready state after performing I/O operations. From the waiting suspended state, the process can go to waiting or ready suspended state. At last, after the complete execution of the process, the process will go to the terminated state and the information of the process will be deleted. This is the whole life cycle of a process.