Topics / Operating System Concepts / Q3
What are the states of a process, and how does a process move between them?
Short answer: The textbook states are New → Ready (waiting for a CPU) → Running → Blocked/Waiting (waiting for I/O or an event) → back to Ready, and finally Terminated. The scheduler moves processes between Ready and Running; system calls and interrupts move them to and from Blocked.
admit dispatch
New ──────────► Ready ◄──────────────► Running ──── exit ───► Terminated (zombie)
▲ preempt / │
│ time slice │ wait for I/O, sleep, lock
│ ▼
└──── event done ──── Blocked
Transitions and what causes them
| Transition | Cause |
|---|---|
| Ready → Running | the scheduler picks this process (dispatch) |
| Running → Ready | pre-empted: time slice used up, or a higher-priority task woke up |
| Running → Blocked | it asked for something not yet available: read() on an empty pipe, sleep(), waiting on a mutex |
| Blocked → Ready | the event happened (the interrupt handler or another task wakes it); it does not go straight to Running |
| Running → Terminated | exit() or a fatal signal; it stays a zombie until the parent calls wait() |
Linux state letters (in ps and top)
| Letter | Kernel state | Meaning |
|---|---|---|
R |
TASK_RUNNING |
running or ready (Linux does not separate them) |
S |
TASK_INTERRUPTIBLE |
sleeping, can be woken by a signal |
D |
TASK_UNINTERRUPTIBLE |
sleeping, cannot be interrupted (usually waiting for disk or a driver) |
T |
stopped | SIGSTOP/Ctrl-Z, or traced by a debugger |
Z |
EXIT_ZOMBIE |
exited, waiting to be reaped |
I |
idle kernel thread | – |
Interview follow-ups
- "Why can't you kill a process in
Dstate?" It is waiting inside the kernel in a section that cannot be interrupted safely; a signal is only acted on when it returns. Many processes stuck inDpoint to a hung storage device or a driver bug. - "How does this relate to scheduling?" The scheduler only chooses among Ready tasks; a blocked task uses no CPU time, which is why blocking I/O is efficient and busy-waiting is not.