CS703 - Advanced Operating Systems
Course Page
Q & A
Short Question & Answers
Solution Manual
Modern Operating Systems by Tanenbaum
CH:01 - Introduction
1. What are the two main functions of an operating system?
An operating system must provide the user with an extended (i.e. virtual) machine, and it must manage the I/O devices and other system resources.
2. What is the difference between timesharing and multiprogramming systems?
Multiprogramming is the rapid switching of the CPU between multiple processes in memory. It is commonly used to keep the CPU busy while one or more processes are doing I/O.
3. What is multiprogramming?
Multiprogramming is the rapid switching of the CPU between multiple processes in memory. It is commonly used to keep the CPU busy while one or more processes are doing I/O.
4. What is spooling? Do you think that advanced personal computer will have spooling as a standard feature in the future?
Input spooling is the technique of reading in jobs, for example, from cards, onto the disk, so that when the currently executing processes are finished, there will be work waiting for the CPU. Output spooling consists of first copying printable files to disk before printing them, rather than printing directly as the output is generated. Input spooling on a personal computer is not very likely, but output spooling is.
5. On early computers, every byte of data read or written was handled by the CPU (i.e., there was no DMA). What implications does this have for multiprogramming?
The prime reason for multiprogramming is to give the CPU something to do while waiting for I/O to complete. If there is no DMA, the CPU is fully occupied doing I/O, so there is nothing to be gained (at least in terms of CPU utilization) by multiprogramming. No matter how much I/O a program does, the CPU will be 100% busy. This of course assumes the major delay is the wait while data are copied. A CPU could do other work if the I/O were slow for other reasons (arriving on a serial line, for instance).
6. Why was timesharing not widespread on second-generation computers?
Second generation computers did not have the necessary hardware to protect the operating system from malicious user programs.
7. The family of computers idea was introduced in the 1960s with the IBM System/360 mainframes. Is this idea now dead as a doornail or does it live on?
It is still alive. For example, Intel makes Pentium I, II, and III, and 4 CPUs with a variety of different properties including speed and power consumption. All of these machines are architecturally compatible. They differ only in price and performance, which is the essence of the family idea.
8. Consider a system that has two CPUs and each CPU has two threads (hyperthreading). Suppose three programs, P0, PI, and P2, are started with run times of 5, 10 and 20mses, respectively. How long will it take to complete the execution of these programs? Assume that all three programs are 100% CPU bound, do not block during execution, and do not change CPUs once assigned.
It may take 20, 25 or 30 msec to complete the execution of these programs depending on how the operating system schedules them. If P0 and P1 are scheduled on the same CPU and P2 is scheduled on the other CPU, it will take 20 msec. If P0 and P2 are scheduled on the same CPU and P1 is scheduled on the other CPU, it will take 25 msec. If P1 and P2 are scheduled on the same CPU and P0 is scheduled on the other CPU, it will take 30 msec. If all three are on the same CPU, it will take 35 msec.
9. One reason GUIs were initially slow to be adopted was the cost of the hardware needed to support them. How much video RAM is needed to support a 25 line x 80 row character monochrome text screen? How much for a 1024 x 768 pixel 24-bit color bitmap? What was the cost of this RAM at 1980 prices ($5/KB)? How much is it now?
A 25 × 80 character monochrome text screen requires a 2000-byte buffer. The 1024 × 768 pixel 24-bit color bitmap requires 2,359,296 bytes. In 1980 these two options would have cost $10 and $11,520, respectively. For current prices, check on how much RAM currently costs, probably less than $1/MB.
10. There are several design goals in building an operating system, for example, resource utilization, timeliness, robustness, and so on. Give an example of two design goals that may contradict one another.
Consider fairness and real time. Fairness requires that each process be allocated its resources in a fair way, with no process getting more than its fair share. On the other hand, real time requires that resources be allocated based on the times when different processes must complete their execution. A real time process may get a disproportionate share of the resources.
11. A computer has a pipeline with four stages. Each stage takes the same time to do its work, namely 1 nsec. How many instructions per second can this machine execute?
Every nanosecond one instruction emerges from the pipeline. This means the machine is executing 1 billion instructions per second. It does not matter at all how many stages the pipeline has. A 10-stage pipeline with 1 nsec per stage would also execute 1 billion instructions per second. All that matters is how often a finished instruction pops out the end of the pipeline.
12. Which of the following instructions should be allowed only in kernel mode?
(a) Disable all interrupts.
(b) Read the time-of-day clock.
(c) Set the time-of-day clock.
(d) Change the memory map.
Choices (a), (c), and (d) should be restricted to kernel mode.
13. List some differences between personal computer operating systems and mainframe operating systems.
Personal computer systems are always interactive, often with only a single user. Mainframe systems nearly always emphasize batch or timesharing with many users, protection is much more of an issue on mainframe systems, as is efficient use of all resources.
14. Consider a computer system that has cache memory, main memory (RAM) and disk, and the operating system uses virtual memory. It takes 2 μsec to access a word from the cache, 10 nsec to access a word from the RAM, and 10 ms to access a word from the disk. If the cache hit rate is 95% and main memory hit rate (after a cache miss) is 99%, what is the average time to access a word?
Average access time = 0.95 × 2 nsec (word is cache)
                                        + 0.05 × 0.99 × 10 nsec (word is in RAM, but not in cache)
                                                  + 0.05 × 0.01 × 10,000,000 nsec (word on disk only)
                                   = 5002.395 nsec = 5.002395 μsec
