0% found this document useful (0 votes)
34 views

Expt 6 Disk Scheduling Lab

The document describes simulations of three disk scheduling algorithms: FCFS, SCAN, and C-SCAN. It includes the aim to simulate these algorithms, descriptions of how disk drives are organized and how requests are queued, and high-level descriptions of each algorithm along with example code, inputs, and outputs of the simulations.

Uploaded by

ahmad ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Expt 6 Disk Scheduling Lab

The document describes simulations of three disk scheduling algorithms: FCFS, SCAN, and C-SCAN. It includes the aim to simulate these algorithms, descriptions of how disk drives are organized and how requests are queued, and high-level descriptions of each algorithm along with example code, inputs, and outputs of the simulations.

Uploaded by

ahmad ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Experiment 6

Aim: To simulate the following disk scheduling algorithms.


a) FCFS
b) SCAN
c) C-SCAN

Description

Magnetic disks are made of disk platters. Each disk platter is circular in shape. The read-write heads
lie slightly above each platter. The heads are all attached to a disk arm that moves all the heads as a
unit. The surface of the platter is logically divided into circular tracks. Each track is divided into
sectors. All tracks at one arm position make up a cylinder. A disk drive may have thousands of such
cylinders and each track may contain hundreds of sectors. Seek time is the time necessary to move
the disk arm to the desired cylinder. The time necessary for the desired sector to rotate to the disk-
head is called rotational latency. The access time can be improved by managing the order in which
disk I/O requests are serviced.

Whenever a process needs I/O to or from the disk, it issues a system call to the operating system. If
the desired disk drive and controller are available, the request can be serviced immediately. If the
drive or controller is busy, any new requests for service will be placed in the queue of pending
requests for that drive. For a multiprogramming system with many processes, the disk queue may
often have several pending requests. Thus, when one request is completed, the operating system
chooses which pending request to service next. How the operating system makes the next request
depends on any one of several disk-scheduling algorithms

a) FCFS Scheduling (First come first served)

This is the simplest form of disk scheduling. This algorithm however, does not provide the fastest
service.

Algorithm
1. Create arrays to store track numbers and distances.

2. Read start address of head and save it as the first element of track array.

3. Read remaining track numbers from user and store them in the remaining elements of the
track array.

4. Find the difference between two adjacent elements of track array and store the absolute value
in distance array. Each element of the distance array gives movement distance between two
ordered tracks.

5. Calculate average movement by dividing the sum of movement by number of tracks.

Program

Output
anil@anil-300E4Z-300E5Z-300E7Z:~/System Software lab/expts_program$ ./expt_6_fcfs

Enter head number:55


Enter number of tracks:9
Enter track number one by one:58
60
70
18
90
150
160
184
average header movement = 29.12 tracks
Tracks Distance
55
58 3
60 2
70 10
18 52
90 72
150 60
160 10
184 24

b) SCAN

SCAN scheduling

In the SCAN algorithm, the disk arm starts at one end of the disk and moves toward the other end,
servicing requests as it reaches each cylinder, until it gets to the other end of the disk. At the other
end, the direction of head movement is reversed, and servicing continues. The head continuously
scans back and forth across the disk.

Algorithm

1. Create arrays to store track numbers and distances.

2. Read start address of head and save it as the first element of track array.

3. Read remaining track numbers from user and store them in the remaining elements of the
track array.

4. Sort tracks in ascending order

5. Find the position of the head in track array

6. Arrange in descending order track number below head

7. Shift the track numbers to the right by one


8. Place head as first position in track array and insert 0 in previous head position in track array

4. Find the difference between two adjacent elements of track array and store the absolute value
in distance array. Each element of the distance array gives movement distance between two
ordered tracks.

5. Calculate average movement by dividing the sum of movement by number of track movements.

Output

anil@anil-300E4Z-300E5Z-300E7Z:~/System Software lab/expts_program$ ./expt_6_b_scan

Enter head number:53


Enter number of tracks:9
Enter track number one by one:98
183
37
122
14
124
65
67
average header movement = 26.22 tracks
Tracks Distance
53
37 16
14 23
0 14
65 65
67 2
98 31
122 24
124 2
183 59

c) C-SCAN
Circular SCAN ( C-SCAN ) scheduling is a variant of SCAN designed to provide a more uniform
wait time. Like SCAN , C-SCAN moves the head from one end of the disk to the other, servicing
requests along the way. When the head reaches the other end, however, it immediately returns to the
beginning of the disk without servicing any requests on the return trip.

Algorithm

1. Create arrays to store track numbers and distances.

2. Read start address of head and save it as the first element of track array.

3. Read the total number of tracks

4. Read remaining track numbers from user and store them in the remaining elements of the
track array.

4. Sort tracks in ascending order

5. Find the position of the head in track array

6. Insert total number of tracks -1 at the end of the array

7. Insert 0 at the end of the array

8. Attach track numbers below head to the end of the array

9. Shift the track numbers to the left by the position of head

10. Find the difference between two adjacent elements of track array and store the absolute value
in distance array. Each element of the distance array gives movement distance between two
ordered tracks.

11. Calculate average movement by dividing the sum of movement by number of track movements.

Program

Output

anil@anil-300E4Z-300E5Z-300E7Z:~/System Software lab/expts_program$ ./expt_6_c_cscan

Enter head number:53


Enter number of tracks:9
Enter total number of tracks:200
Enter track number one by one:98
183
37
122
14
124
65
67
average header movement = 38.20 tracks
Tracks Distance
53
65 12
67 2
98 31
122 24
124 2
183 59
199 16
0 199
14 14
37 23

You might also like