๐ง What are Process States?
A process goes through several states in its life cycle โ from creation to termination โ depending on what itโs doing (waiting, running, blocked, etc.).
The OS maintains and switches these states via a Process Control Block (PCB).
๐ Common Process States (Modern OSes)
Hereโs a simplified 5-state model that covers almost everything FAANG interviews care about:
1. New
-
Process is being created.
-
OS is allocating memory, setting up PCB, etc.
2. Ready
-
Process is loaded into memory and waiting to be scheduled on the CPU.
-
Itโs ready to run but not yet running.
3. Running
-
Process is currently executing on the CPU.
-
Only one process per core can be in this state at any time.
4. Blocked / Waiting
-
Process is waiting for I/O (e.g., disk, network, user input).
-
It cannot run until the I/O completes.
5. Terminated / Exit
-
Process has completed execution or was killed.
-
OS cleans up its memory, I/O, and PCB.
๐ Process State Diagram
+---------+
| New |
+----+----+
โ
+----v----+
| Ready |<----------------------+
+----+----+ |
โ |
+----v----+ I/O complete |
| Running |------------------>+ |
+----+----+ | |
โ I/O request | |
+----v----+ | |
| Blocked |-------------------+ |
+----+----+ |
โ |
+----v----+ |
| Terminated |<------------------+
+-----------+
๐ง Key Transitions Explained
| Transition | Trigger |
|---|---|
| New โ Ready | Process is admitted into memory |
| Ready โ Running | CPU scheduler picks the process |
| Running โ Blocked | Process makes an I/O request |
| Blocked โ Ready | I/O completes |
| Running โ Ready | Time slice expires (preemption) |
| Running โ Terminated | Process exits or is killed |
๐ฆ Modern OS Enhancements (for depth)
| Additional State | Meaning |
|---|---|
| Suspended | Process is swapped out of memory (still in disk) |
| Zombie | Process finished execution, but parent hasnโt read its exit status |
| Orphan | Child process whose parent died (handled by init in Linux) |
These are mostly edge cases, but can be useful in interviews if pushed deeper.
๐ง Interview-Ready One-Liner:
A process transitions through several states โ New, Ready, Running, Blocked, and Terminated โ based on its interaction with the CPU, memory, and I/O. The OS uses these states to schedule and manage processes efficiently.