Beruflich Dokumente
Kultur Dokumente
Nathan Adams
Sun Apr 16 23:28:47 CDT 2017
Chapter 1 - Introduction
Chapter 1.1 - Dedications
Chapter 1.2 - Copyright
Chapter 2 - Process Scheduling
Chapter 2.1 - First Come First Serve
Example 1
Example 2
Example 3
Example 4
Example 5
Exercise Problems
Chapter 2.2 - Shortest Job First (Non-Preemption)
Example 1
Example 2
Example 3
Example 4
Exercise Problems
Chapter 2.3 - Shortest Job First (Preemption)
Example 1
Example 2
Example 3
Example 4
Exercise Problems
Chapter 2.4 - Priority
Example 1
Example 2
Example 3
Example 4
Exercise Problems
Chapter 2.5 - Round Robin
Example 1
Example 2
Example 3
Example 4
Exercise Problems
Chapter 2.6 - Rate Monotonic
Example 1
Example 2
Exercise Problems
Chapter 2.7 - Earliest Deadline First
Example 1
Example 2
Exercise Problems
Chapter 3 - Resource Allocation Graph
Example 1
Example 2
Example 3
Exercise Problems
Problem 1
Problem 2
Chapter 4 - Disk Scheduling
Chapter 4.1 - First Come First Serve
Example 1
Example 2
Example 3
Exercise Problems
Chapter 4.2 - Shortest Seek Time First
Example 1
Example 2
Example 3
Exercise Problems
Chapter 4.3 - SCAN
Example 1
Example 2
Example 3
Exercise Problems
Chapter 4.4 - C-SCAN
Example 1
Example 2
Example 3
Exercise Problems
Chapter 4.5 - LOOK
Example 1
Example 2
Example 3
Exercise Problems
Chapter 4.6 - C-LOOK
Example 1
Example 2
Example 3
Exercise Problems
Chapter 5 - Solutions
Chatper 2.1 - FCFS
Chatper 2.2 - Short Job First (Non-Preemption)
Chatper 2.3 - Short Job First (Preemption)
Chatper 2.4 - Priority
Chatper 2.5 - Round Robin
Chapter 3 - Resource Allocation Graphs
Chapter 4.1 - FCFS
Chapter 4.2 - SSTF
Chapter 4.3 - SCAN
Chapter 4.4 - C-SCAN
Chapter 4.5 - LOOK
Chapter 4.6 - C-LOOK
Chapter 1 - Introduction
After teaching Operating Systems for several years, I have found a lack of
supporting material for the algorithms that are presented in Operating System
books.
The purpose of this book is not to replace current Operating System textbooks
or be a replacement for current Operating System Algorithm books. This book
is simply to augment them with more indepth step by step examples.
This book will not contain every algorithm known to mankind related to
operating systems - the basis for which algorithms that are present in this book
are ones that are presented in Operating System Concepts by Abraham
Silberschatz and Peter B. Galvin.
Please also contact me if you find something incorrect or dont agree with -
Im not a robot and I do make mistakes.
Please do NOT contact me for homework/class help unless you are willing to
pay a hourly fee (down payment is required before session begins). Requests
for free help will be promptly ignored and your email may be blacklisted.
Finally - please do not pirate this book. Instead, refer students to contact me
for a free digital copy.
If you want to fund future books or continuing support of this book, please feel
free to send donations to nathan [at] allostech.com or via Bitcoin -
1NHczVQN2hUAMXLGgXnniR3CRjQ9SGgyFn
Alex Larson - without his help with reviewing this book and helping me
with my other ventures, this book may never have come to fruition.
Dr. Ray Klump - amazing professor who gave me a chance to teach some
classes which gave me the inspiration to write this book.
Elisha Chirchir - helped me create the graphics for the disk scheduling
Dan Bewley and Eric Cedergren - some of my students who pointed out
some typos and mistakes in the book
Chapter 1.2 - Copyright
Operating System Algorithms
All rights reserved. No part of this book may be reproduced in any form or by
any electronic or mechanical means, including information storage and
retrieval systems, without permission in writing from the publisher, except by
reviewers, who may quote breif passages in a review.
ISBN 978-1-545146262
Visit https://allostech.com
Chapter 2 - Process Scheduling
A modern operating system needs a way to prioritize processes due to the
simple fact that there will probably be many different processes running at
once.
There are several algorithms that an operating system may use to schedule a set
of processes. They include:
Rate Monotonic
Earilest Deadline First
Example 1
When scheduling processes, we will use a gantt chart. A gantt chart is simply a
way to layout schedules in boxes. It is commonly used in software engineering
to plan projects and see if there are any overlapping task schedules which need
more resources.
In this book I lay out the gantt charts in a verbose way so you can see the
individual steps (or the work) taken to get to the final answer. You can skip to
the last step when you do the practice exercises if you find that is easier for
you.
We will begin scheduling with Process 1 and on the left we label 0 (because it
starts at time 0) then 24 on the right. In FCFS the algorithm states that the
process will run until it is finished. Process 1 has a burst time of 24 which is
why we put down 24 on the right.
Usually the reason why people perform a gantt chart like this is to determine
the average wait time (or AWT). The AWT is a metric that you can use to
determine how efficient an algorithm is. FCFS is similar to the bubble sort in
the sense that it is usually one of the worst performing algorithms. But it is
important to have a base to compare from.
To calculate AWT you just need to add up the times and divide by the number
of processes. In this example you just take 0 (which is the beginning of
scheduling), 24 (which is the end of Process 1), then finally 27 (which is the
end of Process 2). We do not factor in 30 (end of Process 3) because in this
example no other processes were waiting to run after Process 3. We will add
up those numbers and divide by 3 because there are 3 processes.
Example 2
In this example we will use the same process schedule but changed the order in
which the processes are scheduled. This will give you the ability to see how
the order of the processes will influence the AWT.
Just like above we start with Process 2 - starts at time 0 and runs its full burst
ending at time 3.
( 0 + 3 + 6) / 3 = 3ms AWT
Even though we used the same set of processes from the previous example, you
can see that changing the order of the processes will have an impact on the
AWT.
Example 3
( 0 + 8 + 13 ) / 3 = 7ms AWT
Example 4
( 0 + 5 + 13 ) / 3 = 6ms AWT
Example 5
( 0 + 3 + 8 ) / 3 = 3.667 ms AWT
Exercise Problems
Given the following process schedules, calculate the AWT.
Problem 1
Problem 2
Problem 3
For example if you have Process 1 with a burst time of 2, and Process 2 with a
burst time of 3 - the algorithm would schedule Process 2 first, then Process 1.
In the case of a tie the algorithms states to just use FCFS algorithm. In the
case of Process 1 and Process 2 with the burst time of 2 - using FCFS you
would schedule Process 1 then Process 2.
It is important to point out that there is another form of this algorithm which
uses preemption. Recall preemption is the idea where the operating system has
the ability to pause or stop a process in favor of another one.
Example 1
The first process to be scheduled would be Process 4 because its burst time is
the lowest (3) compared to the burst times of other processes.
Just like in FCFS, the process chosen will run through its full burst. The next
process to be scheduled would be Process 1 because its burst time is lower
than 8 and 7.
Please do note that we are dividing by 4 in this case because there are 4
processes
Example 2
Example 3
This is an interesting example because you can see that Process 1 and Process
4 share the same burst time (as well as the lowest).
From our previous example, according to the algorithm, the way we break this
tie is to use FCFS. So we would schedule Process 1 first then Process 4.
Example 4
Exercise Problems
Given the following process schedules, calculate the AWT.
Problem 1
Problem 2
Problem 3
Problem 4
For example - if a process has arrival time of 0 - this means it is the first
process running. If 2 processes both have the same arrival time then you will
use FCFS to break the tie.
Since a process can be preempted we need to take into account the arrival time
and finish when calculating the average wait time. This can easily be done by
applying the formula of:
Where F is the final time, A is the arrival time and B is the burst time.
Or more simply:
W(time) = ( F(inal) - A(rrival) ) - B(urst)
Or:
W = ( F - A ) - B
Where the Wait time is equal to the ( Finish - Arrival ) - Original Burst Time.
Perform this formula for each process, add them together, and divide by the
number of processes and you will get the average wait time. The reason we do
this is to take into account the arrival time. Lets examine the following
process schedule:
P1 will be scheduled first because its arrival is 0 even though its burst time is
higher than P2 - P2 wont appear to be scheduled for 8 ms right after P1 has
finished. Therefore, P2 did not need to wait to run so its awt is 0.
Then schedule P2
P1 wait time:
( 8 - 0 ) - 8 = 8 - 8 = 0
P2 wait time:
( 12 - 8 ) - 4 = ( 4 ) - 4 = 0
( 0 + 8 ) / 2 = 4ms
Which states that both processes had to wait on average 4ms to run which is
not correct.
Note: If you apply the formula and find that a process has a negative wait
time - then you applied the formula incorrectly. If a process has a negative
wait time it makes as much sense as a planet having negative moons.
Example 1
Examine the following process schedule:
At 1ms P1 will be preempted for P2 because P2s burst time is lower than P1s.
At this point you can imagine the process schedule to look like this:
Now examining the rest of the processes. At 2ms P3 will be introduced to the
operating system. At that time you can imagine the process schedule to look
like this:
You will notice that P3s burst time is higher than P2 so P2 will not be
preempted and P3 will have to wait to run. Looking ahead further to at time
3ms P4 -
P2 still has the lowest burst time compared to the other processes. P2 will run
its full burst and since the other processes have been submitted it becomes
SJFS (Non-preemption) with FCFS if there is a tie.
As you recall the formula for average wait time when using preemption is
Or:
W = ( F - A ) - B
P1w = ( 17 - 0 ) - 8 = 9
P2w = ( 5 - 1 ) - 4 = 0
P3w = ( 26 - 2 ) - 9 = 15
P4w = ( 10 - 3 ) - 5 = 2
Example 2
P1w = ( 19 - 0 ) - 8 = 11
P2w = ( 7 - 1 ) - 4 = 2
P3w = ( 4 - 2 ) - 2 = 0
P4w = ( 12 - 3 ) - 5 = 4
Example 3
In this example you will notice that P1s burst time is 5ms. If you look ahead
you will notice that if the 3 other processes are introduced then P1s burst time
is still the lowest.
Essentially for scheduling you can ignore the arrival time and treat it like a
normal SJFS but you must still apply the formula to determine the average wait
time.
Here is the resulting gantt chart:
P1w = ( 5 - 0 ) - 5 = 0
P2w = ( 12 - 1 ) - 7 = 4
P3w = ( 20 - 2 ) - 8 = 10
P4w = ( 29 - 3 ) - 9 = 17
AWT = ( 0 + 4 + 10 + 17 ) / 4 = 7.75ms
Example 4
However, when we reach P3 - P1s remaining burst time would be 6ms. P3 has
a burst time of 4 which is less than P1s remaining burst time. At this time P1 is
preempted in favor of P3.
When P4 is introduced P3s remaining burst time would be 3 which is less than
P4s burst time. So P3 would run through its full burst.
After that it becomes a simple SJFS where after P1 and P3 we then schedule P4,
the remainder of P1, and then finally P2.
P1w = ( 17 - 0 ) - 8 = 9
P2w = ( 26 - 1 ) - 9 = 16
P3w = ( 6 - 2 ) - 4 = 0
P4w = ( 11 - 3 ) - 5 = 3
AWT = ( 9 + 16 + 0 + 3 ) / 4 = 7ms
Exercise Problems
Given the following process schedules calculate the AWT.
Problem 1
Problem 2
Problem 3
Problem 4
As you can probably guess we introduce a new column called priority which
has a number value determining on the priority of the process.
Priority schedule does not have preemption so you can calculate the average
wait time using the same method in FCFS or SJFS (Non-preemption).
If there are 2 processes with the same priority then you would break the tie
using FCFS.
Example 1
If we assume that the lower number is the higher priority then we can see that
the first process to be scheduled would be P2 with a priority of 1.
There is no preemption so processes will run their full burst before the next
process is scheduled. And as a result of no preemption we do not use the
formula W = ( F - A ) - B from SJFS Preemption.
Example 2
Process Burst Time (ms) Priority
P1 4 1
P2 3 3
P3 2 4
P4 5 2
While this set of schedules only has 4 processes you apply the algorithm the
same way.
We will start with P1 because that has the highest priority (lowest number),
then P4, P2, and finally P3.
So in order:
Example 3
In this example we would schedule P3 first, then P2, P1, P4, and finally P5.
In order:
Example 4
Exercise Problems
Given the following process schedules calculate the AWT.
Problem 1
Problem 2
Problem 3
Problem 4
It works simply starting out like you would with FCFS - schedule the first
process on the list. However, if that process burst time is greater than the time
quantum then it is preempted for the next process. If the burst time is less than
or equal to the time quantum then it will run its full burst without being
preempted.
If a process burst time or remaining burst time is less than the time quantum it
will run its full burst and continue onto the next process. The algorithm will not
pad the difference. For example, if the time quantum was 3ms and the
process had a burst time of 2ms - the process would run for 2ms and continue
onto the next process without pausing for that extra 1ms.
Since this algorithm has the potential for preemption you must apply a
simplified version of the formula from SJFS preemption:
w = ( F - A ) - B
In round robin (at least in these examples) it has no concept of arrival - all
processes are assumed to arrive at the same time (so at time 0ms). This fact
allows you to simplify the formula to just:
Or:
w = F - B
Example 1
time quantum = 4ms
In this example we will start with P1 - but since its burst time is 24ms it will
be preempted when the time reaches 4ms to give 4ms of processor time to P2.
Since P2s burst time is 3ms which is less than or equal to the given time
quantum of 4ms it will run its full burst without being preempted. After that we
will schedule P3, but keep in mind P1 still has 20ms burst time left. P3 also has
a burst time 3 which means it will run its full burst. After P3 we will schedule
P1 in 4ms bursts.
P1w = 30 - 24 = 6
P2w = 7 - 3 = 4
P3w = 10 - 3 = 7
AWT = ( 6 + 4 + 7 ) / 3 = 5.66ms
Example 2
time quantum = 5ms
Process Burst Time (ms)
P1 10
P2 7
P3 5
In this example the time quantum is 5ms so we will schedule the first process
P1 for 5ms, preempted it for P2, and preempt P2 for P3 then the scheduling
would repeat back starting with P1.
P2w = 22 - 7 = 15
P3w = 15 - 5 = 10
AWT = ( 10 + 15 + 10 ) / 3 = 11.67ms
Example 3
time quantum = 4ms
P1w = 15 - 8 = 7
P2w = 8 - 4 = 4
P3w = 11 - 3 = 8
AWT = ( 7 + 4 + 8 ) / 3 = 6.33ms
Example 4
time quantum = 2ms
P1w = 12 - 5 = 7
P2w = 14 - 6 = 8
P3w = 11 - 3 = 8
AWT = ( 7 + 8 + 8 ) / 3 = 7.66ms
Exercise Problems
Given the following process schedules calculate the AWT.
Problem 1
Problem 2
Problem 3
Problem 4
I will say that Rate Monotonic and Earliest Deadline First can be confusing
due to the lack of information out there but I think the content in this book will
help you.
Before you even attempt to schedule Rate Monotonic you can apply a formula
to determine if the set of schedules can be scheduled with Rate Monotonic.
It is important to point out that if the formula passes - then the set of
processes can be scheduled with Rate Monotonic. If it fails - it is not a
guarantee that it cannot be scheduled. In order words its a way to prove
it can be scheduled rather than cant.
Its simply the sum of the burst times divided by the periods less than or equal
to n times (21/2 - 1).
One important note is that unlike the previous algorithms a real time algorithm
will continue forever. Even though the processes have a fixed burst time - their
period indicates that they will run again.
In rate Monotonic the shorter the period the higher the priority.
Example 1
In this example we only have 2 processes - P1 has a burst time of 20 and runs
every 50 ms and P2 has a burst time of 35 ms and a period of 100 ms.
That means that P1 needs to run for a total of 20 ms every 50 ms and P2 needs
to run for 35 ms every 100 ms.
Lets apply the formula to determine if we can schedule this set of processes
using Rate Monotonic (keeping in mind that if the formula fails that it may still
be schedulable).
Or
.75 .828
So yes this should be schedulable. So lets take a look at the gantt chart starting
with P1. P1 has a burst time of 20 ms.
Then we will schedule P2 with a burst time of 35 ms.
Hopefully you will notice that we stopped short at 50 ms. The reason for this is
due to the fact that the period for P1 is 50 ms which is less than P2s period of
100 ms. This gives priority to P1. So we preempt P2 with a remaining burst
time of 5 ms. So we schedule P1:
Example 2
Again lets apply the formula as a check to see if this can be scheduled:
.725 .77976
And finally P3. So far so good - we were able to schedule all 3 processes
within in their periods. And no processes were overlapping which would
require us to determine if a process needs to be preempted.
It just happens that at time 5 ms is when P2 will begin its next period so we
schedule that. P2 has a burst time of 2 ms which puts us at 7 ms.
The next process that will run is P1 at time 8 ms (its period is 8 ms). But we
are current at time 7 ms - so we have dead time for 1 ms. After the dead
time we can schedule P1.
Exercise Problems
Given the following process schedules determine if you can schedule it with
Rate Monotonic scheduling.
Remember: Just because the formula fails doesnt mean that you cant
schedule it
Problem 1
Problem 2
Process Burst Time (ms) Period (ms)
P1 4 20
P2 2 8
P3 2 10
Chapter 2.7 - Earliest Deadline First
Earliest Deadline First (or EDF) is a dynamic scheduling algorithm. Compared
to RMS (or Rate Monotonic Scheduling) which is a static scheduling
algorithm.
Its similar to the formula for Rate Monotonic where C is the burst times, t is
the priod and n is the number of processes - but in this case you are comparing
against 1.
The technical difference between the two algorithms is that RMS will assign a
priority based on the shortest period, EDF will dynamically determine priority
based on the earliest deadline.
Example 1
The process that we will schedule first is P2 because its period is the shortest
among the 3 processes.
And finally P3. But, do take note that scheduling P3 will overlap the period for
P2 (before we schedule P3 we are at time 3 ms - scheduling P3 would put us at
time 7 ms). The question should arise if we should preempt P3 for P2? At this
time the answer is no. Simply because P3 and P2 both have the same next
periods so a tie occurs and the way we break ties in previous algorithms is to
use FCFS. In this case, P3 will not be preempted and run its full burst.
The next process that we will schedule would be P2. Its period was at 5 ms but
P3 ran and was not preempted. P2 will run its full burst and not be preempted.
At this point you should notice that P2 crosses over P1s period. But P2 was not
preempted because its deadline is closer than P1.
After scheduling P1 this will put us at time 10 ms. Both P2 and P3 have the
same period, however, P2s period is shorter so we schedule that first then P3.
Example 2
.9375 1
To start we will schedule P1 because its next period is sooner than P2. (50 vs
80)
Next we will schedule P2. P2 will cross over into P1s period but this will not
preempt P2. The reason is because P2s next period is 80 vs P1s of 100. So P2
will run its full burst.
At this point we will schedule P1. It will cross into the deadline of P2 but it
will not be preempted because P1s next deadline is 100 vs P2s of 160.
And finally we will end this example showing that after finishing the rest of the
burst from the preempted P2 - there is some dead time.
Exercise Problems
Given the following process schedules, determine if you can schedule it with
Earliest Deadline First scheduling.
Problem 1
Problem 2
They are very easy to read and interpret. The important thing to remember is
that a cycle is an indication of a deadlock but is not a guarantee.
In a resource allocation graph, a process can hold and request any number
of resources. Processes are denoted using a circle. Resources are denoted
using a square with a number of dots on the inside related to the count of slots
that the resource has (for example - a CD Rom driver might control multiple
CD-ROMs).
R1 -> 1
P2 -> 1
The resource allocation graph in this case would look like the following:
R1 -> 1
R2 -> 1
R1 -> 2
R2 -> 2
P1 holds R2 requesting R1
P2 holds R1
P3 holds R1 requesting R2
P4 holds R2
In this example we have a cycle of:
But this is not a deadlock because P2 can finish and release R1 allowing P1 to
finish or P4 can finish and release R2 allowing P3 to finish.
Exercise Problems
Given the following scenarios determine if there is a dead lock using a
resource allocation graph.
Problem 1
R1 -> 1
R2 -> 2
R3 -> 1
R3 -> 3
P1 holds R2 requesting R1
P2 holds R2 + R1 requesting R3
P3 holds R3
Problem 2
R1 -> 1
R2 -> 2
R3 -> 1
R3 -> 3
P1 holds R2 requesting R1
P2 holds R2 + R1 requesting R3
P3 holds R3 requesting R2
Chapter 4 - Disk Scheduling
Hard disk technology has changed over the years. The technology that I grew
up with involved an arm and spinning platters. The idea was that a platter was
divided into tracks, then a track is divided up into sectors. Many of these
drives would spin at 5400, 7200, 10000, and even 15000RPM.
However, with the introduction of solid state disk (SSD) really changed the
hard disk as we knew it. There is no longer a spinning media (and as a result
the algorithms may not apply) and data access times are almost instant.
Just like the process scheduling algorithms - the following algorithms were
designed to try to access data in the quickest and most efficient way possible.
The resulting calculation of these algorithms is called total head movements.
This is a number that represents the total number of the movements the head
would make if it was accessing data in a real hard drive.
These algorithms will always state the starting position of the head - but it will
sometimes state the beginning and end positions.
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
To calculate the total head movements we will add up the distances between
when the line changes direction.
| 183 - 53 | = 130
| 183 - 37 | = 146
| 122 - 37 | = 85
| 122 - 14 | = 108
| 124 - 14 | = 110
| 124 - 65 | = 59
| 65 - 67 | = 2
= 640 total head movements
Example 2
queue = 23, 89, 132, 42, 187
start = 100
| 100 - 23 | = 77
| 132 - 23 | = 109
| 132 - 42 | = 90
| 187 - 42 | = 145
= 421 total head movements
Example 3
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
| 180 - 50 | = 130
| 180 - 34 | = 146
| 119 - 34 | = 85
| 119 - 11 | = 108
| 123 - 11 | = 112
| 123 - 62 | = 61
| 64 - 62 | = 2
= 644 total head movements
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
A quick example: if the head is currently at 100 and 30, 101, 104 are in the
queue it will service 101, 104, then 30.
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
The easiest way to determine which is the closest request is to put the requests
in order:
The starting position is 53 and it is closest to 65. To show this you take 53 and
subtract from the request. So the 2 that are closest to 53 is 37 and 65. | 53 - 37 |
= 26 and | 53 - 65 | = 12 . So the algorithm will start at 65 and service the next
closest which would be 67, then 37, 14, 98, 122, 124 and finally 183.
| 53 - 67 | = 14
| 67 - 14 | = 53
| 183 - 14 | = 169
= 236 total head movements
Example 2
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
| 50 - 64 | = 14
| 64 - 11 | = 53
| 180 - 11 | = 169
= 236 total head movements
Example 3
queue = 23, 89, 132, 42, 187
start = 100
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
For example if the head is currently at 180 - it will go to 199 and service all
requests in that direction.
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
end = 199
| 53 - 0 | = 53
| 183 - 0 | = 183
= 236 total head movements
Example 2
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
end = 199
| 50 - 0 | = 50
| 180 - 0 | = 180
= 230 total head movements
Example 3
queue = 23, 89, 132, 42, 187
start = 100
end = 199
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
For example if the head starts at 100 - it will service all requests down to 0.
But then jump up to 199 and service all requests going back down to 0. You
should not include the distance of the jump in the total head movements.
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
end = 199
Since the head starts at position 53 it will go towards 0 again but after it hits 0
it will jump directly to 199.
14, 37, 65, 67, 98, 122, 124, 183
| 53 - 0 | = 53
| 199 - 65 | = 134
= 187 total head movements
Example 2
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
end = 199
| 50 - 0 | = 50
| 199 - 62 | = 137
= 187 total head movements
Example 3
queue = 23, 89, 132, 42, 187
start = 100
end = 199
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
end = 199
Since the head starts at position 53 it will go towards 0 but stop at the lowest
request (14) then head towards the highest request servicing the other requests
along the way.
14, 37, 65, 67, 98, 122, 124, 183
| 53 - 14 | = 39
| 183 - 14 | = 169
= 208 total head movements
Example 2
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
end = 199
| 50 - 11 | = 39
| 180 - 11 | = 169
= 208 total head movements
Example 3
queue = 23, 89, 132, 42, 187
start = 100
end = 199
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
Example 1
queue = 98, 183, 37, 122, 14, 124, 65, 67
start = 53
end = 199
Since the head starts at position 53, it will go towards 0 but stop at the lowest
request (14) then jump up to 183 and travel towards 0 servicing the requests
along the way and stopping at 65. In some versions of the algorithm they may
include the cost of the jump however we would argue you wont because
you wont service requests in the jump.
14, 37, 65, 67, 98, 122, 124, 183
| 53 - 14 | = 39
| 183 - 65 | = 118
= 157 total head movements
Example 2
queue = 95, 180, 34, 119, 11, 123, 62, 64
start = 50
end = 199
| 50 - 11 | = 39
| 180 - 62 | = 118
= 157 total head movements
Example 3
queue = 23, 89, 132, 42, 187
start = 100
end = 199
Circular scanning works just like the elevator to some extent. It begins its scan
toward the nearest end and works it way all the way to the end of the system.
Source: http://www.cs.iit.edu/~cs561/cs450/disksched/disksched.html
Exercise Problems
Problem 1
Problem 2
Problem 3
Problem 4
1. 6
2. 9
3. 4.3
4. 6.33
1. 11.25
2. 17.25
3. 4
4. 4.5
1. 3.75
2. 3.5
3. 3.25
4. 5.75
1. 12.67
2. 12.67
3. 11.67
4. 12.67
1. No deadlock
2. Deadlock
1. 310
2. 520
3. 410
4. 406
1. 134
2. 137
3. 147
4. 118
1. 156
2. 145
3. 151
4. 134
1. 187
2. 178
3. 196
4. 187
1. 134
2. 137
3. 141
4. 121