Bird
Raised Fist0
Interview Prepoperating-systemsmediumAmazonGoogleMicrosoftWipro

Disk Scheduling - SSTF, SCAN, C-SCAN

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

Initialize SSTF Scheduler

Initialize the SSTF scheduler with the head at position 50 and the request queue [10, 22, 20, 2, 40, 6, 38, 48]. No requests have been serviced yet.

💡 Setting up initial state is crucial to understand how the scheduler will pick requests based on shortest seek time.
Line:head = 50 requests = [10, 22, 20, 2, 40, 6, 38, 48] serviced = []
💡 The scheduler starts with a known head position and a list of pending requests.
📊
Disk Scheduling - SSTF, SCAN, C-SCAN - Watch the Algorithm Execute, Step by Step
Watching the algorithm step-by-step reveals how each scheduling strategy optimizes disk head movement differently, which is hard to grasp from code alone.
Step 1/14
·Active fillAnswer cell
Transition newready pid:SSTF - Initialization of SSTF scheduler
SSTF
ready
Ready Queue
empty
Waiting Queue
empty
🖥CPUSSTFt=0
Transition readyrunning pid:SSTF - Calculating closest request
SSTF
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSSTFt=1
SSTF
Transition runningrunning pid:SSTF - Moved head and serviced request 48
SSTF
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSSTFt=2
SSTF
Transition runningrunning pid:SSTF - Calculating next closest request
SSTF
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSSTFt=3
SSTF
Transition runningrunning pid:SSTF - Moved head and serviced request 40
SSTF
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSSTFt=4
SSTF
Transition newready pid:SCAN - Initialization of SCAN scheduler
SCAN
ready
Ready Queue
empty
Waiting Queue
empty
🖥CPUSCANt=0
Transition readyrunning pid:SCAN - Moved head and serviced request 48
SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSCANt=1
SCAN
Transition runningrunning pid:SCAN - Moved head to disk end and reversed direction
SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSCANt=2
SCAN
Transition runningrunning pid:SCAN - Moved head and serviced request 40
SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUSCANt=3
SCAN
Transition newready pid:C-SCAN - Initialization of C-SCAN scheduler
C-SCAN
ready
Ready Queue
empty
Waiting Queue
empty
🖥CPUC-SCANt=0
Transition readyrunning pid:C-SCAN - Moved head and serviced request 48
C-SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUC-SCANt=1
C-SCAN
Transition runningrunning pid:C-SCAN - Moved head to disk end and wrapped to start
C-SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUC-SCANt=2
C-SCAN
Transition runningrunning pid:C-SCAN - Moved head and serviced request 2
C-SCAN
running
Ready Queue
empty
Waiting Queue
empty
🖥CPUC-SCANt=3
C-SCAN
Transition runningterminated pid:SSTF - All requests serviced
SSTF
terminated
burst: 0
SCAN
terminated
burst: 0
C-SCAN
terminated
burst: 0
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=14
SSTF
SCAN
C-SCAN

Key Takeaways

SSTF minimizes immediate seek time by always choosing the closest request next.

This greedy approach is intuitive but can cause starvation for far requests, which is clearer when watching the head movements step-by-step.

SCAN moves the head in one direction servicing all requests until it reaches the end, then reverses direction.

Visualizing SCAN shows how it reduces seek time by avoiding random jumps, unlike SSTF, but still services all requests fairly.

C-SCAN treats the disk as a circular list, moving in one direction and jumping back to start without servicing requests on the return.

Watching C-SCAN's wrap-around clarifies how it provides more uniform wait times compared to SCAN.

Practice

(1/5)
1. Trace the sequence of checks the Banker's Algorithm performs when a process requests additional resources. Which step occurs immediately after verifying the request does not exceed the process's declared maximum need?
easy
A. The algorithm preempts resources from other processes to fulfill the request.
B. The algorithm immediately grants the request without further checks.
C. The algorithm simulates allocation and checks if the system remains in a safe state.
D. The algorithm checks if the requested resources are currently available in the system.

