C-SCAN (Circular SCAN) Disk Scheduling Algorithm

 

C-SCAN (Circular SCAN) Disk Scheduling Algorithm

Aim

To simulate the C-SCAN disk scheduling algorithm and compute the total head movement, displaying Step, From, To, Movement.


Theory

C-SCAN (Circular SCAN) is an improved version of SCAN.

  • The head moves only in one direction (say LEFT → RIGHT).

  • It services all requests while moving in that direction.

  • When it reaches the last track, it jumps to the first track (0) without servicing requests during the return.

  • Then continues again in the same direction.

👉 This provides more uniform waiting time than SCAN.

Why C-SCAN?

SCAN services requests in both directions, so middle tracks get serviced more often.
C-SCAN treats the disk as a circular queue, ensuring fair service.


Advantages

  • Uniform waiting time

  • No bias toward middle cylinders

  • Predictable response time

Disadvantages

  • Extra head movement due to circular jump

  • Slightly more movement than SSTF


Algorithm

  1. Read number of disk requests.

  2. Read request queue.

  3. Read initial head position.

  4. Read disk size.

  5. Sort requests.

  6. Move head in one direction only (RIGHT assumed):

    • Service all requests greater than head.

  7. Move head to disk end.

  8. Jump to track 0.

  9. Continue servicing remaining smaller requests.

  10. Calculate total head movement.


Program: C-SCAN Disk Scheduling (C)

#include <stdio.h> #include <stdlib.h> void sort(int a[], int n){ for(int i=0;i<n-1;i++) for(int j=0;j<n-i-1;j++) if(a[j]>a[j+1]){ int t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } int main(){ int n, head, size; int total=0; printf("Enter number of requests: "); scanf("%d",&n); int req[n]; printf("Enter requests:\n"); for(int i=0;i<n;i++) scanf("%d",&req[i]); printf("Enter initial head position: "); scanf("%d",&head); printf("Enter disk size (max track number): "); scanf("%d",&size); sort(req,n); printf("\nStep\tFrom\tTo\tMovement\n"); printf("--------------------------------\n"); int cur=head, step=1; // service requests to the RIGHT first for(int i=0;i<n;i++){ if(req[i]>=head){ printf("%d\t%d\t%d\t%d\n",step++,cur,req[i],abs(cur-req[i])); total+=abs(cur-req[i]); cur=req[i]; } } // move to disk end printf("%d\t%d\t%d\t%d\n",step++,cur,size-1,abs(cur-(size-1))); total+=abs(cur-(size-1)); cur=size-1; // jump to 0 printf("%d\t%d\t%d\t%d\n",step++,cur,0,abs(cur-0)); total+=abs(cur-0); cur=0; // service remaining requests for(int i=0;i<n;i++){ if(req[i]<head){ printf("%d\t%d\t%d\t%d\n",step++,cur,req[i],abs(cur-req[i])); total+=abs(cur-req[i]); cur=req[i]; } } printf("--------------------------------\n"); printf("Total head movement = %d\n",total); return 0; }

Example (Same Request Set)

Input

Enter number of requests: 8 Enter requests: 98 183 37 122 14 124 65 67 Enter initial head position: 53 Enter disk size (max track number): 200

Sorted Requests

14 37 65 67 98 122 124 183

Sample Run (RIGHT direction only)

Service right side:

53 → 65 → 67 → 98 → 122 → 124 → 183 → 199

Jump to start:

199 → 0

Continue:

0 → 14 → 37


Output Table

Step From To Movement -------------------------------- 1 53 65 12 2 65 67 2 3 67 98 31 4 98 122 24 5 122 124 2 6 124 183 59 7 183 199 16 8 199 0 199 9 0 14 14 10 14 37 23 -------------------------------- Total head movement = 382

Observation

Algorithm    Head Movement
FCFS        640
SSTF        236
SCAN        331
C-SCAN        382

👉 C-SCAN may move more than SCAN but provides fairer waiting time.


Result

The C-SCAN disk scheduling algorithm was successfully implemented and tested.
For the given example, total head movement = 382 tracks.

Comments

Popular posts from this blog

Operating Systems OS Lab PCCSL407 Semester 4 KTU BTech CS 2024 Scheme - Dr Binu V P

Exploring the /proc file system

FCFS First Come First Serve - CPU Scheduling