Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Lab 14: Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK

Theory link: 5.2 Disk scheduling

Experiment 14 of 15 Module 5 2 hours

Video walkthrough

Lab 14 walkthrough — Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK

Video coming soon

Lab 14 walkthrough — Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK

Recorded by Dr. Krithika L.B. Slot lab14-walkthrough

Aim

Aim. To compute the order of service and total head movement for C-SCAN, LOOK and C-LOOK disk scheduling.

Explanation

All three first sweep upward serving requests ≥ head, then:

C-SCAN

Continue to the last cylinder, return to cylinder 0, then sweep up again.

LOOK

Reverse at the last request and serve the rest going down.

C-LOOK

Jump from the last request to the lowest pending request, then sweep up.

Convention

This program counts the return sweep of C-SCAN (199 → 0) and the jump of C-LOOK as head movement. If your instructor excludes them, subtract that distance.

Code

disk2.c
/* disk2.c - disk scheduling: C-SCAN, LOOK, C-LOOK (BACSE106 Lab 14) */
#include <stdio.h>

int main(void)
{
    int n, head, size, choice, i, j, total = 0, start;
    int req[50];

    printf("Number of requests: ");
    scanf("%d", &n);
    printf("Request queue: ");
    for (i = 0; i < n; i++) scanf("%d", &req[i]);
    printf("Initial head position: ");
    scanf("%d", &head);
    printf("Disk size (number of cylinders): ");
    scanf("%d", &size);
    printf("1.C-SCAN  2.LOOK  3.C-LOOK (towards higher cylinders)  Choice: ");
    scanf("%d", &choice);

    for (i = 0; i < n; i++)                              /* sort requests */
        for (j = i + 1; j < n; j++)
            if (req[j] < req[i]) { int t = req[i]; req[i] = req[j]; req[j] = t; }

    start = head;
    printf("\nHead movement: %d", head);
    for (i = 0; i < n; i++)                              /* all three first sweep up */
        if (req[i] >= start) { total += req[i] - head; head = req[i]; printf(" -> %d", head); }

    if (choice == 1) {                                   /* C-SCAN: to the end, jump to 0, sweep up */
        total += (size - 1) - head;  printf(" -> %d", size - 1);
        total += size - 1;           printf(" -> 0");     /* return seek counted */
        head = 0;
        for (i = 0; i < n; i++)
            if (req[i] < start) { total += req[i] - head; head = req[i]; printf(" -> %d", head); }
    } else if (choice == 2) {                            /* LOOK: reverse at the last request */
        for (i = n - 1; i >= 0; i--)
            if (req[i] < start) { total += head - req[i]; head = req[i]; printf(" -> %d", head); }
    } else {                                             /* C-LOOK: jump to the lowest request, sweep up */
        for (i = 0; i < n; i++)
            if (req[i] < start) {
                total += (head > req[i]) ? head - req[i] : req[i] - head;
                head = req[i];
                printf(" -> %d", head);
            }
    }
    printf("\nTotal head movement = %d cylinders\n", total);
    return 0;
}

Download disk2.c

How to run

  1. gcc disk2.c -o disk2
  2. ./disk2
  3. Enter the same inputs as Lab 13 and choose 1, 2 or 3.

Sample input & output

C-SCAN

Input
8 · 98 183 37 122 14 124 65 67 · head 53 · disk size 200 · choice 1
Output
Output
Head movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 199 -> 0 -> 14 -> 37
Total head movement = 382 cylinders

LOOK

Input
8 · 98 183 37 122 14 124 65 67 · head 53 · disk size 200 · choice 2
Output
Output
Head movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 37 -> 14
Total head movement = 299 cylinders

C-LOOK

Input
8 · 98 183 37 122 14 124 65 67 · head 53 · disk size 200 · choice 3
Output
Output
Head movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 14 -> 37
Total head movement = 322 cylinders

Try it yourself

  1. Print the totals both with and without the return sweep.
  2. Combine Labs 13 and 14 into one program that prints a comparison table of all six algorithms.
  3. Add support for the head moving toward 0 first.

Viva questions

Prepare these for the lab evaluation.

Revealed 0
How does C-SCAN differ from SCAN?

It serves requests in only one direction and jumps back to the start, giving more uniform waiting times.

Why are LOOK and C-LOOK usually better than SCAN and C-SCAN?

They do not travel to the end of the disk when no requests are there.

Which of the six algorithms can starve a request?

Only SSTF.