Solution

  1. Step 1: Recall the Banker's Algorithm request sequence

    First, it checks if the request is within the process's maximum declared need.
  2. Step 2: Next step after need check

    The algorithm then verifies if the requested resources are available in the system's current available pool.
  3. Step 3: Subsequent steps

    If available, it simulates allocation and checks for safe state, but this occurs after availability check.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Availability check precedes simulation to avoid unnecessary computation.
Hint: Request ≤ Need -> check availability -> simulate safe state [OK]
Common Mistakes:
  • Assuming simulation happens before availability check
  • Believing requests are granted immediately after need check
  • Thinking preemption is part of Banker's Algorithm
2. When a file grows beyond the capacity of direct block pointers in its inode, what sequence of steps occurs to locate the additional data blocks?
easy
A. The file system uses single indirect pointers to reference blocks that contain further direct block pointers.
B. The inode immediately switches to double indirect pointers, skipping single indirect pointers.
C. The file system allocates new direct pointers dynamically within the inode structure.
D. The inode stores the entire file content directly once direct pointers are exhausted.

Solution

  1. Step 1: Recall inode pointer hierarchy

    Inodes have a fixed number of direct pointers, followed by single, double, and triple indirect pointers for larger files.
  2. Step 2: Understand pointer escalation

    When direct pointers are full, the file system uses single indirect pointers, which point to blocks containing more direct pointers.
  3. Step 3: Eliminate incorrect escalations

    The inode does not skip levels; it uses single indirect before double indirect pointers.
  4. Step 4: Clarify inode content storage

    Inodes never store file content directly; they only store metadata and pointers.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Single indirect pointers extend data block addressing after direct pointers [OK]
Hint: Direct -> Single Indirect -> Double Indirect pointer escalation
Common Mistakes:
  • Skipping pointer levels (double indirect before single indirect)
  • Assuming inode can dynamically add direct pointers
  • Thinking inode stores file content directly
3. Which of the following statements about the five-state process model is INCORRECT?
medium
A. The New state represents a process that is being created but not yet ready to run
B. The Waiting state is used when a process is blocked for I/O completion
C. A process in the Terminated state can be moved back to Ready state if needed
D. The Running state means the process is currently executing on the CPU

Solution

  1. Step 1: Review each statement

    A, B, and D correctly describe standard process states.
    C incorrectly states that a Terminated process can return to Ready, which violates the model.
  2. Step 2: Understand Terminated state

    Terminated means process execution is complete; it cannot be restarted or moved back.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Terminated processes cannot be revived in the five-state model [OK]
Hint: Terminated means final; no return to Ready [OK]
Common Mistakes:
  • Thinking Terminated processes can be restarted
  • Confusing Waiting with Ready state
  • Misunderstanding New state as Ready
4. 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
5. If a system enforces a strict ordering of resource acquisition to prevent circular wait, which of the following is a potential drawback that an interviewer might probe?
hard
A. Processes may experience increased waiting time due to forced ordering, reducing concurrency.
B. The system can still deadlock due to hold and wait despite ordering.
C. No preemption condition is violated by enforcing ordering.
D. Mutual exclusion is no longer required when ordering is enforced.

Solution

  1. Step 1: Understand resource ordering

    Ordering resources prevents circular wait by forcing processes to request resources in a global order.
  2. Step 2: Identify drawbacks

    Strict ordering can cause processes to wait longer than necessary, reducing concurrency and system throughput.
  3. Step 3: Analyze other options

    The system can still deadlock due to hold and wait despite ordering is incorrect because ordering eliminates circular wait, thus preventing deadlock from that condition. No preemption condition is violated by enforcing ordering is false; ordering does not violate no preemption. Mutual exclusion is no longer required when ordering is enforced is false; mutual exclusion is still required for non-shareable resources.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Ordering trades off concurrency for deadlock prevention.
Hint: Ordering resources prevents circular wait but can reduce concurrency [OK]
Common Mistakes:
  • Believing ordering removes all deadlock conditions
  • Confusing ordering with preemption
  • Assuming mutual exclusion is eliminated by ordering