Question: Implement the C-SCAN disk scheduling algorithm in C showing the number of head movements needed. Below is a main function that takes an input file
Implement the C-SCAN disk scheduling algorithm in C showing the number of head movements needed. Below is a main function that takes an input file and the intial head position.
Here is an example:
cat inputfile.txt | ./a.out 53
Here is a sample input using the intial head position as 53:
98, 183, 37, 122, 14, 124, 65, 67 (the head movements should = 183 with a request queue of 0-199)
#include#include /* Assume no more than 1000 requests in the input file */ #define BUFSIZE 1000 /* Assume 5000 cylinders */ #define CYL 5000 /* Assume no requests will be longer than 80 characterse */ #define LINELEN 80
int cscan(int initpos, int requests[], int nmemb) { return 0; } main(int argc, char* argv[]) { char s[LINELEN]; int requests[BUFSIZE]; int count; int initpos; if (argc < 2) { printf("Usage: ./a.out initpos "); exit(1); } initpos = atoi(argv[1]); count=0; while (fgets(s, LINELEN, stdin)) requests[count++]=atoi(s); printf("C-SCAN: %d ", cscan(initpos, requests, count)); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
