Upload
ledan
View
234
Download
0
Embed Size (px)
Citation preview
1
Fundamentals of Operating
Systems (COMP355/L)
A Student's Manual
for Practice Exercises
Text Book: Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Practice Exercises #1 Chapter 1 Introduction Page 2
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Practice Exercises #1 Introduction
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
define an operating system,
define the tasks of an operating system and its elements
1. What is an operating system?
2. What are the operating system goals?
3. What are the main components of a computer system?
Questions
Practice Exercises #1 Chapter 1 Introduction Page 3
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
4. What are the three main purposes of an operating system?
5. We have stressed the need for an operating system to make efficient use of the computing
hardware. When is it appropriate for the operating system to forsake this principle and to “waste”
resources? Why is such a system not really wasteful?
6. What is the main difficulty that a programmer must overcome in writing an operating system for a
real-time environment?
Practice Exercises #1 Chapter 1 Introduction Page 4
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
7. How does the distinction between kernel mode and user mode function as a rudimentary form of
protection (security) system?
8. Which of the following instructions should be privileged?
a. Set value of timer.
b. Read the clock.
c. Clear memory.
d. Issue a trap instruction.
e. Turn off interrupts.
f. Modify entries in device-status table.
g. Switch from user to kernel mode.
h. Access I/O device.
9. Some early computers protected the operating system by placing it in a memory partition that
could not be modified by either the user job or the operating system itself. Describe two difficulties
that you think could arise with such a scheme.
Practice Exercises #1 Chapter 1 Introduction Page 5
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
10. Some CPUs provide for more than two modes of operation. What are two possible uses of these
multiple modes?
11. Timers could be used to compute the current time. Provide a short description of how this could
be accomplished.
Practice Exercises #1 Chapter 1 Introduction Page 6
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
12. Answer to the following questions:
a. Give two reasons why caches are useful.
b. What problems do they solve?
c. What problems do they cause?
d. If a cache can be made as large as the device for which it is caching (for instance, a cache as
large as a disk), why not make it that large and eliminate the device?
Practice Exercises #2 Chapter 2 Operating-System Structures Page 7 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #2 Operating-System Structures
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
To describe the services an operating system provides to users, processes, and other systems
To discuss the various ways of structuring an operating system
To explain how operating systems are installed and customized and how they boot
1. What are the fundamental approaches for users to interface with the operating system. Explain these
approaches briefly.
2. What is the purpose of system calls?
Exercises
Practice Exercises #2 Chapter 2 Operating-System Structures Page 8 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
3. What are the five major activities of an operating system with regard to process
management?
4. What are the three major activities of an operating system with regard to memory
management?
5. What are the three major activities of an operating system with regard to secondary-
storage management?
Practice Exercises #2 Chapter 2 Operating-System Structures Page 9 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
6. What is the purpose of the command interpreter? Why is it usually separate from the
kernel?
7. What system calls have to be executed by a command interpreter or shell in order to
start a new process?
8. What is the purpose of system programs?
Practice Exercises #2 Chapter 2 Operating-System Structures Page 10 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
9. What is the main advantage of the layered approach to system design?
10. List five services provided by an operating system, and explain how each creates
convenience for users. In which cases would it be impossible for user-level programs
to provide these services? Explain your answer.
Practice Exercises #2 Chapter 2 Operating-System Structures Page 11 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
11. Why do some systems store the operating system in firmware, while others store it
on disk?
12. How could a system be designed to allow a choice of operating systems from which
to boot?
What would the bootstrap program need to do?
13. What is the bootstrap program?
Practice Exercises #2 Chapter 2 Operating-System Structures Page 12 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
14. Operating systems provide an environment for execution of programs and services to
programs and users. Fill in the following table with the appropriate OS service
description.
# Operating
System Services Description
1. User interface
2. Program execution
3. I/O operations
4. File-system
manipulation
5. Communications
6. Error detection
7. Resource allocation
8. Accounting
9. Protection and
security
Practice Exercises #3 Chapter 3 Processes Page 13 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #3 Processes
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
To introduce the notion of a process -- a program in execution, which forms the basis of all
computation
To describe the various features of processes, including scheduling, creation and termination, and
communication
To explore inter-process communication using shared memory and message passing
1. What is a process?
2. What are the main components of a process?
Exercises
Practice Exercises #3 Chapter 3 Processes Page 14 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
3. What is the difference between a program and a process?
4. What are the used technics for loading executable files?
5. What are the process states?
6. What is a process control block (PCB)?
Practice Exercises #3 Chapter 3 Processes Page 15 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
7. A PCB contains many pieces of information associated with a specific process. State
some of these pieces of information?
Practice Exercises #3 Chapter 3 Processes Page 16 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
8. What is the objective of multiprogramming?
9. What is the objective of time sharing?
10. How the objective of time sharing can be met?
11. What is a job queue?
Practice Exercises #3 Chapter 3 Processes Page 17 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
12. What is a ready queue? Where is stored? What does it contain?
13. What is a queueing diagram? Describe it briefly.
14. Describe process scheduling.
Practice Exercises #3 Chapter 3 Processes Page 18 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
15. What is the difference between I/O-bound and CPU-bound processes?
16. How the number of the I/O-bound and CPU-bound processes should selected by the long-
term scheduler? Justify your answer.
Practice Exercises #3 Chapter 3 Processes Page 19 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
17. Fill in the following table with the words "high" or "low".
Process Type Spent Time on I/O Spent Time on Computations
I/O-bound process
CPU-bound process
Practice Exercises #4 Chapter 4 CPU Scheduling Page 20 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #4 CPU Scheduling
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
introduce CPU scheduling, which is the basis for multiprogrammed operating systems
describe various CPU-scheduling algorithms
discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system
examine the scheduling algorithms of several operating systems
1. How many processes can run at a time in a single-processor system?
2. What is the objective of multiprogramming?
Exercises
Practice Exercises #4 Chapter 4 CPU Scheduling Page 21 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
3. A process is executed until it must wait, typically for the completion of some I/O request.
a. What happens in such situation in a simple computer system?
b. What happens in such situation in a multiprogramming system?
4. Almost all computer resources are scheduled before use. The CPU is, of course, one of the
primary computer resources. How scheduling is assured?
5. Process execution consists of some operations.
a. What are they?
b. How are they organized?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 22 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
6. Let's consider the Histogram of CPU-burst durations depicted in the following figure:
a. What is the type of the Histogram of CPU-burst durations?
b. Describe short and long CPU bursts.
(Source: Operating System Concepts – 9th
Edition)
Practice Exercises #4 Chapter 4 CPU Scheduling Page 23 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
c. Describe the distribution of short and long CPU bursts in I/O-bound and CPU-
bound programs.
d. What is the importance of this distribution?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 24 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
7. Let's consider the case when the CPU becomes idle.
a. From where the operating system must select one of the processes ?
b. What is the role of short-term scheduler?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 25 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
8. Under which circumstances, CPU-scheduling decisions may take place? When there is a
choice for scheduling?
9. When can we say that the scheduling scheme is nonpreemptive or cooperative?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 26 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
10. When can we say that the scheduling scheme is preemptive?
11. Explain nonpreemptive scheduling.
12. What are the disadvantages of preemptive scheduling? Give some examples.
Practice Exercises #4 Chapter 4 CPU Scheduling Page 27 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
13. What is a dispatcher? What are its functions?
14. What is a dispatch latency?
15. What are the criteria for comparing CPU scheduling algorithm?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 28 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
16. Explain how the criteria for comparing CPU scheduling algorithm should be manipulated?
Practice Exercises #4 Chapter 4 CPU Scheduling Page 29 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
17. What is CPU scheduling?
18. State the most important scheduling algorithms in a system with a single processor.
Practice Exercises #5 Chapter 5 Deadlocks Page 30 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #5 Deadlocks
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
identify system resources,
identify system resources types,
define deadlock conditions
1. A system consists of a finite number of resources to be distributed among a number of
competing processes. The resources are partitioned into several types. State some examples of these
types.
2. A system consists of a finite number of resources to be distributed among a number of
competing processes. The resources are partitioned into several types. State some examples of these
types. Each consisting of some number of identical instances. State an example of these instances.
3. If a process requests an instance of a resource type, then the allocation of any instance of the
type will satisfy the request. If it will not, then what can you conclude?
Exercises
Practice Exercises #5 Chapter 5 Deadlocks Page 31 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
4. What are the events with which we are mainly concerned when we are with deadlocks?
5. When can we say that a set of processes is in a deadlock state?
6. What type of resources can we have in a system?
7. When a deadlock situation can arise?
Practice Exercises #6 Chapter 5 Deadlocks Page 32 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #6 Deadlock Avoidance Safe State
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
define the conditions of safe and unsafe system
apply the safe and unsafe conditions to examine and identify the state of the system
(safe or unsafe),
define deadlock conditions
A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still
avoid a deadlock.
More formally, a system is in a safe state only if there exists a safe sequence.
A sequence of processes is a safe sequence for the current allocation state if, for each , the
resource requests that can still be satisfied by the currently available resources plus the resources held by all
, with . In this situation, if the resources that needs are not immediately available, then , can wait
until all have finished.
When they have finished, can obtain all of its needed resources, complete its designated task, return its
allocated resources, and terminate. When , terminates, can obtain its needed resources, and so on.
If no such sequence exists, then the system state is said to be unsafe.
Figure 1 Safe, unsafe, and deadlock state spaces
Reminder
Exercises
Practice Exercises #6 Chapter 5 Deadlocks Page 33 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
1. Consider a system with 12 magnetic tape drives and three processes: . The
maximum needs by these processes is depicted in the following table.
Suppose that, at time , these are holding number of tape drives depicted in this table (Thus, there are
3 free tape drives).
a. Explain the state of the system (safe or unsafe) at time . Justify your answer and fill in the
following table.
Processes Maximum Needs Current Needs at Allocated Resources at Available Resources at
4 2
10 5
9 2
Available Tapes: At time , the system is in ______________ state
Processes Maximum Needs Current Needs at Current Needs at
10 5 5
4 2 2
9 2 3
Exercises
Practice Exercises #6 Chapter 5 Deadlocks Page 34 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
b. System at time
Suppose that, at time process requests and is allocated one more tape drive (3).
Processes Maximum Needs Current Needs at Allocated Resources at Available Resources at
10 2
4 5
9 3
Available Tapes: At time , the system is in ______________ state
c. What can you deduce?
Practice Exercises #6 Chapter 5 Deadlocks Page 35 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
2. Consider a system with 12 magnetic tape drives and three processes: . The
maximum needs by these processes is depicted in the following table.
Suppose that, at time , these are holding number of tape drives depicted in this table (Thus, there are
3 free tape drives).
Processes Maximum Needs Current Needs at Current Needs at
10 5 5
4 2 2
9 2 3
d. System at time
At time , the system is in a safe state. The sequence satisfies the safety condition.
Process can immediately be allocated all its tape drives and then return them (the system will then
have 5 available tape drives); then process can get all its tape drives and return them (the system
will then have 10 available tape drives); and finally process can get all its tape drives and return
them (the system will then have all 12 tape drives available).
Processes Maximum
Needs
Current Needs at
Will need Available Resources after allocation
4 2 2 (3-2)+4=5
10 5 5 (5-5)+10=10
9 2 7 (10-7)+9=12
Available Tapes: 3 The sequence t time , the
system is in safe state
e. System at time
Suppose that, at time process requests and is allocated one more tape drive (3).
Processes Maximum
Needs
Current Needs at
Will need
(max –current)
current
Available Resources after allocation
(available-wneed)+max
4 2 2 (2-2)+4=4
10 5 5 needs 5 so cannot be satisfied
9 3 6 needs 6 so cannot be satisfied
Available Tapes: 2 The sequence t time , the
system is in unsafe state
Exercises
Practice Exercises #6 Chapter 5 Deadlocks Page 36 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
(*) The system is no longer in a safe state. At this point, only process
, can be allocated all its tape drives. When it returns them, the system will have only 4 available
tape drives.
Since process , is allocated 5 tape drives but has a maximum of 10, it may request 5 more tape
drives. Since they are unavailable, process must wait.
Similarly, process may request an additional 6 tape drives and have to wait, resulting in a
deadlock.
f. What can you deduce?
The mistake was in granting the request from process for one more tape drive. If we had made
wait until either of the other processes had finished and released its resources, then we could have
avoided the deadlock.
Practice Exercises #6 Chapter 5 Deadlocks Page 37 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #7 Banker's Algorithm
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
Apply Banker's algorithm (Deadlock-avoidance algorithm)
Apply Safety Algorithm for finding out whether or not a system is in a safe state
Apply Resource-Request Algorithm which determines if requests can be safely granted.
1. Consider the following snapshot at for a system that has the following resources depicted in
the following table:
# of Instances
Resource
# of Instances
9 4 6
And the following processes de depicted in the following table:
Processes
Current
Allocation
Maximum
Need
Current
Need
(Max-
Current)
(shown
in order)
Work+Allocation
(According to sequence)
A B C A B C A B C Total A B C
3 0 1 4 2 3 1 2 2 F 3 T 534+301=835 8 3 5
1 1 1 7 2 2 6 1 1 F 4 T 835+111=946 9 4 6
2 2 0 3 3 1 1 1 1 F 2 T 314+220=534 5 3 4
2 1 2 3 1 3 1 0 1 F 1 T 102+212=314 3 1 4
Total 8 4 4
Current Available = 946-844=102
Work=Available= 102
Current Available= 946-844=102
Work=Available=102
Exercises
Practice Exercises #6 Chapter 5 Deadlocks Page 38 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
: 102+212=314
: 314+220=534
: 534+301=835
: 835+111=946
The system is safe at because there is a safety sequence
2. Can the request (1,0,1) by be granted at ? Justify your answer.
(True) (
(True) (
Available=Available- = 102-101=001
= - = 101-101=000
= = 212+101=313
Work=Available= 001
Processes
Current
Allocation
Maximum
Need
Current
Need
(Max-
Current)
(shown in
order)
Work+Allocation
(According to sequence)
A B C A B C A B C Total
A B C
3 0 1 4 2 3 1 2 2 F 3 T 534+301=835 8 3 5
1 1 1 7 2 2 6 1 1 F 4 T 835+111=946 9 4 6
2 2 0 3 3 1 1 1 1 F 2 T 314+220=534 5 3 4
3 1 3 3 1 3 0 0 0 F 1 T 001+313=314 3 1 4
The request (1,0,1) by can be granted at because the system will remain safe. The safety
sequence is
Practice Exercises #6 Chapter 5 Deadlocks Page 39 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
New Exercise
1. Consider the following snapshot at for a system that has the following resources depicted in
the following table:
# of Instances
Resource
# of Instances
10 5 7
And the following processes de depicted in the following table:
Processes
Current
Allocation
Maximum
Need
Current
Need
(Max-
Current)
(shown
in order)
Work+Allocation
(According to sequence)
A B C A B C A B C Total A B C
0 1 0 7 5 3 7 4 3 F
2 0 0 3 2 2 1 2 2 F
3 0 2 9 0 2 6 0 0 F
2 1 1 2 2 2 0 1 1 F
Total 7 2 3
Current Available = 1057-723=334
Work=Available= 334
Current Available= 946-844=102
Work=Available=102
Practice Exercises #6 Chapter 5 Deadlocks Page 40 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
2-
requests [3,3,0]
Processes
Current
Allocation
Maximum
Need
Current
Need
(Max-
Current)
(shown
in order)
Work+Allocation
(According to sequence)
A B C A B C A B C Total A B C
0 1 0 7 5 3 7 4 3 F
2 0 0 3 2 2 1 2 2 F
3 0 2 9 0 2 6 0 0 F
5 4 1 2 2 2 0 1 1 F
Total 8 4 2
Current Available = 1057-842=215
Work=Available= 215
Practice Exercises #7 Chapter 5 Deadlocks Page 41 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
Assignment #7 Resource-Allocation and Wait-for Graphs
STUDENT LEARNING OUTCOMES:
Upon completion of this assignment, a successful student will be able to:
examine and investigate deadlock detection algorithms,
identify the different used methods to detect deadlocks,
apply deadlock detection algorithms and methods to determine the presence of deadlocks
identify the conditions which should be provided in order to draw the corresponding wait-for
graph
use wait-for graph to determine the presence or the absence of deadlocks in a system
Deadlock Detection Algorithm
If all resources have only a single instance, then we can define a deadlock detection algorithm that
uses a variant of the resource-allocation graph, called a wait-for graph.
We obtain this graph from the resource-allocation graph by removing the resource nodes and
collapsing the appropriate edges.
As before, a deadlock exists in the system if and only if the wait-for graph contains a cycle.
To detect deadlocks, the system needs to maintain the wait-for graph and periodically invoke an
algorithm that searches for a cycle in the graph.
An algorithm to detect a cycle in a graph requires an order of operations, where n is the number of
vertices in the graph.
1. We propose that all resources have only a single instance, then we can define a deadlock
detection algorithm that uses a variant of the resource-allocation graph, called a wait-for
graph.
a. What are the conditions which should be verified in order to draw this Resource-Allocation
Graph the corresponding Wait-for Graph.
b. If the conditions are verified, draw the corresponding Wait-for Graph
c. Write the cycles.
Observations
Wait-For Graph (WFG) is the same as the RAG with the resource elements stripped out.
Reminder
Practice Exercises #7 Chapter 5 Deadlocks Page 42 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
The cycles can be seen more clearly in this form of the graph.
There is deadlock in the system if and only if there exists a cycle or a knot in the wait-for-graph.
With about half the number of nodes and edges, the WFG requires only about half the storage of a
SRAG.
However, WFGs can only be used for SRAGs with single-instance resources.
Resources for SRAGs can have any number of instances; However, one cannot create WFGs from
these.
1. We propose the following resource-allocation graph, and we also propose that all resources have
only a single instance.
Resource-Allocation Graph
a. State the conditions which should be provided in order to draw the corresponding wait-for
graph?
Exercises
Practice Exercises #7 Chapter 5 Deadlocks Page 43 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
b. If these condition are provided draw the corresponding wait-for graph?
c. State the cycles if they exist.
d. What can you conclude?
Practice Exercises #7 Chapter 5 Deadlocks Page 44 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
2. We propose the following resource-allocation graph, and we also propose that all resources have
only a single instance.
Resource-Allocation Graph
a. State the conditions which should be provided in order to draw the corresponding wait-for
graph?
b. If these condition are provided draw the corresponding wait-for graph?
Practice Exercises #7 Chapter 5 Deadlocks Page 45 `
Dr. Mohamed Aissa Student's Manual for Practice Exercises COMP355 Fundamentals of Operating Systems
c. State the cycles if they exist.
d. What can you conclude?