๐Ÿง  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

TransitionTrigger
New โ†’ ReadyProcess is admitted into memory
Ready โ†’ RunningCPU scheduler picks the process
Running โ†’ BlockedProcess makes an I/O request
Blocked โ†’ ReadyI/O completes
Running โ†’ ReadyTime slice expires (preemption)
Running โ†’ TerminatedProcess exits or is killed

๐Ÿ“ฆ Modern OS Enhancements (for depth)

Additional StateMeaning
SuspendedProcess is swapped out of memory (still in disk)
ZombieProcess finished execution, but parent hasnโ€™t read its exit status
OrphanChild 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.