• 沒有找到結果。

OPERATING SYSTEM CONCEPTS

N/A
N/A
Protected

Academic year: 2022

Share "OPERATING SYSTEM CONCEPTS"

Copied!
120
0
0

加載中.... (立即查看全文)

全文

(1)

INSTRUCTOR’S MANUAL TO ACCOMPANY

OPERATING SYSTEM CONCEPTS

SIXTH EDITION

ABRAHAM SILBERSCHATZ Bell Laboratories PETER BAER GALVIN Corporate Technologies GREG GAGNE Westminster College

Copyright c 2001 A. Silberschatz, P. Galvin and Greg Gagne

(2)
(3)

PREFACE

This volume is an instructor’s manual for the Sixth Edition of Operating-System Concepts by Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne. It consists of answers to the exercises in the parent text. In cases where the answer to a question involves a long program, algorithm development, or an essay, no answer is given, but simply the keywords “No Answer” are added.

Although we have tried to produce an instructor’s manual that will aid all of the users of our book as much as possible, there can always be improvements (improved answers, additional questions, sample test questions, programming projects, alternative orders of presentation of the material, additional references, and so on). We invite you, both instructors and students, to help us in improving this manual. If you have better solutions to the exercises or other items which would be of use with Operating-System Concepts, we invite you to send them to us for consideration in later editions of this manual. All contributions will, of course, be properly credited to their contributor.

Internet electronic mail should be addressed to

avi@bell-labs.com.

Physical mail may be sent to Avi Silberschatz, Information Sciences Research Center, MH 2T-310, Bell Laboratories, 600 Mountain Avenue, Murray Hill, NJ 07974, USA.

A. S.

P. B. G G. G.

iii

(4)
(5)

CONTENTS

Chapter 1 Introduction. . . 1

Chapter 2 Computer-System Structures. . . 5

Chapter 3 Operating-System Structures. . . 9

Chapter 4 Processes. . . 13

Chapter 5 Threads. . . 15

Chapter 6 CPU Scheduling. . . 17

Chapter 7 Process Synchronization. . . 23

Chapter 8 Deadlocks. . . 27

Chapter 9 Memory Management. . . 31

Chapter 10 Virtual Memory. . . 37

Chapter 11 File-System Interface. . . 45

Chapter 12 File-System Implementation. . . 53

Chapter 13 I/O Systems. . . 57

Chapter 14 Mass-Storage Structure. . . 69

Chapter 15 Distributed System Structures. . . 75

Chapter 16 Distributed File Systems. . . 77

Chapter 17 Distributed Coordination. . . 79

Chapter 18 Protection. . . 81

Chapter 19 Security. . . 83

Chapter 20 The Linux System. . . 87

Chapter 21 Windows 2000. . . 97

Appendix A The FreeBSD System. . . 101

Appendix B The Mach System. . . 101

v

(6)
(7)

Chapter 1

INTRODUCTION

Chapter 1 introduces the general topic of operating systems and a handful of important concepts (multiprogramming, time sharing, distributed system, and so on). The purpose is to show why operating systems are what they are by showing how they developed. In operating systems, as in much of computer science, we are led to the present by the paths we took in the past, and we can better understand both the present and the future by understanding the past.

Additional work that might be considered is learning about the particular systems that the students will have access to at your institution. This is still just a general overview, as specific interfaces are considered in Chapter 3.

Answers to Exercises

1.1 What are the three main purposes of an operating system?

Answer:

 To provide an environment for a computer user to execute programs on computer hardware in a convenient and efficient manner.

 To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible.

 As a control program it serves two major functions: (1) supervision of the execution of user programs to prevent errors and improper use of the computer, and (2) manage- ment of the operation and control ofI/Odevices.

1.2 List the four steps that are necessary to run a program on a completely dedicated machine.

Answer:

a. Reserve machine time.

b. Manually load program into memory.

c. Load starting address and begin execution.

d. Monitor and control execution of program from console.

1

(8)

2 Chapter 1 Introduction

1.3 What is the main advantage of multiprogramming?

Answer: Multiprogramming makes efficient use of theCPUby overlapping the demands for theCPUand itsI/Odevices from various users. It attempts to increaseCPUutilization by always having something for theCPUto execute.

1.4 What are the main differences between operating systems for mainframe computers and personal computers?

Answer: The design goals of operating systems for those machines are quite different.

PCs are inexpensive, so wasted resources likeCPUcycles are inconsequential. Resources are wasted to improve usability and increase software user interface functionality. Main- frames are the opposite, so resource use is maximized, at the expensive of ease of use.

1.5 In a multiprogramming and time-sharing environment, several users share the system si- multaneously. This situation can result in various security problems.

a. What are two such problems?

b. Can we ensure the same degree of security in a time-shared machine as we have in a dedicated machine? Explain your answer.

Answer:

a. Stealing or copying one’s programs or data; using system resources (CPU, memory, disk space, peripherals) without proper accounting.

b. Probably not, since any protection scheme devised by humans can inevitably be bro- ken by a human, and the more complex the scheme, the more difficult it is to feel confident of its correct implementation.

1.6 Define the essential properties of the following types of operating systems:

a. Batch b. Interactive

c. Time sharing d. Real time

e. Network f. Distributed Answer:

a. Batch. Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequencer. Performance is increased by attempting to keepCPUandI/Odevices busy at all times through buffering, off-line operation, spooling, and multiprogramming. Batch is good for executing large jobs that need little interaction; it can be submitted and picked up later.

b. Interactive. This system is composed of many short transactions where the results of the next transaction may be unpredictable. Response time needs to be short (seconds) since the user submits and waits for the result.

c. Time sharing. This systems usesCPUscheduling and multiprogramming to provide economical interactive use of a system. TheCPUswitches rapidly from one user to another. Instead of having a job defined by spooled card images, each program reads

(9)

Answers to Exercises 3

its next control card from the terminal, and output is normally printed immediately to the screen.

d. Real time. Often used in a dedicated application, this system reads information from sensors and must respond within a fixed amount of time to ensure correct perfor- mance.

e. Network.

f. Distributed.This system distributes computation among several physical processors.

The processors do not share memory or a clock. Instead, each processor has its own local memory. They communicate with each other through various communication lines, such as a high-speed bus or telephone line.

1.7 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?

Answer: Single-user systems should maximize use of the system for the user. AGUI might “waste”CPUcycles, but it optimizes the user’s interaction with the system.

1.8 Under what circumstances would a user be better off using a time-sharing system, rather than a personal computer or single-user workstation?

