Bird
Raised Fist0
Interview Prepoperating-systemseasyAmazonGoogleMicrosoftFlipkart

Process State Machine - Five-State Model

Choose your preparation mode3 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
🎯
Process State Machine - Five-State Model
easyOSAmazonGoogleMicrosoft

Imagine a busy restaurant kitchen where orders (processes) move through different stages - waiting, cooking, serving - similar to how a process moves through states in an operating system.

💡 Beginners often confuse process states with threads or think a process is either running or not, missing the nuanced intermediate states and transitions that help the OS manage multitasking efficiently.
📋
Interview Question

Explain the five-state process state machine model in operating systems and describe the transitions between these states.

Process states: New, Ready, Running, Waiting, TerminatedState transitions triggered by events like scheduling, I/O, or terminationRole of the Process Control Block (PCB) in managing state information
💡
Scenario & Trace
ScenarioA user launches a text editor application on their computer.
1. The OS creates a new process in the New state. 2. The process moves to Ready state, waiting for CPU allocation. 3. Scheduler picks the process; it transitions to Running state. 4. The process requests to load a file, causing an I/O wait; it moves to Waiting state. 5. After I/O completes, it returns to Ready state. 6. Scheduler runs it again (Running). 7. User closes the editor; process transitions to Terminated state.
  • What happens if a process in Waiting state never receives the I/O completion signal?
  • How does the OS handle a process that is preempted while Running?
  • What if multiple processes are in Ready state simultaneously?
⚠️
Common Mistakes
Confusing process states with thread states

Interviewer doubts your understanding of process vs thread abstractions.

Clarify that process states represent the lifecycle of an independent program instance, while threads are subdivisions within a process.

Assuming a process is either Running or Terminated only

Shows lack of knowledge about intermediate states and multitasking.

Explain all five states and their significance in multitasking OS.

Not mentioning the role of the PCB in state transitions

Interviewer perceives incomplete understanding of OS internals.

Include how PCB stores process context during state changes.

Ignoring what triggers transitions between states

Answers sound superficial and incomplete.

Describe events like I/O requests, scheduler decisions, and termination signals that cause transitions.

🧠
Basic Definition - What It Is
💡 This level covers the essential vocabulary and basic flow of process states, enough to answer simple interview questions.

Intuition

A process moves through five distinct states as it executes, reflecting its current activity and readiness for CPU time.

Explanation

The five-state model describes how an operating system manages processes by categorizing them into New, Ready, Running, Waiting, and Terminated states. A process starts in the New state when created, moves to Ready when prepared to run, transitions to Running when executing on the CPU, shifts to Waiting if it needs to wait for an event like I/O, and finally reaches Terminated when execution completes. This model helps the OS efficiently schedule and manage multiple processes.

Memory Hook

💡 Think of a traffic light system for processes: New (red light preparing), Ready (yellow light waiting), Running (green light go), Waiting (red light stop for event), Terminated (off the road).

Interview Questions

What are the five states in the process state machine?
  • New
  • Ready
  • Running
  • Waiting
  • Terminated
What state is a process in when it is waiting for I/O?
  • Waiting state
Depth Level
Interview Time30 seconds
Depthbasic

Covers naming and simple understanding of states and their purpose.

Interview Target: Minimum floor - never go below this

Knowing only this will help you pass initial screening but is insufficient for deeper technical rounds.

🧠
Mechanism Depth - How It Works
💡 This level explains the triggers and conditions for state transitions and the OS mechanisms involved, expected in product company interviews.

Intuition

Processes transition between states based on system events and scheduler decisions, with the PCB tracking state and context for smooth switching.

Explanation

The five-state process model is dynamic, with transitions triggered by events such as process creation, CPU scheduling, I/O requests, and termination. When a process is created, it enters the New state and is initialized. Once ready, it moves to Ready, where it waits in a queue for CPU allocation. The scheduler selects a Ready process to run, moving it to Running. If the process requires I/O or another event, it transitions to Waiting, suspending execution until the event completes. Upon completion, it returns to Ready. If the process finishes execution or is killed, it moves to Terminated. The OS uses the Process Control Block (PCB) to save the process state during context switches, enabling resumption without loss of data or execution flow.

Memory Hook

💡 Imagine a relay race where runners (processes) pass the baton (CPU) - waiting on the sidelines (Ready), running the race (Running), pausing for water (Waiting), and finishing the race (Terminated).

Interview Questions

What causes a process to move from Running to Waiting?
  • Process requests I/O or waits for an event
  • CPU is released
  • Process state saved in PCB
