DISK MANAGEMENT IN
OPERATING SYSTEM
BSCS 5TH SEMESTER SECTION – A
GROUP V
SUBMITTED TO: MA’AM FARHAT YASMEEN
GROUP MEMBERS
i. Nafeesa Kousar – 03
ii. Zona Zubair – 24
iii. Rabia Kainat – 45
iv. Zill-e-Huma – 41
v. Humna Ghani – 86
vi. Nageena Zareen - 82
vii. Faria Bint-e-Iqbal - 64
CONTENT
i. DISK MANAGEMENT
ii. FCFS
iii. SCAN
iv. C-SCAN
DISK MANAGEMENT
• Disk management is an important functionality provided by the operating system which can be
used to create, delete, format disk partitions, and much more. It enables users to manage and
view the different disks and functions like viewing, creating, deleting, and shrinking the
partitions associated with the disk drives.
• Disk management of the operating system includes:
• Disk format
• Booting from disk
• Bad block recovery
FIRST COME FIRST SERVE (FCFS)
• FCFS is the simplest disk scheduling algorithm. As the name suggests, this algorithm entertains
requests in the order they arrive in the disk queue. The algorithm looks very fair and there is no
starvation (all requests are serviced sequentially) but generally, it does not provide the fastest
service.
Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Output:
Total number of seek operations = 510
Seek Sequence is 176 79 34 60 92 11 41 114
CODE
#Include <iostream>
Using namespace std;
Int size = 8;
Void fcfs(int arr[], int head)
{ I
Nt seek_count = 0;
Int distance, cur_track;
For (int i = 0; i < size; i++)
{
Cur_track = arr[i];
// calculate absolute distance
Distance = abs(cur_track - head);
// Increase the total count
Seek_count += distance;
// Accessed track is now new head
Head = cur_track;
}
Cout << "total number of seek operations = "<<
seek_count << endl;
// Seek sequence would be the same
// As request array sequence
Cout << "seek sequence is" << endl;
For (int i = 0; i < size; i++)
{
Cout << arr[i] << endl;
}}
Int main()
{
Int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
Int head = 50;
Fcfs(arr, head);
Return 0;
}
SCAN SCHEDULING
• In the SCAN disk scheduling algorithm, the head starts from one end of the disk and
moves towards the other end, servicing requests in between one by one and reaching the
other end.
• Then the direction of the head is reversed and the process continues as the head
continuously scans back and forth to access the disk. So, this algorithm works as an
elevator and is hence also known as the elevator algorithm.
• As a result, the requests at the midrange are serviced more and those arriving behind the
disk arm will have to wait.
ALGORITHM
i. Let request array represents an array storing indexes of tracks that have been requested in
ascending order of their time of arrival. ‘Head’ is the position of the disk head.
ii. Let direction represents whether the head is moving towards left or right.
iii. In the direction in which the head is moving service all tracks one by one.
iv. Calculate the absolute distance of the track from the head.
v. Increment the total seek count with this distance.
vi. Currently serviced track position now becomes the new head position.
vii. Go to step 3 until we reach at one of the ends of the disk.
viii. If we reach at end of the disk reverse the direction and go to step 2 until all tracks in the
request array have not been serviced.
EXAMPLE
Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the read/write arm is at
50, and it is also given that the disk arm should move “towards the larger value”.
Therefore, the seek time is calculated as:
=(199-50)+(199-16)
=332
ADVANTAGES
• This algorithm is simple and easy to
understand.
• Scan algorithm has no starvation.
• This algorithm is better than the FCFS
scheduling algorithm.
DISADVANTAGES
• More complex algorithm to implement.
• This algorithm is not fair because it causes
a long waiting time for the cylinders just
visited by the head.
• It causes the head to move till the end of
the disk in this way the requests arriving
ahead of the arm position would get
immediate service but some other requests
that arrive behind the arm position will
have to wait for the request to complete.
CODE
#Include <iostream>
Using namespace std;
Int main(){
Int i,j,k,n,m,sum=0,x,y,h;
Cout<<"enter the size of diskn";
Cin>>m;
Cout<<"enter number of requestsn";
Cin>>n;
Cout<<"enter the requestsn";
Vector <int> a(n),b;
For(i=0;i<n;i++){
Cin>>a[i];
}
For(i=0;i<n;i++){
If(a[i]>m){
Cout<<"error, unknown position "<<a[i]<<"n";
Return 0;
}}
Cout<<"enter the head positionn";
Cin>>h;
Int temp=h;
A.Push_back(h);
A.Push_back(m);
A.Push_back(0);
Sort(a.Begin(),a.End());
For(i=0;i<a.Size();i++){
If(h==a[i])
Break;
}
K=i;
If(k<n/2){
For(i=k;i<a.Size();i++){
B.Push_back(a[i]);
}
For(i=k-1;i>=0;i--){
B.Push_back(a[i]);
}}
Else{
For(i=k;i>=0;i--){
B.Push_back(a[i]);
}
For(i=k+1;i<a.Size();i++){
B.Push_back(a[i]);
}}
Temp=b[0];
Cout<<temp;
For(i=1;i<b.Size();i++){
Cout<<" -> "<<b[i];
Sum+=abs(b[i]-temp);
Temp=b[i];
}
Cout<<'n';
Cout<<"total head movements = "<< sum<<'n';
Cout<<"average head movement =
"<<(float)sum/n<<'n';
Return 0;
}
C-SCAN SCHEDULING
• The direction must be considered, that is, towards larger or smaller value.
• This algorithm moves towards the end of disk requests and serves them.
• Once we reach the end of the disk request, it reaches back to 0 during this
process as no requests are served.
• Once 0 is reached, the remaining requests are served.
EXAMPLE
• Let’s consider a disk
with 200 tracks(0-199),
a request queue
containing track
numbers
[82,170,43,140,24,16,1
90], and the current
position of read-write
head=50.
• The requirement is to
find the total number of
track movements in
cylinders.(Direction
towards larger value.)
EXAMPLE
Direction towards smaller value.
CODE
#Include <iostream>
Using namespace std;
Int size = 8;
Int disk_size = 200;
Void cscan(int arr[], int head)
{
Int seek_count = 0;
Int distance, cur_track;
Vector<int> left, right;
Vector<int> seek_sequence;
// Appending end values
// Which has to be visited
// Before reversing the direction
Left.Push_back(0);
Right.Push_back(disk_size - 1);
// Tracks on the left of the
// Head will be serviced when
// Once the head comes back
// To the beginning (left end).
For (int i = 0; i < size; i++) {
if (arr[i] < head)
Left.Push_back(arr[i]);
If (arr[i] > head)
Right.Push_back(arr[i]);
}
// Sorting left and right vectors
Std::sort(left.Begin(), left.End());
Std::sort(right.Begin(), right.End());
// First service the requests
// On the right side of the
// Head.
For (int i = 0; i < right.Size(); i++) {
cur_track = right[i];
// Appending current track to seek sequence
Seek_sequence.Push_back(cur_track);
// Calculate absolute distance
Distance = abs(cur_track - head);
// Increase the total count
Seek_count += distance;
// Accessed track is now new head
Head = cur_track; }
// Once reached the right end
// Jump to the beginning.
Head = 0;
// Adding seek count for head returning from 199 to 0
Seek_count += (disk_size - 1);
// Now service the requests again
// Which are left.
For (int i = 0; i < left.Size(); i++) {
Cur_track = left[i];
// Appending current track to seek sequence
Seek_sequence.Push_back(cur_track);
// Calculate absolute distance
Distance = abs(cur_track - head);
// Increase the total count
Seek_count += distance;
// Accessed track is now the new head
Head = cur_track; }
Cout << "total number of seek operations = "<<
seek_count << endl;
Cout << "seek sequence is" << endl;
For (int i = 0; i < seek_sequence.Size(); i++) {
Cout << seek_sequence[i] << endl; }}
Int main()
{
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
cout << "Initial position of head: " << head << endl;
CSCAN(arr, head);
return 0;
}
• Advantages
• Works well with moderate to heavy loads.
• It provides better response time and uniform waiting time.
• Disadvantages
• If no requests remain to be serviced, the head will travel to the end of the disk.
• It has more seek movements as compared to the scan algorithm.