Answer: When there are few other users, the task is large, and the hardware is fast, time- sharing makes sense. The full power of the system can be brought to bear on the user’s problem. The problem can be solved faster than on a personal computer. Another case occurs when lots of other users need resources at the same time.

A personal computer is best when the job is small enough to be executed reasonably on it and when performance is sufficient to execute the program to the user’s satisfaction.

1.9 Describe the differences between symmetric and asymmetric multiprocessing. What are three advantages and one disadvantage of multiprocessor systems?

Answer: Symmetric multiprocessing treats all processors as equals, andI/Ocan be pro- cessed on anyCPU. Asymmetric multiprocessing has one masterCPUand the remainder CPUs are slaves. The master distributes tasks among the slaves, andI/Ois usually done by the master only. Multiprocessors can save money by not duplicating power supplies, hous- ings, and peripherals. They can execute programs more quickly and can have increased reliability. They are also more complex in both hardware and software than uniprocessor systems.

1.10 What is the main difficulty that a programmer must overcome in writing an operating system for a real-time environment?

Answer: The main difficulty is keeping the operating system within the fixed time con- straints of a real-time system. If the system does not complete a task in a certain time frame, it may cause a breakdown of the entire system it is running. Therefore when writ- ing an operating system for a real-time system, the writer must be sure that his scheduling schemes don’t allow response time to exceed the time constraint.

1.11 Consider the various definitions of operating system. Consider whether the operating sys- tem should include applications such as Web browsers and mail programs. Argue both that it should and that it should not, and support your answer.

Answer: No answer.

1.12 What are the tradeoffs inherent in handheld computers?

Answer: No answer.

(10)

4 Chapter 1 Introduction

1.13 Consider a computing cluster consisting of two nodes running a database. Describe two ways in which the cluster software can manage access to the data on the disk. Discuss the benefits and detriments of each.

Answer: No answer.

(11)

Chapter 2

COMPUTER-SYSTEM STRUCTURES

Chapter 2 discusses the general structure of computer systems. It may be a good idea to re- view the basic concepts of machine organization and assembly language programming. The students should be comfortable with the concepts of memory, CPU, registers,I/O,interrupts, instructions, and the instruction execution cycle. Since the operating system is the interface be- tween the hardware and user programs, a good understanding of operating systems requires an understanding of both hardware and programs.

Answers to Exercises

2.1 Prefetching is a method of overlapping theI/Oof a job with that job’s own computation.

The idea is simple. After a read operation completes and the job is about to start operating on the data, the input device is instructed to begin the next read immediately. TheCPUand input device are then both busy. With luck, by the time the job is ready for the next data item, the input device will have finished reading that data item. TheCPUcan then begin processing the newly read data, while the input device starts to read the following data.

A similar idea can be used for output. In this case, the job creates data that are put into a buffer until an output device can accept them.

Compare the prefetching scheme with the spooling scheme, where theCPUoverlaps the input of one job with the computation and output of other jobs.

Answer: Prefetching is a user-based activity, while spooling is a system-based activity.

Spooling is a much more effective way of overlappingI/OandCPUoperations.

2.2 How does the distinction between monitor mode and user mode function as a rudimentary form of protection (security) system?

Answer: By establishing a set of privileged instructions that can be executed only when in the monitor mode, the operating system is assured of controlling the entire system at all times.

2.3 What are the differences between a trap and an interrupt? What is the use of each function?

Answer: An interrupt is a hardware-generated change-of-flow within the system. An interrupt handler is summoned to deal with the cause of the interrupt; control is then re-

5

(12)

6 Chapter 2 Computer-System Structures

turned to the interrupted context and instruction. A trap is a software-generated interrupt.

An interrupt can be used to signal the completion of anI/Oto obviate the need for device polling. A trap can be used to call operating system routines or to catch arithmetic errors.

2.4 For what types of operations isDMAuseful? Explain your answer.

Answer: DMAis useful for transferring large quantities of data between memory and devices. It eliminates the need for theCPUto be involved in the transfer, allowing the transfer to complete more quickly and theCPUto perform other tasks concurrently.

2.5 Which of the following instructions should be privileged?

a. Set value of timer.

b. Read the clock.

c. Clear memory.

d. Turn off interrupts.

e. Switch from user to monitor mode.

Answer: The following instructions should be privileged:

a. Set value of timer.

b. Clear memory.

c. Turn off interrupts.

d. Switch from user to monitor mode.

2.6 Some computer systems do not provide a privileged mode of operation in hardware. Con- sider whether it is possible to construct a secure operating system for these computers.

Give arguments both that it is and that it is not possible.

Answer: An operating system for a machine of this type would need to remain in control (or monitor mode) at all times. This could be accomplished by two methods:

a. Software interpretation of all user programs (like some BASIC, APL, and LISPsys- tems, for example). The software interpreter would provide, in software, what the hardware does not provide.

b. Require meant that all programs be written in high-level languages so that all ob- ject code is compiler-produced. The compiler would generate (either in-line or by function calls) the protection checks that the hardware is missing.

2.7 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.

Answer: The data required by the operating system (passwords, access controls, account- ing information, and so on) would have to be stored in or passed through unprotected memory and thus be accessible to unauthorized users.

2.8 Protecting the operating system is crucial to ensuring that the computer system operates correctly. Provision of this protection is the reason behind dual-mode operation, memory protection, and the timer. To allow maximum flexibility, however, we would also like to place minimal constraints on the user.

The following is a list of operations that are normally protected. What is the minimal set of instructions that must be protected?

(13)

Answers to Exercises 7

a. Change to user mode.

b. Change to monitor mode.

c. Read from monitor memory.

d. Write into monitor memory.

e. Fetch an instruction from monitor memory.

f. Turn on timer interrupt.

g. Turn off timer interrupt.

Answer: The minimal set of instructions that must be protected are:

a. Change to monitor mode.

b. Read from monitor memory.

c. Write into monitor memory.

d. Turn off timer interrupt.

2.9 Give two reasons why caches are useful. What problems do they solve? What problems do they cause? 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?

Answer: Caches are useful when two or more components need to exchange data, and the components perform transfers at differing speeds. Cahces solve the transfer problem by providing a buffer of intermediate speed between the components. If the fast device finds the data it needs in the cache, it need not wait for the slower device. The data in the cache must be kept consistent with the data in the components. If a component has a data value change, and the datum is also in the cache, the cache must also be updated.

