Operating System - States of a Process



A process in an operating system can undergo various states during its lifecycle in the system. First of all, when you run a program it becomes a process. Then the operating system manages the process by transitioning it through different states based on the availability of resources and the process's requirements.

Different operating systems can have different names for these states or phases, but the fundamental concepts remain similar. Commonly we have three types models to represent the states of a process in an operating system −

Two State Model

In the simplest model, a process can be in running state or not running state.

  • Running State − Indicates that the process is currently being executed by the CPU.
  • Not Running State − Indicates that the process is not currently being executed. It can be in a waiting state or ready state.

This can be visualized as in the diagram below −

Two State Model of Process

The diagram shows that when a new process is created, it is kept in the not running state until the CPU is allocated to it. Once the CPU is allocated, it moves to the running state. Sometime, if the process needs to wait for I/O operations or other resources, it goes back to the not running state.

The dispatcher is a special program that checks if the CPU is free and allocates it to a process from the not running state. Hence, the process of allocating CPU to a process is called dispatching.

Five State Model

The five-state model describes the lifecycle of a process in 5 stages. Here the not running state is further divided into three states - start, ready, and waiting. This can be visualized as in the diagram below −

Five State Model of Process
  • Start State − The start state is where a new process is created and initialized. The process is not yet ready to run.
  • Ready State − In the ready state, the process is ready to run and is waiting for CPU allocation. It has all the necessary resources except the CPU.
  • Running State − The running state indicates that the process is currently being executed by the CPU.
  • Waiting State − The waiting state happens when a process is waiting for something like I/O operations or other resources. The process cannot continue execution until the user inputs data or the required resource becomes available.
  • End State/Terminated State − The end state indicates that the process has completed its execution and is terminated from CPU.

Seven State Model

The seven-state model further breaks down the five states model by adding two additional states suspended ready and suspended blocked. This can be visualized as in the diagram below −

Seven State Model of Process
  • Suspended Ready State − In this state, the process is in the ready state but has been suspended by the operating system. This can happen when the system needs to free up resources for other processes to avoid deadlock.
  • Suspended Blocked State − In this state, the process is in the waiting state but has been suspended by the operating system. This can happen when the process is waiting for a resource that is not available, and the system needs to free up resources for other processes.

Conclusion

A process in an operating system undergoes various states during its lifecycle. The two-state, five-state, and seven-state models provide different levels of detail about the process states. The two state model is the simplest with only running and not running states. The five-state model adds more detail by breaking down the not running state into start, ready, waiting, and end states. The seven-state model further adds suspended ready and suspended blocked states.

Advertisements