Lab 14 walkthrough — Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK
Lab 14 walkthrough — Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK
Recorded by Dr. Krithika L.B. Slot lab14-walkthrough
Theory link: 5.2 Disk scheduling
Lab 14 walkthrough — Disk scheduling algorithms: C-SCAN, LOOK, C-LOOK
Recorded by Dr. Krithika L.B. Slot lab14-walkthrough
Aim. To compute the order of service and total head movement for C-SCAN, LOOK and C-LOOK disk scheduling.
All three first sweep upward serving requests ≥ head, then:
Continue to the last cylinder, return to cylinder 0, then sweep up again.
Reverse at the last request and serve the rest going down.
Jump from the last request to the lowest pending request, then sweep up.
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.
/* 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;
}gcc disk2.c -o disk2./disk2Head movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 199 -> 0 -> 14 -> 37
Total head movement = 382 cylindersHead movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 37 -> 14
Total head movement = 299 cylindersHead movement: 53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 14 -> 37
Total head movement = 322 cylindersPrepare these for the lab evaluation.
Revealed 0It serves requests in only one direction and jumps back to the start, giving more uniform waiting times.
They do not travel to the end of the disk when no requests are there.
Only SSTF.