This is especially a problem on multiprocessor systems where more than one process may be accessing a datum. A component may be eliminated by an equal-sized cache, but only if: (a) the cache and the component have equivalent state-saving capacity (that is, if the component retains its data when electricity is removed, the cache must retain data as well), and (b) the cache is affordable, because faster storage tends to be more expensive.

2.10 Writing an operating system that can operate without interference from malicious or un- debugged user programs requires some hardware assistance. Name three hardware aids for writing an operating system, and describe how they could be used together to protect the operating system.

Answer:

a. Monitor/user mode b. Privileged instructions c. Timer

d. Memory protection

2.11 SomeCPUs provide for more than two modes of operation. What are two possible uses of these multiple modes?

Answer: No answer.

2.12 What are the main differences between aWANand aLAN? Answer: No answer.

(14)

8 Chapter 2 Computer-System Structures

2.13 What network configuration would best suit the following environ- ments?

a. A dormitory floor b. A university campus

c. A state d. A nation

Answer: No answer.

(15)

Chapter 3

OPERATING-SYSTEM STRUCTURES

Chapter 3 is concerned with the operating-system interfaces that users (or at least programmers) actually see: system calls. The treatment is somewhat vague since more detail requires picking a specific system to discuss. This chapter is best supplemented with exactly this detail for the specific system the students have at hand. Ideally they should study the system calls and write some programs making system calls. This chapter also ties together several important concepts including layered design, virtual machines, Java and the Java virtual machine, system design and implementation, system generation, and the policy/mechanism difference.

Answers to Exercises

3.1 What are the five major activities of an operating system in regard to process management?

Answer:

 The creation and deletion of both user and system processes

 The suspension and resumption of processes

 The provision of mechanisms for process synchronization

 The provision of mechanisms for process communication

 The provision of mechanisms for deadlock handling

3.2 What are the three major activities of an operating system in regard to memory manage- ment?

Answer:

 Keep track of which parts of memory are currently being used and by whom.

 Decide which processes are to be loaded into memory when memory space becomes available.

 Allocate and deallocate memory space as needed.

9

(16)

10 Chapter 3 Operating-System Structures

3.3 What are the three major activities of an operating system in regard to secondary-storage management?

Answer:

 Free-space management.

 Storage allocation.

 Disk scheduling.

3.4 What are the five major activities of an operating system in regard to file management?

Answer:

 The creation and deletion of files

 The creation and deletion of directories

 The support of primitives for manipulating files and directories

 The mapping of files onto secondary storage

 The backup of files on stable (nonvolatile) storage media

3.5 What is the purpose of the command interpreter? Why is it usually separate from the kernel?

Answer: It reads commands from the user or from a file of commands and executes them, usually by turning them into one or more system calls. It is usually not part of the kernel since the command interpreter is subject to changes.

3.6 List five services provided by an operating system. Explain how each provides conve- nience to the users. Explain also in which cases it would be impossible for user-level pro- grams to provide these services.

Answer:

 Program execution. The operating system loads the contents (or sections) of a file into memory and begins its execution. A user-level program could not be trusted to properly allocateCPUtime.

 I/O operations. Disks, tapes, serial lines, and other devices must be communicated with at a very low level. The user need only specify the device and the operation to perform on it, while the system converts that request into device- or controller-specific commands. User-level programs cannot be trusted to only access devices they should have access to and to only access them when they are otherwise unused.

 File-system manipulation. There are many details in file creation, deletion, allocation, and naming that users should not have to perform. Blocks of disk space are used by files and must be tracked. Deleting a file requires removing the name file information and freeing the allocated blocks. Protections must also be checked to assure proper file access. User programs could neither ensure adherence to protection methods nor be trusted to allocate only free blocks and deallocate blocks on file deletion.

 Communications. Message passing between systems requires messages be turned into packets of information, sent to the network controller, transmitted across a com- munications medium, and reassembled by the destination system. Packet ordering and data correction must take place. Again, user programs might not coordinate ac- cess to the network device, or they might receive packets destined for other processes.

(17)

Answers to Exercises 11

 Error detection. Error detection occurs at both the hardware and software levels. At the hardware level, all data transfers must be inspected to ensure that data have not been corrupted in transit. All data on media must be checked to be sure they have not changed since they were written to the media. At the software level, media must be checked for data consistency; for instance, do the number of allocated and unallocated blocks of storage match the total number on the device. There, errors are frequently process-independent (for instance, the corruption of data on a disk), so there must be a global program (the operating system) that handles all types of errors. Also, by having errors processed by the operating system, processes need not contain code to catch and correct all the errors possible on a system.

3.7 What is the purpose of system calls?

Answer: System calls allow user-level processes to request services of the operating sys- tem.

3.8 Using system calls, write a program in either C or C++ that reads data from one file and copies it to another file. Such a program was described in Section 3.3.

Answer: Please refer to the supporting Web site for source code solution.

3.9 Why does Java provide the ability to call from a Java program native methods that are written in, say, C or C++? Provide an example where a native method is useful.

Answer: Java programs are intended to be platform I/O independent. Therefore, the language does not provide access to most specific system resources such as reading from I/O devices or ports. To perform a system I/O specific operation, you must write it in a language that supports such features (such as C or C++.) Keep in mind that a Java pro- gram that calls a native method written in another language will no longer be architecture- neutral.

3.10 What is the purpose of system programs?

Answer: System programs can be thought of as bundles of useful system calls. They provide basic functionality to users and so users do not need to write their own programs to solve common problems.

3.11 What is the main advantage of the layered approach to system design?

Answer: As in all cases of modular design, designing an operating system in a modular way has several advantages. The system is easier to debug and modify because changes affect only limited sections of the system rather than touching all sections of the operating system. Information is kept only where it is needed and is accessible only within a defined and restricted area, so any bugs affecting that data must be limited to a specific module or layer.

3.12 What are the main advantages of the microkernel approach to system design?

Answer: Benefits typically include the following (a) adding a new service does not require modifying the kernel, (b) it is more secure as more operations are done in user mode than in kernel mode, and (c) a simpler kernel design and functionality typically results in a more reliable operating system.

3.13 What is the main advantage for an operating-system designer of using a virtual-machine architecture? What is the main advantage for a user?

Answer: The system is easy to debug, and security problems are easy to solve. Virtual machines also provide a good platform for operating system research since many different operating systems may run on one physical system.

(18)

12 Chapter 3 Operating-System Structures

3.14 Why is a just-in-time compiler useful for executing Java programs?

