全部博文(33)
分类: WINDOWS
2011-04-09 09:28:20
The operating system acts as an interface between an application and the hardware. The user
interacts with the hardware from "the other side". The operating system is a set of services which
simplifies development of applications. Executing a program involves the creation of a process by the
operating system. The creates a process by assigning memory and other resources, establish-ing a priority for the process (in multi-tasking systems), loading program code into memory, and executing the program. The program
then interacts with the user and/or other devices and performs its intended function.
操作系统在应用程序和硬件之间扮演了一个接口的角色,用户在(接口的)另外一端和硬件进行交互。操作系统是一个简化了应用程序开发过程的服务的一个集合。执行一个程序牵涉到操作系统创建进程。内核通过分配相应的内存空间和其他资源,在多任务系统中还要确定进程的优先级别,将程序代码载入内存然后执行程序(的一系列工作)来创建一个进程。然后进程才和用户或者其他设备进行交互来发挥它应有的功能。
Interrupts are central to operating systems, as they provide an efficient way for the operating
system to interact with and react to its environment. The alternative—having the operating system "watch" the various sources of input for events (polling) that require
action—can be found in older systems with very small (50 or 60 bytes) but fairly unusual in modern
systems with fairly large stacks. -based programming is directly supported by most modern CPUs. Interrupts provide a computer with
a way of automatically saving local register contexts, and running specific code in response to events
. Even very basic computers support hardware interrupts, and allow the programmer to specify code
which may be run when that event takes place.
中断是操作系统的核心,因为他们为操作系统提供了和他所处的环境之间的交互提供了一种有效的方式。我们可选择的让操作系统监视多样化的输入事件资源,在老的操作系统中我们可以发现非常小的栈(一般50-60字节)但是这些东西在具有相当大的堆栈空间中又变得相当少见了。基于中断的编程技术可以被大多数现代的CPU直接支持。中断机制为计算机提供了一种自动保存本地寄存器上下文、然后执行特殊代码相应输入事件的方式。即便是在最普通的计算机里也支持硬件中断,允许程序员编写在相应事件发生时可以执行的特殊代码。
When an interrupt is received, the computer's hardware automatically suspends whatever program is
currently running, saves its status, and runs computer code previously associated with the interrupt;
this is analogous to placing a bookmark in a book in response to a phone call. In modern operating
systems, interrupts are handled by the operating system's . Interrupts may come from either
the computer's hardware or from the running program.
当系统接收到一个中断时,系统硬件将自动挂起当前正在执行的任何程序,保存它的各种状态,然后执行先前计算机准备好这个中断的的相应代码;这就好比是当接到一个电话时我们把一张书签放进正在读的书一样。在现代的操作系统里,中断是由操作系统内核来处理的。而中断的来源既有可能是硬件,也有可能是正在运行的程序。
When a hardware device triggers an interrupt, the operating system's kernel decides how to deal with
this event, generally by running some processing code. The amount of code being run depends on
the priority of the interrupt (for example: a person usually responds to a smoke detector alarm
before answering the phone). The processing of hardware interrupts is a task that is usually delegated
to software called device driver, which may be either part of the operating system's kernel, part of
another program, or both. Device drivers may then relay information to a running program by
various means.
当一个硬件设备触发一个中断时,操作系统内核决策如何处理这个中断,通常情况是通过运行一段处理代码。执行代码的长度取决于中断的优先级(举例:一个人通常先对一个烟雾报警器做出反应而不是电话铃声)。硬件中断处理是一个驱动程序(可能是操作系统内核的部分代码,也可能是一个程序的部分代码,或者二者兼而有之)的任务。设备驱动程序可能推迟到一个程序的信息,而实现这种效果可以通过不同途径。
A program may also trigger an interrupt to the operating system. If a program wishes to access
hardware for example, it may interrupt the operating system's kernel, which causes control to be
passed back to the kernel. The kernel will then process the request. If a program wishes additional
resources (or wishes to shed resources) such as memory, it will trigger an interrupt to get the kernel's
attention.
一个程序可能也能触发一个对操作系统的中断请求。例如,如果一个程序需要访问硬件,它可能会中断操作系统的内核运行,而这将导致控制权被转交给内核。内核然后来处理这个中断请求。如果一个程序希望额外的资源(或者希望计划中的资源)例如内存,它将会触发一个中断来引起内核的注意。
Protected mode and supervisor mode 保护模式和管理模式Protected mode is used here more generally in operating system theory to refer to all modes which
limit the capabilities of programs running in that mode, providing things like virtual memory addressing
and limiting access to hardware in a manner determined by a program running in supervisor mode.
Similar modes have existed in supercomputers, minicomputers, and mainframes as they are
essential to fully supporting UNIX-like multi-user operating systems.
一般来说,保护模式是在操作系统中使用的更为普遍的模式,为了指出所有的模式当程序在此模式下运行时的缺陷和能力,保护模式提供一些像虚拟内存地址、限制一个正在运行的进程访问内存。在超级计算机、微型机、工作站中都有类似的操作系统模式,这个模式对于支持多用户的系统像Unix是不可缺少的。
When a computer first starts up, it is automatically running in . The first few
programs to run on the computer, being the , and the operating system have
unlimited access to hardware - and this is required because, by definition, initializing a protected environment can only be done
outside of one. However, when the operating system passes control to another program, it can place
the CPU into .
当一个计算机启动时,它将自动在保护模式下运行。最开始的一些程序在计算机上运行,他们是BIOS,启动项加载程序。而且这时操作系统并没有限制访问硬件,这是有必要的,因为初始化一个受保护的环境只能在这个环境之外进行。然而,当操作系统把控制权交给一个程序时,它将把CPU调到保护模式下。
In , programs may have access to a more limited set of the CPU's instructions. A
user program may leave only by triggering an interrupt, causing control to be passed
back to the . In this way the operating system can maintain exclusive control over things like a
ccess to hardware and memory.
在保护模式下,程序可能会获得一个受限制的CPU指令集。一个用户程序要离开保护模式只有通过触发中断的方式,这个中断处理的结果就是控制权被返回给操作系统内核。用这种方式操作系统可以维持在类似于硬件和内存之类的资源上的互斥控制。
The term "protected mode resource" generally refers to one or more CPU registers, which contain
information that the running program isn't allowed to alter. Attempts to alter these resources
generally causes a switch to supervisor mode, where the operating system can deal with the illegal
operation the program was attempting (for example, by killing the program).
术语“保护模式下的资源”通常是指一个或多个寄存器,这些寄存器内含有正在执行的程序不允许改变的信息。试图改变这些信息将会导致一个向保护模式的转换,这里操作系统可以处理程序试图进行的非法操作(例如:终止进程)。
Memory management 内存管理Among other things, a multiprogramming operating system kernel must be responsible for managing
all system memory which is currently in use by programs. This ensures that a program does not
interfere with memory already used by another program. Since programs time share, each program
must have independent access to memory.
除此之外,一个多道程序设计操作系统内核必须负责管理所有的当前被程序占用的内存。这确保了一个进程不会妨碍被其他程序占用的内存。因为程序是分时共享的,每一个程序都将独占内存。
Memory protection enables the kernel to limit a process' access to the computer's memory. Various
methods of memory protection exist, including memory segmentation and paging. All methods require
some level of hardware support (such as the 80286 MMU) which doesn't exist in all computers.
内存保护允许内核限制一个进程访问内存。多样的内存保护方式存在,包括内存分段分页机制。这些所有的方法都需要硬件支持(像80286微处理器单元),并不是在所有的计算机中都能用。
In both segmentation and paging, certain protected mode registers specify to the CPU what memory
address it should allow a running program to access. Attempts to access other addresses will trigger
an interrupt which will cause the CPU to re-enter supervisor mode, placing the kernel in charge. This is called a segmentation violation or
Seg-V for short, and since it is both difficult to assign a meaningful result to such an operation, and
because it is usually a sign of a misbehaving program, the kernel will generally resort to terminating
the offending program, and will report the error.
在分段和分页两种机制中,某种保护模式下CPU指定寄存器所存储的一段地址是允许程序访问的。试图访问其它地址将会触发一个中断这将导致CPU重新进入保护模式,恢复内核的控制权。这被称作为段错误,而由于为这样的操作设定一个有意义的结果非常困难,当然这通常作为一个错误程序的标志,内核将会终结这个错误的进程,然后报告错误。
In most GNU/Linux systems, part of the hard disk is reserved for virtual memory when the Operating
system is being installed on the system. This part is known as swap space. Windows systems use
a swap file instead of a partition.
在大多数GNU/Linux系统中,部分硬盘空间是在安装操作系统时为虚拟内存保留的,这部分被称作为交换分区。Windows系统使用了一个交换文件来代替这部分分区。
Virtual memory
虚拟内存
The use of virtual memory addressing (such as paging or segmentation) means that the kernel can
choose what memory each program may use at any given time, allowing the operating system to
use the same memory locations for multiple tasks.
虚拟内存地址的使用(例如分页和分段)意味着内核可以选择在任何给定时间给每一个程序分配什么样的内存,允许操作系统对于多任务可以使用相同的内存地址。
If a program tries to access memory that isn't in its current range of accessible memory, but
nonetheless has been allocated to it, the kernel will be interrupted in the same way as it would if the
program were to exceed its allocated memory. (See section on memory management.) Under
UNIX this kind of interrupt is referred to as a page fault.
如果一个进程想要访问当前不在可访问内存表里的空间,但现在没有内存可以分配给它时,内核将会以和该进程需要超过的所需要的内存空间时所采取的同样的方式启动中断机制。(看下内存管理这一章节)在UNIX系统下,这种中断将会被认为是一个页错误。
When the kernel detects a page fault it will generally adjust the virtual memory range of the program
which triggered it, granting it access to the memory requested. This gives the kernel discretionary
power over where a particular application's memory is stored, or even whether or not it has actually
been allocated yet.
当内核检测到一个页错误时它将自动适应所触发他的程序的虚拟内存范围,允许他访问内存需要。这在一个特殊的应用存储空间给了内核自由的权利,或者说它实际上到现在还没被分配除去。
In modern operating systems, memory which is accessed less frequently can be temporarily stored
on disk or other media to make that space available for use by other programs. This is called
, as an area of memory can be used by multiple programs, and what that memory area
contains can be swapped or exchanged on demand.
在当代操作系统中,需要低频次访问内存数据可以临时性的储存在硬盘或者其他存储介质上以为其他程序让出内存空间。这个过程称作“交换”,即内存中一个区域可以被多个程序利用,内存区域包含的内容可以很据需要来交换。Multitasking 多任务
Multitasking refers to the running of multiple independent computer programs on the same computer;
giving the appearance that it is performing the tasks at the same time. Since most computers can
do at most one or two things at one time, this is generally done via time-sharing, which means that each program uses a share of the computer's time to execute.
多任务指的是多个独立的计算机程序在一台计算机上运行;给人的印象就好像是它在同时执行着多个任务。由于大多数电脑能同时做至多两件事情,这就是主要分时共享来实现了,这意味着每一个程序使用电脑时间的一部分来执行自己代码。
An operating system kernel contains a piece of software called a scheduler which determines how
much time each program will spend executing, and in which order execution control should be
passed to programs. Control is passed to a process by the kernel, which allows the program access
to the CPU and memory. Later, control is returned to the kernel through some mechanism, so that
another program may be allowed to use the CPU. This so-called passing of control between the kernel and applications is called a context switch.
一个操作系统内核包含有一系列被称作计划程序的软件,这些软件决定了每个程序将会花费多少时间,按照何种顺序执行,这些信息都需要传给进程,而控制信息由内核传递给进程,它允许进程访问CPU和内存。然后控制信息又通过一些硬件电平信号传给内核,以使进程被允许使用CPU。这中控制信号在内核和应用程序之间进行传递被称作上下位切换。
An early model which governed the allocation of time to programs was called cooperative multitasking.
In this model, when control is passed to a program by the kernel, it may execute for as long as it
wants before explicitly returning control to the kernel. This means that a malicious or malfunctioning
program may not only prevent any other programs from using the CPU, but it can hang the entire
system if it enters an infinite loop.
一种管理进程时间的分配早期的模式被称作非抢占式多任务。在这个模式中,当控制信号被内核传递给进程时,在返回控制权给内核之前它将会继续执行下去只要它想这样做的话。这意味着一个恶意的程序不仅可以阻止任何其他程序使用CPU资源,而且当它陷入死循环时它甚至可以导致这个系统的崩溃。
The philosophy governing preemptive multitasking is that of ensuring that all programs are given
regular time on the CPU. This implies that all programs must be limited in how much time they are
allowed to spend on the CPU without being interrupted. To accomplish this, modern operating system
kernels make use of a timed interrupt. A protected mode timer is set by the kernel which triggers a
return to supervisor mode after the specified time has elapsed.
一种具有哲学管理理念的可抢占式的多任务系统就是可以确保所有的进程都被给一定的时间去使用CPU。这种模式下所有的进程必须被限制在在一段时间里可以使用CPU且不会被中断。为了完成这一点,现代操作系统内核使用了时间片轮转的办法。一个保护模式下的时间段长度由内核设定,当时间用完时它将会触发一个终端返回管理状态。
Kernel preemption
内核的可抢占式
In recent years, concerns have arisen because of long latencies associated with some kernel run-times, sometimes on the order of 100 ms or more in systems with monolithic kernels. These latencies
often produce noticeable slowness in desktop systems, and can prevent operating systems from
performing time-sensitive operations such as audio recording and some communications.
近几年, 由于和内核运行时间相关的一些潜在因素的影响使得人们对可抢占式内核的关注度不断上升。这些潜在因素经常导致桌面系统的运行显著变慢,甚至可以阻止一些时间敏感的操作系统像录音、通讯系统的运行。
Modern operating systems extend the concepts of application preemption to device drivers and kernel
code, so that the operating system has preemptive control over internal run-times as well. Under Windows Vista, the introduction of the Windows Display Driver Model (WDDM)
accomplishes this for display drivers, and in GNU/Linux, the preemptable kernel model introduced in
version 2.6 allows all device drivers and some other parts of kernel code to take advantage of
preemptive multi-tasking.
当代的操作系统将抢占式应用的概念扩展到了设备驱动和内核代码,以使操作系统对内部运行时间的优先控制权。在Vista系统下,视窗显示驱动模型的引入做到了这一点,在GNU/Linux系统下这种抢占式内核模块在2.6版本被引入,这允许所有的设备和其它的一些内核代码充分利用可抢占式多任务系统。
Under Windows versions prior to Windows Vista and Linux prior to version 2.6 all driver execution was
co-operative, meaning that if a driver entered an infinite loop it would freeze the system.
在Windows中的Vista和Linux中的2.6内核之前,所有的驱动执行是在一起的,这意味着如果一个驱动程序进入死循环整个系统就将被冰冻。
Disk access and file systems 硬盘访问和文件系统Access to data stored on disks is a central feature of all operating systems. Computers store data on
using , which are structured in specific ways in order to allow for faster access, higher
reliability, and to make better use out of the drive's available space. The specific way in which files
are stored on a disk is called a file system, and enables files to have names and attributes. It also
allows them to be stored in a hierarchy of directories or folders arranged in a directory tree.
访问存储在硬盘上的数据是所有操作系统的一个主要功能。计算机以文件的形式把数据保存在硬盘上,为了高速存取,高可靠性的目的,也为了充分利用硬盘上的可用空间,它们被以特殊方式有结构的组织在一起。这种文件被存储在硬盘上的特殊方式被称作是文件系统,它允许文件具有名字和属性,也允许它们被以目录树的形式安排存储在一个分层的目录文件里。
While many simpler operating systems support a limited range of options for accessing storage
systems, operating systems like and support a technology known as a virtual file
system or VFS. An operating system like UNIX supports a wide array of storage devices, regardless
of their design or file systems to be accessed through a common application programming interface
(API). This makes it unnecessary for programs to have any knowledge about the device they are
accessing. A VFS allows the operating system to provide programs with access to an unlimited number
of devices with an infinite variety of file systems installed on them through the use of specific device
drivers and file system drivers.
当许多较简单的操作系统支持有限选择性的访问存储系统时,像UNIX和GNU/LINUX已经开始支持被叫做虚拟文件系统的新技术了。像UNIX一样的操作系统开始支持通过一个公共的应用程序接口访问一个存储设备阵列,不论这些存储设备的是怎样被设计、采用何种文件系统。这让下面一个观点变得不再是不可或缺的了,它就是程序必须了解所有它们正在访问的设备的工作方式。一个VFS可以让操作系统通过安装在它们上各种驱动程序和文件系统驱动的支持程序访问各种各样的文件系统。
A connected storage device such as a hard drive is accessed through a device driver. The device
driver understands the specific language of the drive and is able to translate that language into a
standard language used by the operating system to access all disk drives. On UNIX, this is the
language of block devices.
一个被连接的存储设备例如硬盘,是通过设备驱动被访问的。这个设备驱动懂得和这个设备交流的“语言”,它能够将将这种语言翻译成操作系统用于访问所有设备的通用“语言”。在UNIX下,就是设备块。
When the kernel has an appropriate device driver in place, it can then access the contents of the disk
drive in raw format, which may contain one or more file systems. A file system driver is used to
translate the commands used to access each specific file system into a standard set of commands
that the operating system can use to talk to all file systems. Programs can then deal with these file
systems on the basis of filenames, and directories/folders, contained within a hierarchical structure.
They can create, delete, open, and close files, as well as gather various information about them,
including access permissions, size, free space, and creation and modification dates.
Various differences between file systems make supporting all file systems difficult. Allowed characters
in file names, case sensitivity, and the presence of various kinds of file attributes makes the
implementation of a single interface for every file system a daunting task. Operating systems
tend to recommend using (and so support natively) file systems specifically designed for them;
for example, NTFS in Windows and ext3 and ReiserFS in GNU/Linux. However, in practice, third
party drives are usually available to give support for the most widely used file systems in most
general-purpose operating systems (for example, NTFS is available in GNU/Linux through
NTFS-3g, and ext2/3 and ReiserFS are available in Windows through FS-driver and rfstool).
当内核在合适的地方有一个合适的设备驱动时,它才可以访问没有格式化的硬盘里的内容,这时的硬盘可能会有一个或者多个文件系统。一个文件系统驱动程序一般是将访问某种特定文件系统的命令翻译成操作系统可以用来和各种各样的文件系统交换信息的标准命令集合。程序然后才可以在基于文件名程、包含层式目录的属性来处理这些文件系统。它们可以创建、打开、删除和关闭文件,也可以获取关于这些文件的而各种信息,包括访问权限,大小,可用空间,创建和修改日期。不同文件系统之间各种各样的差异导致支持各种文件系统是很困难的。文件名中允许包含的字符、环境敏感性,以及多种多样的文件属性的表述让对各种操作系统只有一个单一接口实现起来真是一项很繁重的工作。操作系统倾向于使用一些专门为它们设计的文件系统,例如Windows中的NTFS,GNU/LINUX中的EXT3格式文件系统。然而,在实践中,第三方驱动通常用于支持许多在大多数操作系统广泛使用的文件系统(例如,GNU/Linux系统通过NTFS-3g可以使用NTFS文件系统,Windows通过FS-driver和rfs-tool可以访问ext2/3文件系统)。