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.

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.

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 is of course assume 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 serial line, for instance).

It is still alive. For example, Intel makes Pentium I, II, and III, and 4 CPUs with a variety of different properites including spped and power consumption. All of these machines ar architecturally compatible. They differ only in price and perfermance, which is the essence of the family idea.

A 25x80 character monochrome text screen requires a 2000-byte buffer. 2580=2000 The 1024x768 pixel 24-bit color bitmap requires 2359296 bytes. 102476824/8=2359296 In 1980 these two options would have cost $10 and $11520, respectively. 20005/1024=9.77 2359296*5/1024=11520 For current prices, check on how much RAM currently costs, probably less than $1/MB.

Consider fairness and real time. Fairness requires that each process be allocated it 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.

a)禁止所有的中断。 b)读日期-时间时钟。 c)设置日期-时间时钟。 d)改变存储器映像。



It may take 20, 25, 30 or 35 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 mses. 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.

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.


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

The manuscript contains 80 X 50 X 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 ( 2.8 X 10^6 X 10^-9 s) from the registers or 5.8 msec (2.8 X 10^6 X 2 X 10^-9 s) from the cache. There are approximately 2700 ( 2.8 X 10^6 % 1024 = 2735 ) 1024-byte blocks of data, so scanning from the disk would require about 27 seconds (2700 X 10 X 10^-3= 27s ), and from tape 2 minutes 7 senconds ( 100 + 27 = 127s tape不考虑读入时的文件大小? ).

Maybe. If the caller get control back and immediately overwrites the data, when the write finally occurs, the wrong data will be written. However, if the driver first copied the data to a private buffer before returning, then the caller can be allowed to continue immediately. Another possiblity is to allow the caller to continue and give it a singal when the buffer may be used, but this is tricky and error prone.

A trap instruction switches the execution mode of a CPU from the user mode to the kernel mode. This instruction allow a user program to invoke functions in the operation system kernel.

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 exactly the same position in the instruction stream. An interrupt is caused by an external event and its timing is not reproducible.

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.

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 noraml path in an emergency when the mounted device was being repaired.

A system call allows a user process to access and execute operating system functions indside the kernel. User programs use system calls to invoke operating system services.

Fork can fail if there are no free slot left in the process table (and possibley 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 authority to unlink it.

19.在count = write(fd, buffer, nbytes);调用中,能在count中而不是nbytes中返回值吗?如果能,为什么?
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 return nbytes.

20.有一个文件,其文件描述符是fd,内含字节序列:3,1,4,1,5,9,2,6,5,3,5。有如下系统调用:lseek(fd,3,SEEK_SET); read(fd,&buffter,4); 其中lseek调用寻找文件中的字节3。在读操作完成后,buffer中的内容是什么?
It contains the bytes: 1, 5, 9, 2.


Time to retrieve the file = 1 * 50 ms (Time to move the arm over track # 50)

  • 5 ms (Time for the first sector to rotate under the head)
  • 10/100 * 1000 ms (Read 10 MB) = 155 ms

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 and writing. This is not possible with character specical files.

System calls do not really have names, other than in a documentation sence. When the libray procedure read traps to the kernel, it puts the number of the system call in a register ro 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 import, since this is what appears in the program.

Yes it can, especially if the kernel is message-passing system.

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 perfermance 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 operatiing system may schedule another process o run when a system call completes, further slowing the progress in real time of a calling process.

26.图1-23说明有一批UNIX的系统调用没有与之相等价的Win32 API。对于所列出的每一个没有Win32等价的调用,若程序员要把一个UNIX程序转换到Windows下运行,会有什么后果?
Serval UNIX calls have no counterpart in the Win32 API: Link: a Win32 program cannot refer to a file by an alternative name or see it in more than one directory. Also, attempting to create a link is a convenient way to test fro 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 uses access control lists Kill: Windows programmers cannot kill a misbehaving program that is not cooperating.

Every system architecture has its own set of instructions that it can execute. Thus a Pentumn cannot excute SPARC programs and 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 machine-dependent 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 onece. To be highly protable, the size of the machine-dependent layer must be kept as small as possible.

Separation of policy and mechanism allows OS designers to implement a small number of basic primitives in the kernel. These primitives are simpified, 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.


a) A micro year is 10^-6 X 365 X 24 X 3600 = 31.536 sec.
b) 10^9*10^-6=1000m
c) 2^10 X 2^10 X 2^10 X 2^10 = 2^40 Bytes
d) 6000 X 10^24 X 10^-3 = 6 X 10^24 kilogram


31.如果读者拥有一个个人UNIX类操作系统(Linux/MINIX/FreeBSD等),可以安全地崩溃和再启动,请写一个可以试图创建一个无限制数量子进程的shell脚本并观察所发生的事。在运行实验之前 ,通过shell键入sync,在磁盘上备份好文件缓冲区以避免毁坏文件系统。(注意:在没有得到系统管理呐的允许之前,不要在分时系统上进行这一尝试。其后果将会立即发生,尝试者可能会被抓住并受到惩罚。)

32.用一个类似于UNIX od或MS-DOS DEBUG的程序考察并尝试解释UNIX类系统或Windows的目录。提示:如何进行取决于OS允许做什么。一个有益的技巧是在一个有某个操作系统的软盘上创建一个目录,然后使用一个允许进行此类的访问的不同的操作系统读盘上的原始数据。


《现代操作系统》精读与思考笔记 第一章 引论