Answer: Java is an interpreted language. This means that the JVM interprets the byte- code instructions one at a time. Typically, most interpreted environments are slower than running native binaries, for the interpretation process requires converting each instruction into native machine code. A just-in-time (JIT) compiler compiles the bytecode for a method into native machine code the first time the method is encountered. This means that the Java program is essentially running as a native application (of course, the conversion process of the JIT takes time as well but not as much as bytecode interpretation.) Furthermore, the JIT caches compiled code so that it may be reused the next time the method is encountered. A Java program that is run by a JIT rather than a traditional interpreter typically runs much faster.

3.15 Why is the separation of mechanism and policy a desirable property?

Answer: Mechanism and policy must be separate to ensure that systems are easy to modify. No two system installations are the same, so each installation may want to tune the operating system to suit its needs. With mechanism and policy separate, the policy may be changed at will while the mechanism stays unchanged. This arrangement provides a more flexible system.

3.16 The experimental Synthesis operating system has an assembler incorporated within the kernel. To optimize system-call performance, the kernel assembles routines within kernel space to minimize the path that the system call must take through the kernel. This ap- proach is the antithesis of the layered approach, in which the path through the kernel is extended so that building the operating system is made easier. Discuss the pros and cons of the Synthesis approach to kernel design and to system-performance optimization.

Answer: Synthesis is impressive due to the performance it achieves through on-the-fly compilation. Unfortunately, it is difficult to debug problems within the kernel due to the fluidity of the code. Also, such compilation is system specific, making Synthesis difficult to port (a new compiler must be written for each architecture).

(19)

Chapter 4

PROCESSES

In this chapter we introduce the concepts of a process and concurrent execution; These concepts are at the very heart of modern operating systems. A process is is a program in execution and is the unit of work in a modern time-sharing system. Such a system consists of a collection of processes: Operating-system processes executing system code and user processes executing user code. All these processes can potentially execute concurrently, with the CPU (orCPUs) multiplexed among them. By switching theCPUbetween processes, the operating system can make the computer more productive. We also introduce the notion of a thread (lightweight process) and interprocess communication (IPC). Threads are discussed in more detail in Chapter 5.

Answers to Exercises

4.1 MS-DOSprovided no means of concurrent processing. Discuss three major complications that concurrent processing adds to an operating system.

Answer:

 A method of time sharing must be implemented to allow each of several processes to have access to the system. This method involves the preemption of processes that do not voluntarily give up theCPU(by using a system call, for instance) and the kernel being reentrant (so more than one process may be executing kernel code concurrently).

 Processes and system resources must have protections and must be protected from each other. Any given process must be limited in the amount of memory it can use and the operations it can perform on devices like disks.

 Care must be taken in the kernel to prevent deadlocks between processes, so processes aren’t waiting for each other’s allocated resources.

4.2 Describe the differences among short-term, medium-term, and long-term scheduling.

Answer:

13

(20)

14 Chapter 4 Processes

 Short-term(CPUscheduler)—selects from jobs in memory those jobs that are ready to execute and allocates theCPUto them.

 Medium-term—used especially with time-sharing systems as an intermediate schedul- ing level. A swapping scheme is implemented to remove partially run programs from memory and reinstate them later to continue where they left off.

 Long-term(job scheduler)—determines which jobs are brought into memory for pro- cessing.

The primary difference is in the frequency of their execution. The short-term must select a new process quite often. Long-term is used much less often since it handles placing jobs in the system and may wait a while for a job to finish before it admits another one.

4.3 ADECSYSTEM-20 computer has multiple register sets. Describe the actions of a context switch if the new context is already loaded into one of the register sets. What else must happen if the new context is in memory rather than in a register set and all the register sets are in use?

Answer: TheCPUcurrent-register-set pointer is changed to point to the set containing the new context, which takes very little time. If the context is in memory, one of the contexts in a register set must be chosen and be moved to memory, and the new context must be loaded from memory into the set. This process takes a little more time than on systems with one set of registers, depending on how a replacement victim is selected.

4.4 Describe the actions a kernel takes to context switch between processes.

Answer: In general, the operating system must save the state of the currently running process and restore the state of the process scheduled to be run next. Saving the state of a process typically includes the values of all the CPU registers in addition to memory alloca- tion. Context switches must also perform many architecture-specific operations, including flushing data and instruction caches.

4.5 What are the benefits and detriments of each of the following? Consider both the systems and the programmers’ levels.

a. Symmetric and asymmetric communication b. Automatic and explicit buffering

c. Send by copy and send by reference d. Fixed-sized and variable-sized messages Answer: No answer.

4.6 The correct producer– consumer algorithm in Section 4.4 allows only n;1 buffers to be full at any one time. Modify the algorithm to allow all buffers to be utilized fully.

Answer: No answer.

4.7 Consider the interprocess-communication scheme where mailboxes are used.

a. Suppose a process P wants to wait for two messages, one from mailbox A and one from mailbox B. What sequence of send and receive should it execute?

b. What sequence of sendand receiveshould P execute if P wants to wait for one message either from mailbox A or from mailbox B (or from both)?

(21)

Answers to Exercises 15

c. A receiveoperation makes a process wait until the mailbox is nonempty. Either devise a scheme that allows a process to wait until a mailbox is empty, or explain why such a scheme cannot exist.

Answer: No answer.

4.8 Write a socket-based Fortune Teller server. Your program should create a server that listens to a specified port. When a client receives a connection, the server should respond with a random fortune chosen from its database of fortunes.

Answer: No answer.

(22)
(23)

Chapter 5

THREADS

The process model introduced in Chapter 4 assumed that a process was an executing program with a single thread of control. Many modern operating systems now provide features for a process to contain multiple threads of control. This chapter introduces many concepts associated with multithreaded computer systems and covers how to use Java to create and manipulate threads. We have found it especially useful to discuss how a Java thread maps to the thread model of the host operating system.

Answers to Exercises

5.1 Provide two programming examples of multithreading giving improved performance over a single-threaded solution.

Answer: (1) A Web server that services each request in a separate thread. (2) A paral- lelized application such as matrix multiplication where different parts of the matrix may be worked on in parallel. (3) An interactive GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third thread monitors performance.

5.2 Provide two programming examples of multithreading that would not improve perfor- mance over a single-threaded solution.

Answer: (1) Any kind of sequential program is not a good candidate to be threaded. An example of this is a program that calculates an individual tax return. (2) Another example is a ”shell” program such as the C-shell or Korn shell. Such a program must closely monitor its own working space such as open files, environment variables, and current working directory.