15. What is a trap instruction? Explain its use in operating systems.
A trap instruction switches the execution mode of a CPU from the user mode to the kernel mode. This instruction allows a user program to invoke functions in the operating system kernel.
16. What is the key difference between a trap and an interrupt?
A trap is caused by the program and is synchronous with it. If the program is run again and again, the trap will always occur at exactly the same position in the instruction stream. An interrupt is caused by an external event and its timing is not reproducible.
17. When a user program makes a system call to read or write a disk file, it provides an indication of which file it wants, a pointer to the data buffer, and the count. Control is then transferred to the operating system, which calls the appropriate driver. Suppose that the driver starts the disk and terminates until an interrupt occurs. In the case of reading from the disk, obviously the caller will have to be blocked (because there are no data for it). What about the case of writing to the disk? Need the caller be blocking awaiting completion of the disk transfer?
Maybe. If the caller gets control back and immediately overwrites the data, when the write finally occurs, the wrong data will be written. However, if the driver first copies the data to a private buffer before returning, then the caller can be allowed to continue immediately. Another possibility is to allow the caller to continue and give it a signal when the buffer may be reused, but this is tricky and error prone.
18. Why is the process table needed in a timesharing system? Is it also needed in personal computer systems in which only one process exists, that process taking over the entire machine until it is finished?
The process table is needed to store the state of a process that is currently suspended, either ready or blocked. It is not needed in a single process system because the single process is never suspended.
19. Is there any reason why you might want to mount a file system on a nonempty directory? If so, what is it?
Mounting a file system makes any files already in the mount point directory inaccessible, so mount points are normally empty. However, a system administrator might want to copy some of the most important files normally located in the mounted directory to the mount point so they could be found in their normal path in an emergency when the mounted device was being checked or repaired.
20- What is the purpose of a system call in an operating system?
A system call allows a user process to access and execute operating system functions inside the kernel. User programs use system calls to invoke operating system services.
21. What is the essential difference between a block special file and a character special file?
Block special files consist of numbered blocks, each of which can be read or written independently of all the other ones. It is possible to seek to any block and start reading or writing. This is not possible with character special files.
22. In the example given in Fig. 1-17, the library procedure is called read and the system call itself is called read. Is it essential that both of these have the same name? If not, which one is more important?
System calls do not really have names, other than in a documentation sense. When the library procedure read traps to the kernel, it puts the number of the system call in a register or on the stack. This number is used to index into a table. There is really no name used anywhere. On the other hand, the name of the library procedure is very important, since that is what appears in the program.
23. The client-server model is popular in distributed systems. Can it also be used in a single-computer system?
Yes it can, especially if the kernel is a message-passing system.
24. To a programmer, a system call looks like any other call to a library procedure. Is it important that a programmer know which library procedures result in system calls? Under what circumstances and why?
As far as program logic is concerned it does not matter whether a call to a library procedure results in a system call. But if performance is an issue, if a task can be accomplished without a system call the program will run faster. Every system call involves overhead time in switching from the user context to the kernel context. Furthermore, on a multiuser system the operating system may schedule another process to run when a system call completes, further slowing the progress in real time of a calling process.
25. Figure 1-23 shows that a number of UNIX system calls have no Win32 API equivalents. For each of the calls listed as having no Win32 equivalent, what are the consequences for a programmer of converting a UNIX program to run under Windows?
Several UNIX calls have no counterpart in the Win32 API:

Link: a Win32 program cannot refer to a file by an alternate name or see it in more than one directory. Also, attempting to create a link is a convenient way to test for and create a lock on a file.

Mount and umount: a Windows program cannot make assumptions about standard path names because on systems with multiple disk drives the drive name part of the path may be different.

Chmod: Windows programmers have to assume that every user can access every file.

