Operating System Concepts 9th: Chapter 1 Introduction
An operating system is a program that manages a computer’s hardware. It
also provides a basis for application programs and acts as an intermediary
between the computer user and the computer hardware.
操作系统的定义:一个管理计算机硬件,并作为用户与硬件之间的中介为应用程序提供基础的程序。
What Operating Systems Do
From the computer’s point of view, the operating system is the program
most intimately involved with the hardware. In this context, we can view
an operating system as a resource allocator.
从计算机的角度看,操作系统与硬件联系紧密,是资源分配者。
the operating system is the one program running at all times on the
computer—usually called the kernel. (Along with the kernel, there are two
other types of programs: system programs, which are associated with the
operating system but are not necessarily part of the kernel, and applic-
ation programs, which include all programs not associated with the oper-
ation of the system.)
操作系统是一个在计算机运行期间一直在running的程序,也被称为内核。除了内核外还有另外两种程序:系统程序,直接与操作系统交互,但不属于内核。应用程序,不直接与
操作系统交互。
Computer-System Organization
For a computer to start running—for instance, when it is powered up or
rebooted—it needs to have an initial program to run. This initial program,
or bootstrap program, tends to be simple. Typically, it is stored within
the computer hardware in read-only memory (ROM) or electrically erasable
programmable read-only memory (EEPROM), known by the general term
firmware. It initializes all aspects of the system, from CPU registers to device
controllers to memory contents. The bootstrap program must know how to load
the operating system and how to start executing that system. To accomplish
this goal, the bootstrap program must locate the operating-system kernel and
load it into memory.
计算机启动时先启动固件(ROM或EEPROM)中的bootstrap程序,由该程序初始化整个系统,然后加载并执行操作系统内核。
Some services are provided outside of the kernel, by system programs that
are loaded into memory at boot time to become system processes, or system
daemons that run the entire time the kernel is running. On UNIX, the first system
process is “init,” and it starts many other daemons. Once this phase is complete,
the system is fully booted, and the system waits for some event to occur.
内核加载完毕后会加载系统程序,使他们成为系统进程或称守护进程,并且在整个内核运行期间都存在。在UNIX中第一个系统进程是
init进程,他还会启动许多其他守护进程。一旦这一阶段完成,系统就完全启动了,开始等待事件发生。
The occurrence of an event is usually signaled by an interrupt from either
the hardware or the software. Hardware may trigger an interrupt at any time
by sending a signal to the CPU, usually by way of the system bus. Software
may trigger an interrupt by executing a special operation called a system call
事件通常由中断触发,硬件中断由硬件通过系统总线发信号给CPU触发,软件中断通过执行系统调用触发。
Operating-System Structure
One of the most important aspects of operating systems is the ability
to multiprogram. A single program cannot, in general, keep either the CPU
or the I/O devices busy at all times. Single users frequently have multiple
programs running.Multiprogramming increases CPU utilization by organizing
jobs (code and data) so that the CPU always has one to execute.
操作系统最重要的一个方面就是多道程序的能力。多道程序设计可以增加CPU的利用率。
The idea is as follows: The operating system keeps several jobs in memory
simultaneously (Figure 1.9). Since, in general, main memory is too small to
accommodate all jobs, the jobs are kept initially on the disk in the job pool.
This pool consists of all processes residing on disk awaiting allocation of main
memory.
为了实现多道程序,操作系统要把多个任务同时放入内存,但内存太小了,所以任务一开始会被放到磁盘的任务池中,等待被分配内存。
In a multiprogrammed system, the operating system simply switches to,
and executes, another job. When that job needs to wait, the CPU switches to
another job, and so on. Eventually, the first job finishes waiting and gets the
CPU back. As long as at least one job needs to execute, the CPU is never idle.
多道程序系统中,操作系统会在一个任务需要等待时将CPU切换给另一个任务,并且等待结束时将CPU还给它。这样只要由任务需要执行CPU就不会空闲。
Time sharing (or multitasking) is a logical extension of multiprogramming.In
time-sharing systems, the CPU executes multiple jobs by switching among them,
but the switches occur so frequently that the users can interact with each program
while it is running.
分时是多道程序设计的扩展,CPU频繁地在多个进程间切换以达到用户可以与多个进程交互的目的。
A program loaded into memory and executing is called a process.
被加载到内存中并且正在执行的程序叫做进程。
If several jobs are ready to be brought into memory, and if there is not enough room
for all of them, then the system must choose among them. Making this decision involves
job scheduling
任务调度决定磁盘中哪个任务被加载到内存。
if several jobs are ready to run at the same time, the system must choose which job
will run first. Making this decision is CPU scheduling.
CPU调度决定内存中哪个任务被执行。
In a time-sharing system, the operating system must ensure reasonable
response time. This goal is sometimes accomplished through swapping,
whereby processes are swapped in and out of main memory to the disk. A more
common method for ensuring reasonable response time is virtual memory, a
technique that allows the execution of a process that is not completely in
memory. The main advantage of the virtual-memory scheme is that it
enables users to run programs that are larger than actual physical memory.
Further, it abstracts main memory into a large, uniform array of storage,
separating logical memory as viewed by the user from physical memory.
This arrangement frees programmers from concern over memory-storage
limitations.
为了保证实时交互,进程需要在内存与磁盘间交换。一个重要的方法就是虚拟内存,可以使程序部分加载,此外还可以使用户运行大于物理内存的程序,并将内存抽象为一个统一的数组,即逻辑内存,使程序员可以摆脱物理内存的限制。
Operating-System Operations
A trap (or an exception) is a software-generated interrupt caused
either by an error (for example, division by zero or invalid memory access)
or by a specific request from a user program that an operating-system service
be performed.
陷入是一种由软件触发的中断,可能是发生了错误也可能是需要系统服务。
we need two separate modes of operation: user mode and kernel mode (also
called supervisor mode, system mode, or privileged mode). A bit, called the
mode bit, is added to the hardware of the computer to indicate the current
mode:kernel (0) or user (1).
为了系统的安全性,我们将系统分为两种模式:用户模式和内核模式。由mode bit来区分当前处于哪种模式。
when a user application requests a service from the operating system (via a
system call), the system must transition from user to kernel mode to fulfill
the request.
当用户程序请求系统服务时系统由用户模式切换到内核模式。
At system boot time, the hardware starts in kernel mode.
系统启动时处于内核模式。
The dual mode of operation provides us with the means for protecting the
operating system from errant users—and errant users from one another. We
accomplish this protection by designating some of the machine instructions that
may cause harm as privileged instructions. The hardware allows privileged
instructions to be executed only in kernel mode. If an attempt is made to
execute a privileged instruction in user mode, the hardware does not execute
the instruction but rather treats it as illegal and traps it to the operating system.
为了防止恶意的用户,我们将可能造成损害的指令设为特权指令,只有在内核模式才能执行,当在用户模式想要执行特权指令时会发生trap.
Initial control resides in the operating system, where instructions are executed
in kernel mode. When control is given to a user application, the mode is set to
user mode. Eventually, control is switched back to the operating system via an
interrupt, a trap, or a system call.
当控制权交给用户程序时系统会切换到用户模式,最终会由中断,陷入,或系统调用将控制权交回给操作系统。
When a system call is executed, it is typically treated by the hardware
as a software interrupt. Control passes through the interrupt vector to a
service routine in the operating system, and the mode bit is set to kernel
mode.
当执行系统调用时,硬件会将其视为软中断,控制权会通过中断向量转移给系统服务例程,并将模式设为内核模式。