5.3 What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?

Answer: (1) User-level threads are unknown by the kernel, whereas the kernel is aware of kernel threads. (2) User threads are scheduled by the thread library and the kernel schedules kernel threads. (3) Kernel threads need not be associated with a process whereas every user thread belongs to a process.

17

(24)

18 Chapter 5 Threads

5.4 Describe the actions taken by a kernel to context switch between kernel-level threads.

Answer: Context switching between kernel threads typically requires saving the value of the CPU registers from the thread being switched out and restoring the CPU registers of the new thread being scheduled.

5.5 Describe the actions taken by a thread library to context switch between user-level threads.

Answer: Context switching between user threads is quite similar to switching between kernel threads, although it is dependent on the threads library and how it maps user threads to kernel threads. In general, context switching between user threads involves taking a user thread of its LWP and replacing it with another thread. This act typically involves saving and restoring the state of the registers.

5.6 What resources are used when a thread is created? How do they differ from those used when a process is created?

Answer: Because a thread is smaller than a process, thread creation typically uses fewer resources than process creation. Creating a process requires allocating a process control block (PCB), a rather large data structure. The PCB includes a memory map, list of open files, and environment variables. Allocating and managing the memory map is typically the most time-consuming activity. Creating either a user or kernel thread involves allocat- ing a small data structure to hold a register set, stack, and priority.

5.7 Assume an operating system maps user-level threads to the kernel using the many-to- many model where the mapping is done throughLWPs. Furthermore, the system allows the developers to create real-time threads. Is it necessary to bound a real-time thread to an LWP? Explain.

Answer: No Answer.

5.8 Write a multithreaded Pthread or Java program that generates the Fibonacci series. This program should work as follows: The user will run the program and will enter on the command line the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers.

Answer: Please refer to the supporting Web site for source code solution.

5.9 Write a multithreaded Pthread or Java program that outputs prime numbers. This program should work as follows: The user will run the program and will enter a number on the command line. The program will then create a separate thread that outputs all the prime numbers less than or equal to the number that the user entered.

Answer: Please refer to the supporting Web site for source code solution.

(25)

Chapter 6

CPU SCHEDULING

CPU scheduling is the basis of multiprogrammed operating systems. By switching the CPU among processes, the operating system can make the computer more productive. In this chap- ter, we introduce the basic scheduling concepts and discuss in great lengthCPU scheduling.

FCFS,SJF, Round-Robin, Priority, and the other scheduling algorithms should be familiar to the students. This is their first exposure to the idea of resource allocation and scheduling, so it is important that they understand how it is done. Gantt charts, simulations, and play acting are valuable ways to get the ideas across. Show how the ideas are used in other situations (like waiting in line at a post office, a waiter time sharing between customers, even classes being an interleaved Round-Robin scheduling of professors).

A simple project is to write several differentCPUschedulers and compare their performance by simulation. The source ofCPUandI/Obursts may be generated by random number genera- tors or by a trace tape. The instructor can make the trace tape up in advance to provide the same data for all students. The file that I used was a set of jobs, each job being a variable number of alternatingCPUandI/Obursts. The first line of a job was the word JOB and the job number.

An alternating sequence ofCPUn andI/On lines followed, each specifying a burst time. The job was terminated by anENDline with the job number again. Compare the time to process a set of jobs usingFCFS, Shortest-Burst-Time, and Round-Robin scheduling. Round-Robin is more difficult, since it requires putting unfinished requests back in the ready queue.

Answers to Exercises

6.1 ACPUscheduling algorithm determines an order for the execution of its scheduled pro- cesses. Given n processes to be scheduled on one processor, how many possible different schedules are there? Give a formula in terms of n.

Answer: n! (n factorial = nn – 1n – 2...21)

6.2 Define the difference between preemptive and nonpreemptive scheduling. State why strict nonpreemptive scheduling is unlikely to be used in a computer center.

Answer: Preemptive scheduling allows a process to be interrupted in the midst of its exe- cution, taking theCPUaway and allocating it to another process. Nonpreemptive schedul-

19

(26)

20 Chapter 6 CPU Scheduling

ing ensures that a process relinquishes control of theCPUonly when it finishes with its currentCPUburst.

6.3 Consider the following set of processes, with the length of theCPU-burst time given in milliseconds:

Process Burst Time Priority

P1 10 3

P2 1 1

P3 2 3

P4 1 4

P5 5 2

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.

a. Draw four Gantt charts illustrating the execution of these processes usingFCFS,SJF, a nonpreemptive priority (a smaller priority number implies a higher priority), andRR (quantum = 1) scheduling.

b. What is the turnaround time of each process for each of the scheduling algorithms in part a?

c. What is the waiting time of each process for each of the scheduling algorithms in part a?

d. Which of the schedules in part a results in the minimal average waiting time (over all processes)?

Answer:

a. The four Gantt charts are

2 3 4 5 1 5 1 5 1 5

1 3 1 5 1

1 2 3 4 5

2 4 3 5 1

1 3 4

5 2

SJF RR FCFS

Priority

b. Turnaround time

FCFS RR SJF Priority

P1 10 19 19 16

P2 11 2 1 1

P3 13 7 4 18

P4 14 4 2 19

P5 19 14 9 6

c. Waiting time (turnaround time minus burst time)

(27)

Answers to Exercises 21

FCFS RR SJF Priority

P1 0 9 9 6

P2 10 1 0 0

P3 11 5 2 16

P4 13 3 1 18

P5 14 9 4 1

d. Shortest Job First

6.4 Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. In answering the questions, use nonpreemptive scheduling and base all decisions on the information you have at the time the decision must be made.

Process Arrival Time Burst Time

P1 0.0 8

P2 0.4 4

P3 1.0 1

a. What is the average turnaround time for these processes with theFCFSscheduling algorithm?

b. What is the average turnaround time for these processes with theSJFscheduling al- gorithm?

c. TheSJFalgorithm is supposed to improve performance, but notice that we chose to run process P1at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if theCPUis left idle for the first 1 unit and thenSJFscheduling is used. Remember that processes P1

and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling.

Answer:

a. 10.53 b. 9.53 c. 6.86

Remember that turnaround time is finishing time minus arrival time, so you have to sub- tract the arrival times to compute the turnaround times.FCFSis 11 if you forget to subtract arrival time.

6.5 Consider a variant of theRRscheduling algorithm where the entries in the ready queue are pointers to thePCBs.

a. What would be the effect of putting two pointers to the same process in the ready queue?

b. What would be the major advantages and disadvantages of this scheme?

c. How would you modify the basicRRalgorithm to achieve the same effect without the duplicate pointers?

Answer:

(28)

22 Chapter 6 CPU Scheduling

a. In effect, that process will have increased its priority since by getting time more often it is receiving preferential treatment.

b. The advantage is that more important jobs could be given more time, in other words, higher priority in treatment. The consequence, of course, is that shorter jobs will suffer.

c. Allot a longer amount of time to processes deserving higher priority. In other words, have two or more quantums possible in the Round-Robin scheme.

6.6 What advantage is there in having different time-quantum sizes on different levels of a multilevel queueing system?

Answer: Processes that need more frequent servicing, for instance, interactive processes such as editors, can be in a queue with a small time quantum. Processes with no need for frequent servicing can be in a queue with a larger quantum, requiring fewer context switches to complete the processing, making more efficient use of the computer.

6.7 Consider the following preemptive priority-scheduling algorithm based on dynamically changing priorities. Larger priority numbers imply higher priority. When a process is waiting for theCPU(in the ready queue but not running), its priority changes at a rate ; when it is running, its priority changes at a rate . All processes are given a priority of 0 when they enter the ready queue. The parameters and can be set to give many different scheduling algorithms.

a. What is the algorithm that results from > >0?

b. What is the algorithm that results from < <0?

Answer:

a. FCFS b. LIFO

6.8 ManyCPUscheduling algorithms are parameterized. For example, theRRalgorithm re- quires a parameter to indicate the time slice. Multilevel feedback queues require parame- ters to define the number of queues, the scheduling algorithms for each queue, the criteria used to move processes between queues, and so on.

These algorithms are thus really sets of algorithms (for example, the set ofRRalgorithms for all time slices, and so on). One set of algorithms may include another (for example, the FCFSalgorithm is theRRalgorithm with an infinite time quantum). What (if any) relation holds between the following pairs of sets of algorithms?

a. Priority andSJF

b. Multilevel feedback queues andFCFS c. Priority andFCFS

d. RRandSJF Answer:

a. The shortest job has the highest priority.

b. The lowest level ofMLFQisFCFS.

c. FCFSgives the highest priority to the job having been in existence the longest.

(29)

Answers to Exercises 23

d. None

6.9 Suppose that a scheduling algorithm (at the level of short-term CPUscheduling) favors those processes that have used the least processor time in the recent past. Why will this al- gorithm favorI/O-bound programs and yet not permanently starveCPU-bound programs?

Answer: It will favor theI/O-bound programs because of the relatively shortCPUburst request by them; however, theCPU-bound programs will not starve because theI/O-bound programs will relinquish theCPUrelatively often to do theirI/O.

6.10 Explain the differences in the degree to which the following scheduling algorithms dis- criminate in favor of short processes:

a. FCFS b. RR

c. Multilevel feedback queues Answer:

a. FCFS—discriminates against short jobs since any short jobs arriving after long jobs will have a longer waiting time.

b. RR—treats all jobs equally (giving them equal bursts ofCPUtime) so short jobs will be able to leave the system faster since they will finish first.

c. Multilevel feedback queues—work similar to theRRalgorithm—they discriminate favorably toward short jobs.

(30)
(31)

Chapter 7

PROCESS

SYNCHRONIZATION

Chapter 7 is concerned with the topic of process synchronization among concurrently executing processes. Concurrency is generally very hard for students to deal with correctly, and so we have tried to introduce it and its problems with the classic process coordination problems: mutual exclusion, bounded-buffer, readers/writers, and so on. An understanding of these problems and their solutions is part of current operating-system theory and development.

We first use semaphores and monitors to introduce synchronization techniques. Next, Java synchronization is introduced to further demonstrate a language-based synchronization tech- nique.

Answers to Exercises

7.1 What is the meaning of the term busy waiting? What other kinds of waiting are there in an operating system? Can busy waiting be avoided altogether? Explain your answer.

Answer: No answer.

7.2 Explain why spinlocks are not appropriate for uniprocessor systems yet may be suitable for multiprocessor systems.

Answer: No answer.

7.3 Prove that, in the bakery algorithm (Section 7.2), the following property holds: If Piis in its critical section and Pk(k6=i) has already chosen itsnumber[k] 6= 0, then (number[i], i) < (number[k], k).

Answer: No answer.

7.4 The first known correct software solution to the critical-section problem for two threads was developed by Dekker; it is shown in Figure 7.27. The two threads, T0 and T1, coordinate activity sharing an object of class Dekker.

Show that the algorithm satisfies all three requirements for the critical- section problem.

Answer: No answer.

25

(32)

26 Chapter 7 Process Synchronization

7.5 The first known correct software solution to the critical-section problem for n processes with a lower bound on waiting of n ; 1 turns was presented by Eisenberg and McGuire. The processes share the following variables:

enum pstate fidle, want in, in csg; pstate flag[n];

int turn;

All the elements of flag are initially idle; the initial value of turn is immaterial (between 0 and n-1). The structure of process Pi is shown in Fig- ure 7.28.

Prove that the algorithm satisfies all three requirements for the critical- section problem.

Answer: No answer.

7.6 In Section 7.3, we mentioned that disabling interrupts frequently can af- fect the system's clock. Explain why it can, and how such effects can be minimized.

Answer: No answer.

7.7 Show that, if the wait and signal operations are not executed atomically, then mutual exclusion may be violated.

Answer: No answer.

7.8 The Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and the barber room containing the barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop.

If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coordinate the barber and the customers.

Answer: Please refer to the supporting Web site for source code solution.

7.9 The Cigarette-Smokers Problem. Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three in- gredients: tobacco, paper, and matches. One of the smoker processes has paper, another has tobacco, and the third has matches. The agent has an infinite supply of all three materials. The agent places two of the in- gredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats.

Write a program to synchronize the agent and the smokers.

Answer: Please refer to the supporting Web site for source code solution.

7.10 Demonstrate that monitors, conditional critical regions, and semaphores are all equivalent, insofar as the same types of synchronization problems can be implemented with them.

Answer: No answer.

7.11 Write a bounded-buffer monitor in which the buffers (portions) are embed- ded within the monitor itself.

Answer: No answer.

(33)

Answers to Exercises 27

7.12 The strict mutual exclusion within a monitor makes the bounded-buffer mon- itor of Exercise 7.11 mainly suitable for small portions.

