Explain process state model with diagram.
Process state
- The process state indicates the current activity of the process.
- As a process executes, it changes its state.
- The state of a process is defined by the current activity of that process.
- A process goes through a series of distinct process states.
- A process goes through basically 3 states.
- Running (actually using the CPU at that time and running).
- Ready (runnable; temporarily stopped to allow another process run).
- Blocked (unable to run until some external event happens).
- Logically, the first two states are similar. In both cases the process is willing to run, only in the second one temporarily there is no CPU available for it.
- In blocked state, the process cannot run even if the CPU is available to it as the process is waiting for some external event to take place.
- There four possible transitions between these three states.
- Transition 1 occurs when the operating system discovers that a process cannot continue right now due to unavailability of input. In other systems including UNIX, when a process reads from a pipe or special file (e.g. terminal) and there is no input available, the process is automatically blocked.
- Transition 2 and 3 are caused by the process scheduler (a part of the operating system), without the process even knowing about them.
- Transition 2 occurs when the scheduler decides that the running process has run long enough, and it is time to let another process have some CPU time.
- Transition 3 occurs when all the other processes have had their fair share and it is time for the first process to get the CPU to run again. The subject of scheduling, that is, deciding which process should run when and for how long, is an important one.
- Transition 4 occurs when the external event for which a process was waiting (such as the arrival of some input) happens. If no other process is running at that time, transition 3 will be triggered and the process will start running. Otherwise it may have to wait in ready state for a little time until the CPU is available and its turn comes.