Kill: Windows programmers cannot kill a misbehaving program that is not cooperating.
26. A portable operating system is one that can be ported from one system architecture to another without any modification. Explain why it is infeasible to build an operating system that is completely portable. Describe two high-level layers that you will have in designing an operating system that is highly portable.
Every system architecture has its own set of instructions that it can execute. Thus a Pentium cannot execute SPARC programs and a SPARC cannot execute Pentium programs. Also, different architectures differ in bus architecture used (such as VME, ISA, PCI, MCA, SBus, ...) as well as the word size of the CPU (usually 32 or 64 bit). Because of these differences in hardware, it is not feasible to build an operating system that is completely portable. A highly portable operating system will consist of two high-level layers---a machinedependent layer and a machine independent layer. The machine-dependent layer addresses the specifics of the hardware, and must be implemented separately for every architecture. This layer provides a uniform interface on which the machine-independent layer is built. The machine-independent layer has to be implemented only once. To be highly portable, the size of the machinedependent layer must be kept as small as possible.
27. Explain how separation of policy and mechanism aids in building microkernel-based operating systems.
Separation of policy and mechanism allows OS designers to implement a small number of basic primitives in the kernel. These primitives are simplified, because they are not dependent of any specific policy. They can then be used to implement more complex mechanisms and policies at the user level.
28. Here are some questions for practicing unit conversions:
(a) How long is a microyear in seconds?
(b) Micrometers are often called microns. How long is a gigamicron?
(c) How many bytes are there in a I-TB memory?
(d) The mass of the earth is 6000 yottagrams. What is that in kilograms?
(a) A micro year is 10−6 × 365 × 24 × 3600 = 31.536 sec.
(b) 1000 meters or 1 km.
(c) There are 240 bytes, which is 1,099,511,627,776 bytes.
(d) It is 6 × 1024 kg.
29. An alert reviewer notices a consistent spelling error in the manuscript of an operating systems textbook that is about to go to press. The book has approximately 700 pages, each with 50 lines of 80 characters each. How long will it take to electronically scan the text for the case of the master copy being in each of the levels of memory of Fig. 1-7? For internal storage methods, consider that the access time given in per character, for disk devices assume the time is per block of 1024 characters, and for tape assume the time given is to the start of the data with subsequent access at the same speed as disk access.
The manuscript contains 80 × 50 × 700 = 2.8 million characters. This is, of course, impossible to fit into the registers of any currently available CPU and is too big for a 1-MB cache, but if such hardware were available, the manuscript could be scanned in 2.8 msec from the registers or 5.8 msec from the cache. There are approximately 2700 1024-byte blocks of data, so scanning from the disk would require about 27 seconds, and from tape 2 minutes 7 seconds. Of course, these times are just to read the data. Processing and rewriting the data would increase the time.
30. Can the;          count = write(fd, buffer, nbytes);
Call return any value in count other than nbytes? If so, why?
If the call fails, for example because fd is incorrect, it can return −1. It can also fail because the disk is full and it is not possible to write the number of bytes requested. On a correct termination, it always returns nbytes.
31. For each of the following system calls, give a condition that causes it to fail: fork, exec, and unlink.
Fork can fail if there are no free slots left in the process table (and possibly if there is no memory or swap space left). Exec can fail if the file name given does not exist or is not a valid executable file. Unlink can fail if the file to be unlinked does not exist or the calling process does not have the authority to unlink it.
32. A file whose file descriptor is fd contains the following sequence of bytes: 3,1,4,1,5,9,2,6,5,3,5. The following system calls are made:
lseek(fd, 3, SEEK_SET);
read(fd, &buffer, 4);
where the lseek call makes a seek to byte 3 of the file. What does buffer contain after the read has completed?
It contains the bytes: 1, 5, 9, 2.
33. What is the difference between kernel and user mode? Explain how having two distinct modes aids in designing an operating system.
Operating System's were designed with two different major operative mode.

Kernel Mode:
In the kernel mode running codes can access to hardware directly and here we can see any CPU instruction and reference can put any memory address. I mean in this mode the codes run directly hardware with no restriction, it can be put and access memory directly. The Kernel mode is safety place of the operating system that hides important things from the users who wants to damage the system, operating system seperate kernel programs and user programs in the different modes.For instance, when we install a hardware driver(software) use kernel mode. In addition, Kernel mode crashes will be hard to solve it is not recoverable.

User Mode:
In the user mode running codes can not access to hardware directly(access thanks to system calls) and can not put any referance to memory directly. We can say it is normal mode that we use the programs like internet explorer, media player etc, in this mode.Most of the codes running, the computer works in this mode.It is not access directly any important place to Operating System so if there is a problem in here, it can be recoverable, only that application crash, not entire system.

I explained something what is kernel and user mode. They are enforced from CPU hardware and they are extremely important for operating system safety, because of the user can not use kernel mode that includes critical data structures operates machine, direct hardware and direct memory accessing, if there is any harm to system, the main system will be halt.Thanks to this distinct the user can use the user mode and operating system avoid to meet any harm. Because, the user can not access any important place.
Course Instructor

Mr. Farhan Zaidi
MS Computer Science
University of Southern California, USA

Modern Operating Systems by Tanenbaum

Operating Systems Internals and Design Principles by William Stallings

Operating Systems by Gary Nutt

Computer Systems: A programmer’s perspective
by Randal E. Bryant & David R.