-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk_scheduling.c
56 lines (56 loc) · 1.26 KB
/
disk_scheduling.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
int n,a[20],max,ini,total,i;
void fcfs()
{
total=abs(ini-a[0]);
for(i=0;i<n-1;i++)
{
total+=abs(a[i+1]-a[i]);
}
printf("FCFS total head movement(seek time)=%d\n",total);
}
void scan()
{
int small=max;
for(i=0;i<n;i++)
{
if(a[i]<small)
{
small=a[i];
}
}
total=abs(max-ini)+abs(max-small);
printf("SCAN total head movement(seek time)=%d\n",total);
}
void cscan()
{
int large=0;
for(i=0;i<n;i++)
{
if(a[i]>large && a[i]<ini)
{
large=a[i];
}
}
total=abs(max-ini)+max+large;
printf("CSCAN total head movement(seek time)=%d\n",total);
}
void main()
{
printf("Enter the number of requests: ");
scanf("%d",&n);
printf("Enter the requests: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the total disc size: ");
scanf("%d",&max);
max--;
printf("Enter the starting position: ");
scanf("%d",&ini);
fcfs();
scan();
cscan();
}