Disk Management Presentation of Group V [Operating System (Lab)].pptx

  • 1.
    DISK MANAGEMENT IN OPERATINGSYSTEM BSCS 5TH SEMESTER SECTION – A GROUP V SUBMITTED TO: MA’AM FARHAT YASMEEN
  • 2.
    GROUP MEMBERS i. NafeesaKousar – 03 ii. Zona Zubair – 24 iii. Rabia Kainat – 45 iv. Zill-e-Huma – 41 v. Humna Ghani – 86 vi. Nageena Zareen - 82 vii. Faria Bint-e-Iqbal - 64
  • 3.
    CONTENT i. DISK MANAGEMENT ii.FCFS iii. SCAN iv. C-SCAN
  • 4.
    DISK MANAGEMENT • Diskmanagement is an important functionality provided by the operating system which can be used to create, delete, format disk partitions, and much more. It enables users to manage and view the different disks and functions like viewing, creating, deleting, and shrinking the partitions associated with the disk drives. • Disk management of the operating system includes: • Disk format • Booting from disk • Bad block recovery
  • 6.
    FIRST COME FIRSTSERVE (FCFS) • FCFS is the simplest disk scheduling algorithm. As the name suggests, this algorithm entertains requests in the order they arrive in the disk queue. The algorithm looks very fair and there is no starvation (all requests are serviced sequentially) but generally, it does not provide the fastest service. Input: Request sequence = {176, 79, 34, 60, 92, 11, 41, 114} Initial head position = 50 Output: Total number of seek operations = 510 Seek Sequence is 176 79 34 60 92 11 41 114
  • 8.
    CODE #Include <iostream> Using namespacestd; Int size = 8; Void fcfs(int arr[], int head) { I Nt seek_count = 0; Int distance, cur_track; For (int i = 0; i < size; i++) { Cur_track = arr[i]; // calculate absolute distance Distance = abs(cur_track - head); // Increase the total count Seek_count += distance; // Accessed track is now new head Head = cur_track; } Cout << "total number of seek operations = "<< seek_count << endl; // Seek sequence would be the same // As request array sequence Cout << "seek sequence is" << endl;
  • 9.
    For (int i= 0; i < size; i++) { Cout << arr[i] << endl; }} Int main() { Int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 }; Int head = 50; Fcfs(arr, head); Return 0; }
  • 11.
    SCAN SCHEDULING • Inthe SCAN disk scheduling algorithm, the head starts from one end of the disk and moves towards the other end, servicing requests in between one by one and reaching the other end. • Then the direction of the head is reversed and the process continues as the head continuously scans back and forth to access the disk. So, this algorithm works as an elevator and is hence also known as the elevator algorithm. • As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will have to wait.
  • 12.
    ALGORITHM i. Let requestarray represents an array storing indexes of tracks that have been requested in ascending order of their time of arrival. ‘Head’ is the position of the disk head. ii. Let direction represents whether the head is moving towards left or right. iii. In the direction in which the head is moving service all tracks one by one. iv. Calculate the absolute distance of the track from the head. v. Increment the total seek count with this distance. vi. Currently serviced track position now becomes the new head position. vii. Go to step 3 until we reach at one of the ends of the disk. viii. If we reach at end of the disk reverse the direction and go to step 2 until all tracks in the request array have not been serviced.
  • 13.
    EXAMPLE Suppose the requeststo be addressed are-82,170,43,140,24,16,190. And the read/write arm is at 50, and it is also given that the disk arm should move “towards the larger value”. Therefore, the seek time is calculated as: =(199-50)+(199-16) =332
  • 14.
    ADVANTAGES • This algorithmis simple and easy to understand. • Scan algorithm has no starvation. • This algorithm is better than the FCFS scheduling algorithm. DISADVANTAGES • More complex algorithm to implement. • This algorithm is not fair because it causes a long waiting time for the cylinders just visited by the head. • It causes the head to move till the end of the disk in this way the requests arriving ahead of the arm position would get immediate service but some other requests that arrive behind the arm position will have to wait for the request to complete.
  • 15.
    CODE #Include <iostream> Using namespacestd; Int main(){ Int i,j,k,n,m,sum=0,x,y,h; Cout<<"enter the size of diskn"; Cin>>m; Cout<<"enter number of requestsn"; Cin>>n; Cout<<"enter the requestsn"; Vector <int> a(n),b; For(i=0;i<n;i++){ Cin>>a[i]; } For(i=0;i<n;i++){ If(a[i]>m){ Cout<<"error, unknown position "<<a[i]<<"n"; Return 0; }} Cout<<"enter the head positionn"; Cin>>h; Int temp=h; A.Push_back(h); A.Push_back(m); A.Push_back(0); Sort(a.Begin(),a.End());
  • 16.
  • 17.
    Temp=b[i]; } Cout<<'n'; Cout<<"total head movements= "<< sum<<'n'; Cout<<"average head movement = "<<(float)sum/n<<'n'; Return 0; }
  • 19.
    C-SCAN SCHEDULING • Thedirection must be considered, that is, towards larger or smaller value. • This algorithm moves towards the end of disk requests and serves them. • Once we reach the end of the disk request, it reaches back to 0 during this process as no requests are served. • Once 0 is reached, the remaining requests are served.
  • 20.
    EXAMPLE • Let’s considera disk with 200 tracks(0-199), a request queue containing track numbers [82,170,43,140,24,16,1 90], and the current position of read-write head=50. • The requirement is to find the total number of track movements in cylinders.(Direction towards larger value.)
  • 21.
  • 22.
    CODE #Include <iostream> Using namespacestd; Int size = 8; Int disk_size = 200; Void cscan(int arr[], int head) { Int seek_count = 0; Int distance, cur_track; Vector<int> left, right; Vector<int> seek_sequence; // Appending end values // Which has to be visited // Before reversing the direction Left.Push_back(0); Right.Push_back(disk_size - 1); // Tracks on the left of the // Head will be serviced when // Once the head comes back // To the beginning (left end). For (int i = 0; i < size; i++) { if (arr[i] < head) Left.Push_back(arr[i]);
  • 23.
    If (arr[i] >head) Right.Push_back(arr[i]); } // Sorting left and right vectors Std::sort(left.Begin(), left.End()); Std::sort(right.Begin(), right.End()); // First service the requests // On the right side of the // Head. For (int i = 0; i < right.Size(); i++) { cur_track = right[i]; // Appending current track to seek sequence Seek_sequence.Push_back(cur_track); // Calculate absolute distance Distance = abs(cur_track - head); // Increase the total count Seek_count += distance; // Accessed track is now new head Head = cur_track; } // Once reached the right end // Jump to the beginning. Head = 0; // Adding seek count for head returning from 199 to 0 Seek_count += (disk_size - 1);
  • 24.
    // Now servicethe requests again // Which are left. For (int i = 0; i < left.Size(); i++) { Cur_track = left[i]; // Appending current track to seek sequence Seek_sequence.Push_back(cur_track); // Calculate absolute distance Distance = abs(cur_track - head); // Increase the total count Seek_count += distance; // Accessed track is now the new head Head = cur_track; } Cout << "total number of seek operations = "<< seek_count << endl; Cout << "seek sequence is" << endl; For (int i = 0; i < seek_sequence.Size(); i++) { Cout << seek_sequence[i] << endl; }} Int main() { int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 }; int head = 50; cout << "Initial position of head: " << head << endl; CSCAN(arr, head); return 0; }
  • 26.
    • Advantages • Workswell with moderate to heavy loads. • It provides better response time and uniform waiting time. • Disadvantages • If no requests remain to be serviced, the head will travel to the end of the disk. • It has more seek movements as compared to the scan algorithm.