a. Explain why this assertion is true.

b. Design a new scheme that is suitable for larger portions.

Answer: No answer.

7.13 Suppose that the signal statement can appear as only the last statement in a monitor procedure. Suggest how the implementation described in Section 7.7 can be simplified.

Answer: No answer.

7.14 Consider a system consisting of processes P1, P2, ..., Pn, each of which has a unique priority number. Write a monitor that allocates three identical line printers to these processes, using the priority numbers for deciding the order of allocation.

Answer: No answer.

7.15 A file is to be shared among different processes, each of which has a unique number. The file can be accessed simultaneously by several processes, sub- ject to the following constraint: The sum of all unique numbers associ- ated with all the processes currently accessing the file must be less than n. Write a monitor to coordinate access to the file.

Answer: No answer.

7.16 Suppose that we replace the wait and signal operations of monitors with a single construct await(B), where B is a general Boolean expression that causes the process executing it to wait until B becomes true.

a. Write a monitor using this scheme to implement the readers--writers prob- lem.

b. Explain why, in general, this construct cannot be implemented efficiently.

c. What restrictions need to be put on the await statement so that it can be implemented efficiently? (Hint: Restrict the generality of B; see kessels [1977].)

Answer: No answer.

7.17 Write a monitor that implements an alarm clock that enables a calling program to delay itself for a specified number of time units (ticks). You may as- sume the existence of a real hardware clock that invokes a procedure tick in your monitor at regular intervals.

Answer: No answer.

7.18 Why does Solaris 2 implement multiple locking mechanisms? Under what cir- cumstances does it use spinlocks, semaphores, adaptive mutexes, conditional variables, and readers--writers locks? Why does it use each mechanism? What is the purpose of turnstiles?

Answer: Solaris 2 provides different locking mechanisms depending on the application developer's needs. Spinlocks are useful for multiprocessor sys- tems where a thread can run in a busy-loop (for a short period of time) rather

(34)

28 Chapter 7 Process Synchronization

than incurring the overhead of being put in a sleep queue. Mutexes are use- ful for locking resources. Solaris 2 uses adaptive mutexes, meaning that

the mutex is implemented with a spin lock on multiprocessor machines. Semaphores and condition variables are more appropriate tools for synchronization when a resource must be held for a long period of time for spinning is ineffi- cient for a long duration. Readers/writers locks are useful when readers and writers both need access to a resource, but the readers are more ac- tive and performance can be gained not using exclusive access locks. So- laris 2 uses turnstiles to order the list of threads waiting to acquire ei- ther an adaptive mutex or a reader--writer lock.

7.19 Why do Solaris 2 and Windows 2000 use spinlocks as a synchronization mech- anism on only multiprocessor systems and not on uniprocessor systems?

Answer: No answer.

7.20 Explain the differences, in terms of cost, among the three storage types:

volatile, nonvolatile, and stable.

Answer: No answer.

7.21 Explain the purpose of the checkpoint mechanism. How often should check- points be performed? How does the frequency of checkpoints affect:

 System performance when no failure occurs?

 The time it takes to recover from a system crash?

 The time it takes to recover from a disk crash?

Answer: No answer.

7.22 Explain the concept of transaction atomicity.

Answer: No answer.

7.23 Show that the two-phase locking protocol ensures conflict serializability.

Answer: No answer.

7.24 Show that some schedules are possible under the two-phase locking proto- col but not possible under the timestamp protocol, and vice versa.

Answer: No answer.

(35)

Chapter 8

DEADLOCKS

Deadlock is a problem that can only arise in a system with multiple active asynchronous pro- cesses. It is important that the students learn the three basic approaches to deadlock: prevention, avoidance, and detection (although the terms prevention and avoidance are easy to confuse).

It can be useful to pose a deadlock problem in human terms and ask why human systems never deadlock. Can the students transfer this understanding of human systems to computer systems?

Projects can involve simulation: create a list of jobs consisting of requests and releases of resources (single type or multiple types). Ask the students to allocate the resources to prevent deadlock. This basically involves programming the Banker’s Algorithm.

The survey paper by Coffman, Elphick, and Shoshani [1971] is good supplemental reading, but you might also consider having the students go back to the papers by Havender [1968], Habermann [1969], and Holt [1971a]. The last two were published in CACM and so should be readily available.

Answers to Exercises

8.1 List three examples of deadlocks that are not related to a computer-system environment.

Answer:

 Two cars crossing a single-lane bridge from opposite directions.

 A person going down a ladder while another person is climbing up the ladder.

 Two trains traveling toward each other on the same track.

8.2 Is it possible to have a deadlock involving only one single process? Explain your answer.

Answer: No. This follows directly from the hold-and-wait condition.

8.3 People have said that proper spooling would eliminate deadlocks. Certainly, it eliminates from contention card readers, plotters, printers, and so on. It is even possible to spool tapes (called staging them), which would leave the resources ofCPUtime, memory, and disk space. Is it possible to have a deadlock involving these resources? If it is, how could

29

(36)

30 Chapter 8 Deadlocks

such a deadlock occur? If it is not, why not? What deadlock scheme would seem best to eliminate these deadlocks (if any are possible), or what condition is violated (if they are not possible)?

Answer: No answer.

8.4 Consider the traffic deadlock depicted in Figure 8.11.

a. Show that the four necessary conditions for deadlock indeed hold in this example.

b. State a simple rule that will avoid deadlocks in this system.

Answer: No answer.

8.5 Suppose that a system is in an unsafe state. Show that it is possible for the processes to complete their execution without entering a deadlock state.

Answer: No answer.

In a real computer system, neither the resources available nor the demands of processes for resources are consistent over long periods (months). Resources break or are replaced, new processes come and go, new resources are bought and added to the system. If deadlock is controlled by the banker’s algorithm, which of the following changes can be made safely (without introducing the possibility of deadlock), and under what circumstances?

a. Increase Available (new resources added)

b. Decrease Available (resource permanently removed from system)

c. Increase Max for one process (the process needs more resources than allowed, it may want more)

d. Decrease Max for one process (the process decides it does not need that many re- sources)

e. Increase the number of processes f. Decrease the number of processes Answer: No answer.

8.6 Prove that the safety algorithm presented in Section 8.5.3 requires an order of mn2op- erations.

Answer: No answer.

8.7 Consider a system consisting of four resources of the same type that are shared by three processes, each of which needs at most two resources. Show that the system is deadlock- free.

