Bird
Raised Fist0
Interview Prepoperating-systemseasyAmazonGoogleMicrosoftFlipkart

Process State Machine - Five-State Model

Choose your preparation mode3 modes available
🎯
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. Trace the sequence of events when a user program invokes a system call to read a file. Which step happens immediately after the CPU switches to kernel mode?
easy
A. The kernel verifies the system call number and arguments
B. The hardware raises an interrupt to the device
C. The user program resumes execution in user mode
D. The kernel copies data directly to the user buffer without validation

Solution

  1. Step 1: User program issues system call

    The user program executes a special instruction causing a trap to kernel mode.
  2. Step 2: CPU switches to kernel mode

    Control transfers to the OS kernel with elevated privileges.
  3. Step 3: Kernel validates system call

    The kernel inspects the system call number and arguments to ensure they are valid and safe.
  4. Step 4: Why other options are incorrect

    The kernel copies data directly to the user buffer without validation is unsafe; kernel must validate before copying data. The user program resumes execution in user mode happens after system call completion, not immediately after mode switch. The hardware raises an interrupt to the device is unrelated here; hardware interrupts occur asynchronously, not immediately after mode switch.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    System call trap -> kernel mode -> validate call -> execute service [OK]
Hint: Kernel validates system call immediately after mode switch
Common Mistakes:
  • Assuming kernel copies data before validation
  • Confusing interrupt handling with system call flow
  • Thinking user mode resumes immediately after trap
2. Which trade-off is a key limitation of using a global waiter (arbitrator) to prevent deadlock in the Dining Philosophers problem?
medium
A. It simplifies resource allocation but introduces a single point of failure and potential bottleneck
B. It increases concurrency but risks livelock under high contention
C. It eliminates deadlock but can cause starvation due to unfair scheduling
D. It guarantees fairness but requires complex priority inheritance mechanisms

Solution

  1. Step 1: Understand the global waiter approach

    A global waiter serializes fork acquisition requests to prevent circular wait.
  2. Step 2: Analyze trade-offs

    This centralization simplifies deadlock prevention but creates a single point of failure and can bottleneck performance.
  3. Step 3: Evaluate other options

    It increases concurrency but risks livelock under high contention is incorrect as concurrency is reduced; It eliminates deadlock but can cause starvation due to unfair scheduling is incorrect because starvation is not guaranteed; It guarantees fairness but requires complex priority inheritance mechanisms is incorrect as priority inheritance is unrelated here.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Centralized control trades deadlock prevention for potential bottleneck and failure risk.
Hint: Global waiter = deadlock-free but centralized bottleneck [OK]
Common Mistakes:
  • Confusing starvation with deadlock prevention
  • Assuming increased concurrency with global waiter
  • Misattributing priority inheritance to this solution
3. Which of the following statements about the C-SCAN disk scheduling algorithm is INCORRECT?
medium
A. C-SCAN services requests in one direction only and jumps back to the beginning without servicing requests on the return trip.
B. C-SCAN eliminates starvation by always servicing the closest request next.
C. C-SCAN can cause longer average seek times than SSTF because it ignores the closest requests on the return path.
D. C-SCAN provides a more uniform wait time compared to SCAN by treating the disk as a circular list.

Solution

  1. Step 1: Review C-SCAN behavior

    C-SCAN moves the head in one direction, servicing requests, then jumps back to the start without servicing requests on the return.
  2. Step 2: Understand fairness and wait times

    This approach provides uniform wait times and avoids starvation.
  3. Step 3: Analyze each option

    C-SCAN eliminates starvation by always servicing the closest request next. is incorrect because C-SCAN does not always service the closest request next; it ignores requests on the return jump.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    C-SCAN eliminates starvation by always servicing the closest request next. is the only incorrect statement about C-SCAN.
Hint: C-SCAN jumps back without servicing requests, so closest next request isn't guaranteed
Common Mistakes:
  • Assuming C-SCAN always picks the closest request next
  • Confusing C-SCAN with SCAN regarding servicing on return
  • Believing C-SCAN causes starvation
4. Why is aging used as a technique to prevent starvation, and what is a potential downside of applying aging aggressively?
medium
A. Aging increases priority of waiting processes to prevent starvation but can cause priority inversion if overused.
B. Aging decreases priority of high-priority processes to prevent deadlock but may cause livelock.
C. Aging randomly changes priorities to balance load but can lead to starvation of critical processes.
D. Aging forces processes to release resources periodically but increases overhead significantly.

Solution

  1. Step 1: Understand aging purpose

    Aging gradually increases the priority of waiting processes to ensure they eventually get CPU time, preventing starvation.
  2. Step 2: Identify downside

    Over-aggressive aging can cause priority inversion, where lower-priority processes gain higher priority than intended, disrupting scheduling fairness.
  3. Step 3: Analyze options

    Aging increases priority of waiting processes to prevent starvation but can cause priority inversion if overused correctly states aging's purpose and downside. Aging decreases priority of high-priority processes to prevent deadlock but may cause livelock incorrectly associates aging with deadlock prevention and livelock. Aging randomly changes priorities to balance load but can lead to starvation of critical processes misrepresents aging as random priority changes. Aging forces processes to release resources periodically but increases overhead significantly confuses aging with resource release policies.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Aging = priority boost to prevent starvation, risk of priority inversion.
Hint: Aging = priority boost to avoid starvation, watch for inversion
Common Mistakes:
  • Confusing aging with deadlock prevention
  • Thinking aging randomly changes priorities
5. Which of the following statements about user mode and kernel mode is INCORRECT?
medium
A. Mode switches are triggered by traps or interrupts to ensure controlled privilege escalation.
B. Kernel mode has unrestricted access to all hardware and memory.
C. User mode code cannot directly access kernel memory for protection reasons.
D. System calls execute entirely in user mode without switching to kernel mode.

Solution

  1. Step 1: Review privilege separation

    User mode is restricted; kernel mode has full privileges.
  2. Step 2: Validate each statement

    User mode code cannot directly access kernel memory for protection reasons. is true; user mode cannot access kernel memory. Kernel mode has unrestricted access to all hardware and memory. is true; kernel mode has full access. Mode switches are triggered by traps or interrupts to ensure controlled privilege escalation. is true; traps/interrupts cause mode switches.
  3. Step 3: Identify incorrect statement

    System calls execute entirely in user mode without switching to kernel mode. is false; system calls require switching to kernel mode to execute privileged operations.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    System calls always involve mode switch to kernel [OK]
Hint: System calls require kernel mode execution
Common Mistakes:
  • Believing system calls run entirely in user mode
  • Confusing hardware interrupts with system calls
  • Assuming user mode can access kernel memory
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard