




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































OPERATING-
SYSTEM
CONCEPTS
Yale University
PETER BAER GALVIN Corporate Technologies
GREG GAGNE Westminster College
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.
1.1 In a multiprogramming and time-sharing environment, several users share the system simultaneously. 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 ma- chine as in a dedicated machine? Explain your answer.
Answer:
a. Stealing or copying one’s programs or data; using system re- sources ( CPU, memory, disk space, peripherals) without proper accounting. b. Probably not, since any protection scheme devised by humans can inevitably be broken by a human, and the more complex the scheme, the more difficult it is to feel confident of its correct implementation.
1
2 Chapter 1 Introduction
1.2 The issue of resource utilization shows up in different forms in differ- ent types of operating systems. List what resources must be managed carefully in the following settings: a. Mainframe or minicomputer systems b. Workstations connected to servers c. Handheld computers Answer:
a. Mainframes: memory and CPU resources, storage, network band- width. b. Workstations: memory and CPU resouces c. Handheld computers: power consumption, memory resources. 1.3 Under what circumstances would a user be better off using a time- sharing system rather than a PC 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 exe- cuted reasonably on it and when performance is sufficient to execute the program to the user’s satisfaction. 1.4 Which of the functionalities listed below need to be supported by the operating system for the following two settings: (a) handheld devices and (b) real-time systems. a. Batch programming b. Virtual memory c. Time sharing Answer: For real-time systems, the operating system needs to support virtual memory and time sharing in a fair manner. For handheld systems, the operating system needs to provide virtual memory, but does not need to provide time-sharing. Batch programming is not necessary in both settings. 1.5 Describe the differences between symmetric and asymmetric multipro- cessing. What are three advantages and one disadvantage of multipro- cessor systems? Answer: Symmetric multiprocessing treats all processors as equals, and I/O can be processed on any CPU. Asymmetric multiprocessing has one master CPU and the remainder CPUs are slaves. The master distributes tasks among the slaves, and I/O is usually done by the master only. Multiprocessors can save money by not duplicating power supplies, housings, 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.
4 Chapter 1 Introduction
to manage its resources. A personal computer on the other hand has to be capable of providing all of the required functionality in a stand- alone manner without relying on a centralized manner. Scenarios where administrative costs are high and where sharing leads to more efficient use of resources are precisely those settings where network computers are preferred. 1.10 What is the purpose of interrupts? What are the differences between a trap and an interrupt? Can traps be generated intentionally by a user program? If so, for what purpose? 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 returned to the interrupted context and instruction. A trap is a software-generated interrupt. An interrupt can be used to signal the completion of an I/O to obviate the need for device polling. A trap can be used to call operating system routines or to catch arithmetic errors. 1.11 Direct memory access is used for high-speed I/O devices in order to avoid increasing the CPU ´s execution load. a. How does the CPU interface with the device to coordinate the transfer? b. How does the CPU know when the memory operations are com- plete? c. The CPU is allowed to execute other programs while the DMA controller is transferring data. Does this process interfere with the execution of the user programs? If so, describe what forms of interference are caused. Answer: The CPU can initiate a DMA operation by writing values into special registers that can be independently accessed by the device. The device initiates the corresponding operation once it receives a com- mand from the CPU. When the device is finished with its operation, it interrupts the CPU to indicate the completion of the operation. Both the device and the CPU can be accessing memory simultaneously. The memory controller provides access to the memory bus in a fair manner to these two entities. A CPU might therefore be unable to issue memory operations at peak speeds since it has to compete with the device in order to obtain access to the memory bus. 1.12 Some computer systems do not provide a privileged mode of operation in hardware. Is it possible to construct a secure operating system for these computer systems? 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 accom- plished by two methods: a. Software interpretation of all user programs (like some BASIC , Java, and LISP systems, for example). The software interpreter would provide, in software, what the hardware does not provide.
Exercises 5
b. Require meant that all programs be written in high-level lan- guages so that all object code is compiler-produced. The compiler would generate (either in-line or by function calls) the protection checks that the hardware is missing.
1.13 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 ex- change data, and the components perform transfers at differing speeds. Caches 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 com- ponent 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.
1.14 Discuss, with examples, how the problem of maintaining coherence of cached data manifests itself in the following processing environments:
a. Single-processor systems b. Multiprocessor systems c. Distributed systems
Answer: In single-processor systems, the memory needs to be updated when a processor issues updates to cached values. These updates can be performed immediately or in a lazy manner. In a multiprocessor system, different processors might be caching the same memory location in its local caches. When updates are made, the other cached locations need to be invalidated or updated. In distributed systems, consistency of cached memory values is not an issue. However, consistency problems might arise when a client caches file data.
1.15 Describe a mechanism for enforcing memory protection in order to pre- vent a program from modifying the memory associated with other pro- grams. Answer: The processor could keep track of what locations are asso- ciated with each process and limit access to locations that are outside of a program’s extent. Information regarding the extent of a program’s memory could be maintained by using base and limits registers and by performing a check for every memory access.
1.16 What network configuration would best suit the following environ- ments?
Exercises 7
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 performance. e. Network. Provides operating system features across a network such as file sharing. f. SMP. Used in systems where there are multiple CPU’s each run- ning the same copy of the operating system. Communication takes place across the system bus. g. 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 local area network. h. Clustered. A clustered system combines multiple computers into a single system to perform computational task distributed across the cluster. i. Handheld. A small computer system that performs simple tasks such as calendars, email, and web browsing. Handheld systems differ from traditional desktop systems with smaller memory and display screens and slower processors.
1.18 What are the tradeoffs inherent in handheld computers? Answer: Handheld computers are much smaller than traditional desk- top PC’s. This results in smaller memory, smaller screens, and slower processing capabilities than a standard desktop PC. Because of these limitations, most handhelds currently can perform only basic tasks such as calendars, email, and simple word processing. However, due to their small size, they are quite portable and, when they are equipped with wireless access, can provide remote access to electronic mail and the world wide web.
10 Chapter 2 Operating-System Structures
2.3 Describe three general methods for passing parameters to the operating system. Answer:
a. Pass parameters in registers b. Registers pass starting addresses of blocks of parameters c. Parameters can be placed, or pushed, onto the stack by the program, and popped off the stack by the operating system.
Exercises 11
2.4 Describe how you could obtain a statistical profile of the amount of time spent by a program executing different sections of its code. Discuss the importance of obtaining such a statistical profile. Answer: One could issue periodic timer interrupts and monitor what instructions or what sections of code are currently executing when the interrupts are delivered. A statistical profile of which pieces of code were active should be consistent with the time spent by the program in different sections of its code. Once such a statistical profile has been obtained, the programmer could optimize those sections of code that are consuming more of the CPU resources.
2.5 What are the five major activities of an operating system in regard to file management? Answer:
2.6 What are the advantages and disadvantages of using the same system- call interface for manipulating both files and devices? Answer: Each device can be accessed as though it was a file in the file system. Since most of the kernel deals with devices through this file in- terface, it is relatively easy to add a new device driver by implementing the hardware-specific code to support this abstract file interface. There- fore, this benefits the development of both user program code, which can be written to access devices and files in the same manner, and device driver code, which can be written to support a well-defined API. The disadvantage with using the same interface is that it might be difficult to capture the functionality of certain devices within the context of the file access API, thereby either resulting in a loss of functionality or a loss of performance. Some of this could be overcome by the use of ioctl oper- ation that provides a general purpose interface for processes to invoke operations on devices.
2.7 What is the purpose of the command interpreter? Why is it usually separate from the kernel? Would it be possible for the user to develop a new command interpreter using the system-call interface provided by the operating system? 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. An user should be able to develop a new command interpreter using the system-call interface provided by the operating system. The command interpreter allows an user to create and manage processes and also determine ways by which they communicate (such as through pipes and files). As all of this functionality could be accessed
Exercises 13
microkernel architecture by using interprocess communication mecha- nisms such as messaging. These messages are conveyed by the operating system. The primary disadvantage of the microkernel architecture are the overheads associated with interprocess communication and the fre- quent use of the operating system’s messaging functions in order to enable the user process and the system service to interact with each other.
2.13 In what ways is the modular kernel approach similar to the layered approach? In what ways does it differ from the layered approach? Answer: The modular kernel approach requires subsystems to interact with each other through carefully constructed interfaces that are typi- cally narrow (in terms of the functionality that is exposed to external modules). The layered kernel approach is similar in that respect. How- ever, the layered kernel imposes a strict ordering of subsystems such that subsystems at the lower layers are not allowed to invoke opera- tions corresponding to the upper-layer subsystems. There are no such restrictions in the modular-kernel approach, wherein modules are free to invoke each other without any constraints.
2.14 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.
2.15 Why is a just-in-time compiler useful for executing Java programs? Answer: Java is an interpreted language. This means that the JVM inter- prets the bytecode instructions one at a time. Typically, most interpreted environments are slower than running native binaries, for the interpre- tation 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 appli- cation (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 en- countered. A Java program that is run by a JIT rather than a traditional interpreter typically runs much faster.
2.16 What is the relationship between a guest operating system and a host operating system in a system like VMware? What factors need to be considered in choosing the host operating system? Answer: A guest operating system provides its services by mapping them onto the functionality provided by the host operating system. A key issue that needs to be considered in choosing the host operating system is whether it is sufficiently general in terms of its system-call interface in order to be able to support the functionality associated with the guest operating system.
14 Chapter 2 Operating-System Structures
2.17 The experimental Synthesis operating system has an assembler incorpo- rated within the kernel. To optimize system-call performance, the kernel assembles routines within kernel space to minimize the path that the sys- tem call must take through the kernel. This approach is the antithesis of the layered approach, in which the path through the kernel is extended to make building the operating system 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). 2.18 In Section 2.3, we described a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Write this program using either the Windows32 or POSIX API. Be sure to include all necessary error checking, including ensuring that the source file exists. Once you have correctly designed and tested the program, if you used a system that supports it, run the program using a utility that traces system calls.
similar functionality. Answer: Please refer to the supporting Web site for solution.