0
0
Operating-systemsConceptBeginner · 3 min read

C-SCAN Disk Scheduling: How It Works and When to Use

C-SCAN (Circular SCAN) is a disk scheduling algorithm that moves the disk arm in one direction servicing requests until it reaches the end, then quickly returns to the start without servicing requests on the return. This approach provides a more uniform wait time compared to SCAN by treating the disk as a circular list.
⚙️

How It Works

Imagine a librarian who walks along a row of bookshelves from left to right, picking up requested books as they go. When they reach the last shelf, instead of walking back through the shelves again, they quickly return to the first shelf without picking any books on the way back. This is how C-SCAN works for disk scheduling.

The disk arm moves in one direction (say from the innermost track to the outermost track), servicing all pending requests along the way. Once it reaches the last track, it jumps back to the first track without servicing any requests during this return. This makes the wait time for requests more predictable and fair, as all requests are handled in a single direction sweep.

💻

Example

This Python example simulates C-SCAN disk scheduling for a set of disk requests and shows the order in which requests are serviced.
python
def c_scan(requests, head, disk_size):
    requests = sorted(requests)
    left = [r for r in requests if r < head]
    right = [r for r in requests if r >= head]

    order = []
    # Service requests to the right of head
    for r in right:
        order.append(r)
    # Jump to start (0) and service requests on the left
    for r in left:
        order.append(r)

    return order

# Example usage
requests = [95, 180, 34, 119, 11, 123, 62, 64]
head = 50
disk_size = 200
order = c_scan(requests, head, disk_size)
print("Order of servicing requests:", order)
Output
Order of servicing requests: [62, 64, 95, 119, 123, 180, 11, 34]
🎯

When to Use

C-SCAN is useful when you want to ensure a more uniform wait time for disk requests, especially in systems with heavy and continuous disk activity. It avoids the problem of longer wait times for requests near the start of the disk that can happen in the SCAN algorithm.

This algorithm is often used in operating systems and storage controllers where fairness and predictability in disk access times are important, such as in database servers or file servers handling many simultaneous requests.

Key Points

  • C-SCAN moves the disk arm in one direction only, servicing requests.
  • After reaching the end, it jumps back to the start without servicing requests on the return.
  • This approach provides a more uniform wait time than SCAN.
  • It treats the disk as a circular list of tracks.
  • Commonly used in systems needing fair and predictable disk access.

Key Takeaways

C-SCAN services disk requests in one direction and jumps back to start without servicing on return.
It provides more uniform wait times compared to SCAN by treating the disk as circular.
Useful in systems with heavy disk usage needing fairness and predictability.
The disk arm moves from current head position to the end, then quickly returns to the beginning.
C-SCAN avoids long waits for requests near the start of the disk.