Process States and Transitions
Scenario
Imagine a busy restaurant kitchen. An order comes in, waits to be prepped, is actively cooked, might be paused while waiting for a missing ingredient, and finally is served. Processes in an operating system follow an identical lifecycle.
Mental model
A process's lifecycle is like a patient's journey through a hospital.
A patient is admitted (New), waits in the waiting room (Ready), sees the doctor (Running), might wait for lab results (Blocked/Waiting), and finally is discharged (Terminated).
Explanation
When you double-click an application, the operating system doesn't just hand it the CPU and walk away. Instead, the OS manages the process through a strict lifecycle of discrete states, ensuring fair access to system resources. This lifecycle dictates exactly what a process is allowed to do at any given moment.
The most fundamental distinction in this lifecycle is whether a process is actually executing instructions on the CPU or waiting for its turn. But 'waiting' isn't a single state. A process can be waiting because it's ready to execute but the CPU is busy with another program, or it can be waiting because it's fundamentally stuck until some external event (like an I/O operation or network response) finishes. This distinction is the core of process scheduling.
Every process starts in the **New** state, where the OS allocates its memory and creates its Process Control Block (PCB). Once initialization is complete, it is moved to the **Ready** state. At this point, the process is fully prepared to execute; it's simply waiting in a queue for the OS scheduler to assign it a CPU core.
When the scheduler picks the process, it transitions from Ready to **Running**. This is the only state where the process's actual instructions are being executed by the CPU hardware. However, a process rarely runs to completion uninterrupted. If its time-slice expires, the OS forcefully moves it back to the **Ready** state to let another process run.
If the running process needs to read from disk or wait for user input, it transitions to the **Blocked** (or Waiting) state. It cannot execute instructions while blocked, even if the CPU is completely idle. Once the disk read or user input completes, the hardware sends an interrupt to the OS, which moves the process from Blocked back to Ready. Finally, when the process finishes its last instruction or is killed, it enters the **Terminated** state, allowing the OS to reclaim its resources.
Key points
- New: The process is being created and initialized by the OS.
- Ready: The process is waiting to be assigned to a processor. It has all the resources it needs except the CPU.
- Running: Instructions are being actively executed on the CPU.
- Blocked (Waiting): The process is waiting for some event to occur (e.g., I/O completion) and cannot run even if given the CPU.
- Terminated: The process has finished execution and is awaiting resource cleanup.
Common mistakes
- Confusing Blocked and Ready states: Many think both mean 'waiting for the CPU'. Ready means the process CAN execute right now if a CPU is free. Blocked means the process CANNOT execute, even if a CPU is free, because it is waiting on an external event like I/O.
- Assuming processes go directly from Blocked to Running: When an I/O operation finishes, the OS does not immediately inject the blocked process back into the CPU. Instead, it moves it to the Ready queue to wait its fair turn.
Glossary
- process
- The technical term for a software program that is currently loaded into memory and actively running on your computer.
- lifecycle
- The strict series of stages (like New, Ready, Running, and Terminated) that every running program must cycle through from the moment it opens until it closes.
- system resources
- The finite hardware components of a computer, like the CPU time, RAM memory, and disk storage, that programs must share.
Recall questions
- What is the difference between the Ready and Blocked states?
- What transition occurs when a running process issues an I/O request?
- Can a process transition directly from Blocked to Running?
Questions & answers
A process has just completed its I/O operation. Which state does it enter next?
Ready state.
Approach: Remember the process lifecycle diagram: I/O completion triggers an interrupt that moves the process from Blocked/Waiting into the Ready queue, not directly to Running.
If a CPU has multiple cores, can a single process be in the Running state on multiple cores simultaneously?
No, a single process (assuming a single-threaded context) can only execute on one core at a time. Threads within a process can run on multiple cores.
Approach: Clarify the distinction between a process (an execution environment) and a thread (an execution unit). A standard single-threaded process executes one instruction stream at a time.
Continue learning
Previous: Process vs program & the PCB
Next: Context Switching