

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A c++ program simulating the first-in-first-out (fifo) disk scheduling strategy. The program generates random requests and calculates the average and variance of head movements. The output shows that the results are uniformly distributed as expected.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!
A simple disk-scheduling system. #include <iostream.h> #include <math.h> #include <time.h> int rand(int&); void clear(double [], int); const int multip = 7919; // a prime number; const int modulr = 7879; // a prime number; main() { int fin = 100; int i,j; int n=10000; int req[10000]; double moves[10000]; int seed = time(NULL)%1000; for (int run=0; run <50; run++) { int start=0; double movesum = 0.0; double average = 0.0; double variance = 0.0; double vsum = 0.0; clear(req,n); clear(moves,n); for (i=0; i<n; i++) // Generate n requests in req array { req[i]=rand(seed); j=abs(req[i]-start); moves[i]=double(j)/100.0;
movesum=movesum + moves[i]; start = req[i]; } average = movesum/double(n); for (i=0; i<n; i++) { double c = average-moves[i]; vsum = vsum + cc; } if (n>1) variance = vsum/double(n-1); cout << "Run = " << run; cout <<" movesum = "<<movesum<<" variance = "<<variance<<endl; } } int rand(int& s) // This generates random numbers between 0-99. { double u; s = (s * multip)% modulr; // compute new seed u = (100.0double(s))/double(modulr); return int(u); } void clear(double a[], int n) { for (int i=0; i<n ; i++) a[i]=0.0; } This is just FIFO disk-scheduling strategy. The output of the simulation appears to be uniformly distributed over variance as expected.