osQuesCh1 4
osQuesCh1 4
Practice Exercises
/ 1.1 What are the three main purposes of an operating system?
1.2 What are the main differences between operating systems for mainframe
computers and personal computers?
1.3 List the four steps that are necessary to run a program on a completely
dedicated machine—a computer that is running only that program.
1.4 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?
1.5 What is the main difficulty that a programmer must overcome in writing
an operating system for a real-time environment?
, 1.6 Consider the various definitions of operating system. Consider whether
the operating system should include applications such as Web browsers
Exercises 43
and mail programs. Argue both that it should and that it should not, and
support your answers.
1.7 How does the distinction between kernel mode and user mode function
as a rudimentary form of protection (security) system?
;/1.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.
1.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.
1.10 Some CPUs provide for more than two modes of operation. What are
two possible uses of these multiple modes?
1.11 Timers could be used to compute the current time. Provide a short
description of how this could be accomplished.
1.12 Is the Internet a LAN or a WAN?
Exercises
y 1.13 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
machine as in a dedicated machine? Explain your answer.
1.14 The issue of resource utilization shows up in different forms in different
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
44 Chapter 1 Introduction
L/1.15 Under what circumstances would a user be better off using a time-
sharing system rather than a PC or a single-user workstation?
1.16 Identify which of the functionalities listed below need to be supported by
the operating system for (a) handheld devices and (b) real-time systems.
a. Batch programming
b. Virtual memory
c. Time sharing
1.17 Describe the differences between symmetric and asymmetric multipro-
cessing. What are three advantages and one disadvantage of multipro-
cessor systems?
1.18 How do clustered systems differ from multiprocessor systems? What is
required for two machines belonging to a cluster to cooperate to provide
a highly available service?
1.19 Distinguish between the client-server and peer-to-peer models of
distributed systems.
1.20 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 disadvantages of
each.
1.21 How are network computers different from traditional personal com-
puters? Describe some usage scenarios in which it is advantageous to
use network computers.
1.22 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?
N/1.23 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.
1.24 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.
v 1.25 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
Exercises 45
a. Single-processor systems
b. Multiprocessor systems
c. Distributed systems
a. A dormitory floor
b. A university campus
c. A state
d. A nation
a. Batch
b. Interactive
c. Time sharing
d. Real time
e. Network
f. Parallel
g. Distributed
h. Clustered
i. Handheld
Practice Exercises
f 2.1 What is the purpose of system calls?
2.2 What are the five major activities of an operating system with regard to
process management?
2.3 What are the three major activities of an operating system with regard
to memory management?
92 Chapter 2 Operating-System Structures
2.4 What are the three major activities of an operating system with regard
to secondary-storage management?
^ 2.5 What is the purpose of the command interpreter? Why is it usually
separate from the kernel?
2.6 What system calls have to be executed by a command interpreter or shell
in order to start a new process?
2.7 What is the purpose of system programs?
2.8 What is the main advantage of the layered approach to system design?
What are the disadvantages of using the layered approach?
2.9 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.
2.10 Why do some systems store the operating system in firmware, while
others store it on disk?
2.11 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?
Exercises
x 2.12 The services and functions provided by an operating system can be
divided into two main categories. Briefly describe the two categories
and discuss how they differ.
J 2.13 Describe three general methods for passing parameters to the operating
system.
2.14 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.
2.15 What are the five major activities of an operating system with regard to
file management?
2.16 What are the advantages and disadvantages of using the same system-
call interface for manipulating both files and devices?
J 2.17 Would it be possible for the user to develop a new command interpreter
using the system-call interface provided by the operating system?
2.18 What are the two models of interprocess communication? What are the
strengths and weaknesses of the two approaches?
2.19 Why is the separation of mechanism and policy desirable?
2.20 It is sometimes difficult to achieve a layered approach if two components
of the operating system are dependent on each other. Identify a scenario
in which it is unclear how to layer two system components that require
tight coupling of their functionalities.
Programming Projects 93
Programming Problems
2.27 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 Win32 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. Linux systems provide the ptrace utility, and
Solaris systems use the truss or dtrace command. On Mac OS X, the
ktrace facility provides similar functionality. As Windows systems do
not provide such features, you will have to trace through the Win32
version of this program using a debugger.
Programming Projects
2.28 Adding a system call to the Linux Kernel.
In this project, you will study the system-call interface provided by the
Linux operating system and learn how user programs communicate with
the operating system kernel via this interface. Your task is to incorporate
a new system call into the kernel, thereby expanding the functionality
of the operating system.
Practice Exercises 141
Practice Exercises
3.1 Palm OS provides no means of concurrent processing. Discuss three
major complications that concurrent processing adds to an operating
system.
3.2 The Sun UltraSPARC processor has multiple register sets. Describe what
happens when a context switch occurs if the new context is already
loaded into one of the register sets. What happens if the new context is
in memory rather than in a register set and all the register sets are in
use?
j 3.3 When a process creates a new process using the f ork () operation, which
of the following states is shared between the parent process and the child
process?
a. Stack
b. Heap
c. Shared memory segments
3.4 With respect to the RFC mechanism, consider the "exactly once" semantic.
Does the algorithm for implementing this semantic execute correctly
even if the ACK message back to the client is lost due to a network
problem? Describe the sequence of messages and discuss whether
"exactly once" is still preserved.
3.5 Assume that a distributed system is susceptible to server failure. What
mechanisms would be required to guarantee the "exactly once" semantic
for execution of RPCs?
142 Chapter 3 Processes
Exercises
/ 3.6 Describe the differences among short-term, medium-term, and long-
term scheduling.
y 3.9 Including the initial parent process, how many processes are created by
the program shown in Figure 3.28?
3.10 Using the program in Figure 3.29, identify the values of pid at lines A, B,
C, and D. (Assume that the actual pids of the parent and child are 2600
and 2603, respectively.)
3.11 Give an example of a situation in which ordinary pipes are more suitable
than named pipes and an example of a situation in which named pipes
are more suitable than ordinary pipes.
3.13 Using the program shown in Figure 3.30, explain what the output will
be at Line A.
#include <stdio.h>
#include <unistd.h>
int mainO
{
/* fork a child process */
forkO;
return 0;
}
Figure 3.28 How many processes are created?
Programming Problems 143
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int mainO
{
pid_t pid, pidl;
return 0;
}
Figure 3.29 What are the pid values?
/ 3.14 What are the benefits and the disadvantages of each of the following?
Consider both the system level and the programmer level.
a. Synchronous and asynchronous communication
b. Automatic and explicit buffering
c. Send by copy and send by reference
d. Fixed-sized and variable-sized messages
Programming Problems
task points to the data structures of the parent task, depending on the set of
flags passed to clone ().
Several distributions of the Linux kernel now include the NPTL thread
library. NPTL (which stands for Native POSIX Thread Library) provides a POSIX-
compliant thread model for Linux systems along with several other features,
such as better support for SMP systems, as well as taking advantage of NUMA
support. In addition, the start-up cost for creating a thread is lower with NPTL
than with traditional Linux threads. Finally, with NPTL, the system has the
potential to support hundreds of thousands of threads. Such support becomes
more important with the growth of multicore and other SMP systems.
4.6 Summary
Practice Exercises
4.5 Assume that an operating system maps user-level threads to the kernel
using the many-to-many model and that the mapping is done through
LWPs. Furthermore, the system allows developers to create real-time
threads for use in real-time systems. Is it necessary to bind a real-time
thread to an LWP? Explain.
4.6 A Pthread program that performs the summation function was provided
in Section 4.3.1. Rewrite this program in Java.
I Exercises
a. Register values
b. Heap memory
c. Global variables
d. Stack memory
#include <pthread.h>
#include <stdio.h>
int value = 0;
void *runner(void *param) ; /* the thread */
pid = f orkQ ;
4.16 Modify the socket-based date server (Figure 3.19) in Chapter 3 so that
the server services each client request in a separate thread.
4.17 The Fibonacci sequence is the series of numbers 0,1,1,2,3,5,8,....
Formally, it can be expressed as:
fibo = 0
fibi =1
fibn =
Projects
The set of projects below deal with two distinct topics—naming service and
matrix muliplication.