How does the OS handle multiple processes in Ready state?
  • Scheduler queues processes
  • Selects one based on scheduling algorithm
  • Others remain in Ready
What happens during a context switch?
  • Save current process state in PCB
  • Load next process state from PCB
  • Update CPU registers
Depth Level
Interview Time2-3 minutes
Depthintermediate

Demonstrates understanding of process lifecycle management and OS internals.

Interview Target: Target level for FAANG on-sites

Mastering this level distinguishes you from most candidates and shows readiness for system design and OS questions.

📊
Explanation Depth Levels
💡 Choose your explanation depth based on interview stage and company expectations.
LevelInterview TimeSuitable ForRisk
Basic Definition30sScreening call or initial HR roundToo shallow for technical on-site interviews
Mechanism Depth2-3 minutesTechnical phone screens and on-site interviews at product companiesRequires good understanding; missing details may lower score
💼
Interview Strategy
💡 Use this guide to structure your explanation clearly and confidently before every OS mock interview.

How to Present

Start with a concise definition of the five process states.Provide a relatable example or analogy to illustrate the states.Explain the triggers and transitions between states in detail.Discuss common edge cases and how the OS handles them.

Time Allocation

Definition: 30s → Example: 1min → Mechanism: 2min → Edge cases: 30s. Total ~4min

What the Interviewer Tests

Interviewer checks your clarity on process lifecycle, ability to explain state transitions, and understanding of OS scheduling and context switching.

Common Follow-ups

  • What happens if a process in Waiting state never receives the event it waits for? → It may lead to indefinite blocking or deadlock.
  • How does preemption affect the Running state? → The process is moved back to Ready, and its state saved.
💡 These follow-ups test your grasp of process management robustness and OS fairness.
🔍
Pattern Recognition

When to Use

Asked when discussing process management, multitasking, or OS scheduling concepts.

Signature Phrases

Explain the five states of a processWhat happens when a process requests I/O?Compare Ready vs Waiting states

NOT This Pattern When

Similar Problems

Practice

(1/5)
1. Consider a producer-consumer system using semaphores: when a producer produces an item, what is the correct sequence of semaphore operations to ensure proper synchronization?
easy
A. Wait on 'empty' semaphore, wait on mutex, add item, signal mutex, signal 'full' semaphore
B. Wait on mutex, wait on 'empty' semaphore, add item, signal 'full' semaphore, signal mutex
C. Wait on 'full' semaphore, wait on mutex, add item, signal mutex, signal 'empty' semaphore
D. Signal 'empty' semaphore, wait on mutex, add item, signal 'full' semaphore, wait on 'full' semaphore

Solution

  1. Step 1: Understand semaphore roles

    'empty' counts available buffer slots; 'full' counts filled slots; mutex protects buffer access.
  2. Step 2: Producer must wait for empty slot

    Producer waits (P operation) on 'empty' to ensure space is available before producing.
  3. Step 3: Acquire mutex before modifying buffer

    Mutex wait ensures exclusive access to buffer.
  4. Step 4: Add item, then release mutex

    After adding, signal (V operation) mutex to release critical section.
  5. Step 5: Signal 'full' to indicate new item

    Signaling 'full' wakes consumers waiting for items.
  6. Step 6: Why other options fail

    Wait on 'full' semaphore, wait on mutex, add item, signal mutex, signal 'empty' semaphore waits on 'full' which is incorrect; Wait on mutex, wait on 'empty' semaphore, add item, signal 'full' semaphore, signal mutex waits on mutex before 'empty' which can cause deadlock; Signal 'empty' semaphore, wait on mutex, add item, signal 'full' semaphore, wait on 'full' semaphore signals before waiting, breaking synchronization.
  7. Final Answer:

    Option A -> Option A
  8. Quick Check:

    Wait empty -> wait mutex -> produce -> signal mutex -> signal full [OK]
Hint: Producer waits on empty, consumer waits on full
Common Mistakes:
  • Confusing 'full' and 'empty' semaphore roles
  • Incorrect order of mutex and semaphore waits
  • Signaling before waiting causing race
2. What is a key limitation of the Banker's Algorithm that affects its practical use in modern operating systems?
medium
A. It requires processes to declare their maximum resource needs in advance, which is often impractical.
B. It can only handle a single resource type, limiting its applicability.
C. It always leads to deadlocks if the system is heavily loaded.
D. It preempts resources from processes, causing starvation.