Answer: Suppose the system is deadlocked. This implies that each process is holding one resource and is waiting for one more. Since there are three processes and four resources, one process must be able to obtain two resources. This process requires no more resources and, therefore it will return its resources when done.

8.8 Consider a system consisting of m resources of the same type, being shared by n processes.

Resources can be requested and released by processes only one at a time. Show that the system is deadlock-free if the following two conditions hold:

a. The maximum need of each process is between 1 and m resources b. The sum of all maximum needs is less than m + n

Answer: Using the terminology of Section 7.6.2, we have:

(37)

Answers to Exercises 31

a. Pni = 1 Maxi < m + n b. Maxi  1 for all i

Proof: Needi = Maxi ; Allocationi If there exists a deadlock state then:

c. Pni = 1 Allocationi = m

Use a. to get:PNeedi + P Allocationi = PMaxi < m + n Use c. to get:

P

Needi + m < m + n Rewrite to get:Pni = 1 Needi < n

This implies that there exists a process Pi such that Needi = 0. Since Maxi  1 it fol- lows that Pihas at least one resource that it can release. Hence the system cannot be in a deadlock state.

8.9 Consider a computer system that runs 5,000 jobs per month with no deadlock-prevention or deadlock-avoidance scheme. Deadlocks occur about twice per month, and the operator must terminate and rerun about 10 jobs per deadlock. Each job is worth about $2 (inCPU time), and the jobs terminated tend to be about half-done when they are aborted.

A systems programmer has estimated that a deadlock-avoidance algorithm (like the banker’s algorithm) could be installed in the system with an increase in the average execu- tion time per job of about 10 percent. Since the machine currently has 30-percent idle time, all 5,000 jobs per month could still be run, although turnaround time would increase by about 20 percent on average.

a. What are the arguments for installing the deadlock-avoidance algorithm?

b. What are the arguments against installing the deadlock-avoidance algorithm?

Answer: No answer.

8.10 We can obtain the banker’s algorithm for a single resource type from the general banker’s algorithm simply by reducing the dimensionality of the various arrays by 1. Show through an example that the multiple-resource-type banker’s scheme cannot be implemented by individual application of the single-resource-type scheme to each resource type.

Answer: No answer.

8.11 Can a system detect that some of its processes are starving? If you answer “yes,” explain how it can. If you answer “no,” explain how the system can deal with the starvation prob- lem.

Answer: No answer.

8.12 Consider the following snapshot of a system:

Allocation Max Available

A B C D A B C D A B C D

P0 0 0 1 2 0 0 1 2 1 5 2 0

P1 1 0 0 0 1 7 5 0

P2 1 3 5 4 2 3 5 6

P3 0 6 3 2 0 6 5 2

P4 0 0 1 4 0 6 5 6

Answer the following questions using the banker’s algorithm:

a. What is the content of the matrix Need?

(38)

32 Chapter 8 Deadlocks

b. Is the system in a safe state?

c. If a request from process P1arrives for (0,4,2,0), can the request be granted immedi- ately?

Answer: No answer.

8.13 Consider the following resource-allocation policy. Requests and releases for resources are allowed at any time. If a request for resources cannot be satisfied because the resources are not available, then we check any processes that are blocked, waiting for resources. If they have the desired resources, then these resources are taken away from them and are given to the requesting process. The vector of resources for which the waiting process is waiting is increased to include the resources that were taken away.

For example, consider a system with three resource types and the vector Available initialized to (4,2,2). If process P0asks for (2,2,1), it gets them. If P1asks for (1,0,1), it gets them. Then, if P0 asks for (0,0,1), it is blocked (resource not available). If P2 now asks for (2,0,0), it gets the available one (1,0,0) and one that was allocated to P0(since P0is blocked).

P0’s Allocation vector goes down to (1,2,1), and its Need vector goes up to (1,0,1).

a. Can deadlock occur? If so, give an example. If not, which necessary condition cannot occur?

b. Can indefinite blocking occur?

Answer:

a. Deadlock cannot occur because preemption exists.

b. Yes. A process may never acquire all the resources it needs if they are continuously preempted by a series of requests such as those of process C.

8.14 Suppose that you have coded the deadlock-avoidance safety algorithm and now have been asked to implement the deadlock-detection algorithm. Can you do so by simply using the safety algorithm code and redefining Maxi = Waitingi + Allocationi, where Waitingiis a vector specifying the resources process i is waiting for, and Allocationi is as defined in Section 8.5 Explain your answer.

Answer: No answer.

(39)

Chapter 9

MEMORY

MANAGEMENT

Although many systems are demand paged (discussed in Chapter 10), there are still many that are not, and in many cases the simpler memory management strategies may be better, especially for small dedicated systems. We want the student to learn about all of them: resident monitor, swapping, partitions, paging, and segmentation.

Answers to Exercises

9.1 Name two differences between logical and physical addresses.

Answer: No answer.

9.2 Explain the difference between internal and external fragmentation.

Answer: Internal Fragmentation is the area in a region or a page that is not used by the job occupying that region or page. This space is unavailable for use by the system until that job is finished and the page or region is released.

9.3 Describe the following allocation algorithms:

a. First fit b. Best fit c. Worst fit Answer:

a. First-fit: search the list of available memory and allocate the first block that is big enough.

b. Best-fit: search the entire list of available memory and allocate the smallest block that is big enough.

c. Worst-fit: search the entire list of available memory and allocate the largest block.

(The justification for this scheme is that the leftover block produced would be larger and potentially more useful than that produced by the best-fit approach.)

33

參考文獻

相關文件

From Remark 3.4, there exists a minimum kernel scale σ min , such that the correspondence produced by the HD model with the kernel scale σ ≥ σ min is the same as the correspondence

substance) is matter that has distinct properties and a composition that does not vary from sample

A set of kernel interfaces and APIs QEMU frontend.. EACH VM IS

– Each listener may respond to a different kind of  event or multiple listeners might may respond to event, or multiple listeners might may respond to 

• Any node that does not have a local replica of the object periodically creates a QoS-advert message contains (a) its δ i deadline value and (b) depending-on , the ID of the node

The presentation or rebranding by a company of an established product in a new form, a new package or under a new label into a market not previously explored by that company..

Variable symbols: Any user-defined symbol xxx appearing in an assembly program that is not defined elsewhere using the ( xxx) directive is treated as a variable, and

The main objective of this system is to design a virtual reality learning system for operation practice of total station instrument, and to make learning this skill easier.. Students