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
Steps
setup

Process Created and Added to New State

The process is created and enters the New state, preparing to be admitted to the system.

💡 Initialization is crucial to understand where a process starts before it can be scheduled.
Line:process.state = 'New' # STEP 1
💡 Processes begin in the New state before admission to the ready queue.
📊
Process State Machine - Five-State Model - Watch the Algorithm Execute, Step by Step
Watching the process state transitions and queue movements step-by-step reveals how operating systems manage process lifecycles and CPU allocation.
Step 1/10
·Active fillAnswer cell
Transition noneNew pid:1 - Process created
1
New
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=0
Transition NewReady pid:1 - Process admitted to ready queue
1
Ready
burst: 5
Ready Queue
1
Waiting Queue
empty
🖥CPUidlet=0
Transition ReadyRunning pid:1 - Scheduler dispatched process to CPU
1
Running
burst: 5
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=1
Transition RunningRunning pid:1 - Process executed one CPU unit
1
Running
burst: 4
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=2
Transition RunningWaiting pid:1 - Process requested I/O
1
Waiting
burst: 4
Ready Queue
empty
Waiting Queue
1 (I/O)
🖥CPUidlet=3
1
Transition WaitingReady pid:1 - I/O completed
1
Ready
burst: 4
Ready Queue
1
Waiting Queue
empty
🖥CPUidlet=4
1
Transition ReadyRunning pid:1 - Scheduler dispatched process to CPU again
1
Running
burst: 4
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=5
1
Transition RunningRunning pid:1 - Process executed one CPU unit
1
Running
burst: 3
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=6
1
Transition RunningTerminated pid:1 - Process completed execution
1
Terminated
burst: 0
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=7
1
Transition TerminatedIdle - No processes left to run
1
Terminated
burst: 0
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=8
1
idle

Key Takeaways

Processes transition through distinct states: New, Ready, Running, Waiting, and Terminated.

This lifecycle is fundamental but often abstract; seeing it step-by-step clarifies the flow.

The ready queue holds processes waiting for CPU, and the waiting queue holds those blocked on I/O.

Understanding these queues visually helps grasp scheduling and blocking concepts.

CPU scheduling decisions move processes between Ready and Running, while I/O requests cause transitions to Waiting.

Watching these decisions unfold shows how the OS manages CPU and I/O resources dynamically.

Practice

(1/5)
1. 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
2. In a system with multiple CPUs (multi-core), how does context switching overhead differ compared to a single-core system, and what additional factors must be considered?
hard
A. Context switching overhead per CPU remains the same, but inter-CPU cache coherence and synchronization add extra overhead
B. Context switching overhead is eliminated because each CPU runs its own process independently
C. Context switching overhead doubles because each CPU must save and restore registers twice
D. Context switching overhead is reduced because the scheduler can switch processes faster across CPUs

Solution

  1. Step 1: Per-CPU context switch cost

    Each CPU still saves/restores registers during context switches, so overhead per CPU is similar to single-core.
  2. Step 2: Additional multi-core factors

    Multi-core systems require cache coherence protocols and synchronization mechanisms, adding overhead beyond single-core context switching.
  3. Step 3: Misconceptions

    Context switching is not eliminated; CPUs do not save/restore registers twice per switch; scheduler speedup is not guaranteed.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Multi-core adds complexity beyond per-CPU context switch overhead.
Hint: Multi-core = same per-CPU cost + extra sync overhead [OK]
Common Mistakes:
  • Thinking multi-core removes context switch overhead
  • Assuming overhead doubles incorrectly
  • Believing scheduler is always faster on multi-core
3. If a file system uses triple indirect pointers in its inode structure, what is a potential downside when accessing a small file that fits entirely within direct blocks?
hard
A. The inode size increases significantly, wasting space for small files.
B. Accessing small files becomes slower due to unnecessary traversal of indirect pointers.
C. The file system must allocate indirect blocks even if the file is small.
D. There is no downside; triple indirect pointers do not affect small file access.

Solution

  1. Step 1: Understand inode fixed size

    Inodes have a fixed size that includes space for direct and indirect pointers, regardless of file size.
  2. Step 2: Analyze impact on small files

    Including triple indirect pointers increases inode size, which can waste space when storing many small files.
  3. Step 3: Clarify access speed for small files

    Accessing small files uses direct pointers only; indirect pointers are not traversed, so no speed penalty.
  4. Step 4: Confirm allocation behavior

    Indirect blocks are allocated only when needed; small files do not allocate them.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Fixed inode size with many pointers wastes space for small files [OK]
Hint: Fixed inode size -> wasted space for small files with many pointers
Common Mistakes:
  • Assuming indirect pointers slow down small file access
  • Believing indirect blocks are allocated for small files
  • Thinking triple indirect pointers have no impact on inode size
4. If the buffer size in a producer-consumer system is increased dynamically at runtime, which challenge arises that the classic semaphore-based solution does NOT handle well?
hard
A. Consumers must signal the 'empty' semaphore twice per consumed item
B. The 'empty' semaphore count must be adjusted atomically to reflect new buffer slots
C. Producers will never block because buffer is always large enough
D. Mutex locks become ineffective with dynamic buffer sizes

Solution

  1. Step 1: Classic solution assumes fixed buffer size

    Semaphore 'empty' initialized once to buffer size; dynamic resizing breaks this assumption.
  2. Step 2: Adjusting semaphore counts

    When buffer grows, 'empty' semaphore must be incremented atomically to reflect new slots; otherwise, producers may block unnecessarily.
  3. Step 3: Why other options are incorrect

    Consumers must signal the 'empty' semaphore twice per consumed item is false; consumers do not signal 'empty' twice. Mutex locks become ineffective with dynamic buffer sizes is false; mutex still protects critical section regardless of size. Producers will never block because buffer is always large enough is false; producers can still block if buffer is full.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Dynamic buffer size requires careful semaphore count updates [OK]
Hint: Dynamic buffer size requires dynamic semaphore adjustment
Common Mistakes:
  • Assuming fixed semaphore counts suffice for dynamic buffers
  • Thinking mutex depends on buffer size
  • Misunderstanding producer blocking conditions
5. If a system call is invoked from an interrupt handler already running in kernel mode, what is the expected behavior regarding mode switching and privilege checks?
hard
A. The system call is deferred until the interrupt handler finishes and user mode resumes.
B. The CPU switches to user mode before executing the system call to prevent privilege escalation.
C. The system call executes immediately without a mode switch since already in kernel mode.
D. The system call triggers a nested mode switch to a higher privilege level.

Solution

  1. Step 1: Understand current mode

    Interrupt handlers run in kernel mode with full privileges.
  2. Step 2: System call invoked in kernel mode

    Since already in kernel mode, no mode switch is needed; system call executes directly.
  3. Step 3: Why other options are incorrect

    The CPU switches to user mode before executing the system call to prevent privilege escalation. is incorrect; switching to user mode would reduce privileges improperly. The system call is deferred until the interrupt handler finishes and user mode resumes. is wrong; system calls are not deferred. The system call triggers a nested mode switch to a higher privilege level. is false; kernel mode is the highest privilege level, no nested switch occurs.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    System call in kernel mode -> no mode switch -> immediate execution [OK]
Hint: No mode switch if already in kernel mode
Common Mistakes:
  • Assuming mode switch always occurs on system call
  • Thinking system calls are deferred inside kernel
  • Believing nested privilege levels exist beyond kernel mode