Solution

  1. Step 1: Identify Banker's Algorithm assumptions

    The algorithm requires prior knowledge of maximum resource needs for each process.
  2. Step 2: Analyze limitations

    This requirement is often unrealistic in dynamic or unpredictable environments.
  3. Step 3: Evaluate other options

    B is false; Banker's Algorithm handles multiple resource types.
    C is false; it avoids deadlocks rather than causing them.
    D is false; it does not preempt resources.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Pre-declaration of max needs is the main practical limitation.
Hint: Banker's Algorithm needs max resource claims upfront [OK]
Common Mistakes:
  • Thinking it only supports one resource type
  • Believing it causes deadlocks under load
  • Confusing it with preemptive algorithms
3. Which of the following statements best explains why SSTF can lead to starvation, and why SCAN or C-SCAN are preferred in heavy-load scenarios?
medium
A. SSTF picks the closest request, potentially ignoring far requests indefinitely; SCAN and C-SCAN guarantee servicing all requests by sweeping the disk head across all tracks.
B. SSTF always services requests in arrival order, causing long waits for distant requests; SCAN and C-SCAN service requests in a fixed direction to prevent this.
C. SSTF has higher overhead due to sorting requests; SCAN and C-SCAN have lower overhead and thus better performance under load.
D. SSTF requires knowledge of all requests upfront; SCAN and C-SCAN can operate with partial knowledge, making them more scalable.

Solution

  1. Step 1: Understand SSTF starvation

    SSTF always picks the nearest request, so requests far from the current head position may wait indefinitely.
  2. Step 2: SCAN and C-SCAN fairness

    They move the head in a fixed direction, servicing all requests in order, ensuring no starvation.
  3. Step 3: Evaluate other options

    Options B, C, and D contain incorrect claims: SSTF does not service requests in arrival order; it does not have higher overhead due to sorting; and it requires knowledge of all requests upfront similarly to SCAN and C-SCAN.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    SSTF picks the closest request, potentially ignoring far requests indefinitely; SCAN and C-SCAN guarantee servicing all requests by sweeping the disk head across all tracks. correctly explains starvation and fairness trade-offs.
Hint: SSTF starves distant requests; SCAN/C-SCAN sweep all tracks fairly
Common Mistakes:
  • Confusing SSTF with FCFS regarding request order
  • Assuming SSTF has higher computational overhead
  • Believing SCAN/C-SCAN require less request knowledge
4. Which of the following statements about memory compaction is INCORRECT?
medium
A. Compaction can be performed without halting all running processes
B. Compaction does not affect internal fragmentation
C. Compaction requires additional CPU overhead and may cause temporary performance degradation
D. Compaction reduces external fragmentation by relocating allocated memory blocks

Solution

  1. Step 1: Understand compaction process

    Compaction moves allocated blocks to create contiguous free memory, reducing external fragmentation (A correct).
  2. Step 2: Analyze process halting

    Compaction usually requires pausing processes to safely move memory (D incorrect).
  3. Step 3: Consider overhead and fragmentation

    Compaction adds CPU overhead and can degrade performance temporarily (C correct); it does not affect internal fragmentation (B correct).
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Compaction generally requires halting processes [OK]
Hint: Compaction = pause + move blocks -> reduce external fragmentation [OK]
Common Mistakes:
  • Assuming compaction is transparent to running processes
  • Confusing internal and external fragmentation effects
  • Underestimating compaction overhead
5. Which of the following statements about non-preemptive SJF scheduling is INCORRECT?
medium
A. Once a process starts executing, it cannot be preempted until completion
B. It selects the process with the shortest burst time from the ready queue when CPU is free
C. It can lead to longer average waiting time compared to preemptive SJF
D. It guarantees no starvation of any process

Solution

  1. Step 1: Understand starvation in non-preemptive SJF

    Non-preemptive SJF can cause starvation if short jobs keep arriving, delaying longer jobs indefinitely.
  2. Step 2: Analyze other options

    A: Correct, non-preemptive means no interruption once started.
    B: Incorrect, non-preemptive SJF does not guarantee no starvation.
    C: Correct, it can lead to longer average waiting time compared to preemptive SJF.
    D: Correct, selection is based on shortest burst time when CPU is free.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Non-preemptive SJF does not guarantee no starvation; starvation can occur.
Hint: Non-preemptive SJF can starve long processes if short ones keep arriving [OK]
Common Mistakes:
  • Assuming non-preemptive SJF prevents starvation
  • Confusing preemptive and non-preemptive behavior