Operating System 简明教程

Operating System - Architecture

操作系统允许用户应用程序与系统硬件进行交互。由于操作系统是一个如此复杂的结构,因此其架构对其使用情况起着重要的作用。操作系统架构的每个组件都应明确定义,具有明确的输入、输出和功能。

An operating system allows the user application programs to interact with the system hardware. Since the operating system is such a complex structure, its architecture plays an important role in its usage. Each component of the Operating System Architecture should be well defined with clear inputs, outputs and functions.

Import Terms

在操作系统架构中,我们有两个主要术语,它们定义了操作系统的主要组件。

In operating system Architecture, we’ve two major terms which defines the major components of the operating systems.

  1. Kernal − Kernal is the central component of an operating system architecture in most of the implementation. A kernal is responsible for all major operations and interaction with the hardware. A kernal manages memory, processor, input/output devices and provides interface to application programs to interact with hardware components.

  2. Shell − Shell is an interface of an operating system. It can be command line interface or a graphical user interface. User interacts with an operating system using shell. Application programs can also use shell interface to interact with underlying operating system.

  3. System Softwares − System softwares are the programs which interact with Kernal and provides interface for security managment, memory management and other low level activities.

  4. Application Programs − Application softwares/Programs are the one using which a user interacts with the operating system. For example a word processor to create a document and save it on the file system, a notepad to create notes etc.

以下是操作系统架构的各种流行实现。

Following are various popular implementations of Operating System architectures.

  1. Simple Architecture

  2. Monolith Architecture

  3. Micro-Kernel Architecture

  4. Exo-Kernel Architecture

  5. Layered Architecture

  6. Modular Architecture

  7. Virtual Machine Architecture

Simple Architecture

有许多结构相当简单的操作系统。这些系统一开始很小,后来迅速扩展,远远超出了其范围。MS-DOS 就是一个常见的例子。它仅为小部分人设计。没有迹象表明它会变得如此受欢迎。

There are many operating systems that have a rather simple structure. These started as small systems and rapidly expanded much further than their scope. A common example of this is MS-DOS. It was designed simply for a niche amount for people. There was no indication that it would become so popular.

os basic structure

少数操作系统具有简单但强大的体系结构,例如 MS-DOS。这将导致对计算机系统及其各种应用程序的更大控制权。简单的体系结构允许程序员根据需要隐藏信息,并根据需要实现内部例程,而无需更改外部规范。

Few operating systems have a simple yet powerful architecture, for example, MS-DOS. That would lead to greater control over the computer system and its various applications. The simple architecture allows the programmers to hide information as required and implement internal routines as they see fit without changing the outer specifications.

Advantages

以下是简单操作系统架构的优点。

Following are advantages of a simple operating system architecture.

  1. Easy Development - In simple operation system, being very few interfaces, development is easy especially when only limited functionalities are to be delivered.

  2. Better Performance - Such a sytem, as have few layers and directly interects with hardware, can provide a better performance as compared to other types of operating systems.

Disadvantages

以下是简单操作系统架构的缺点。

Following are disadvantages of a simple operating system architecture.

  1. Frequent System Failures - Being poorly designed, such a system is not robust. If one program fails, entires operating system crashses. Thus system failures are quiet frequent in simple operating systems.

  2. Poor Maintainability - As all layers of operating systems are tightly coupled, change in one layer can impact other layers heavily and making code unmanageable over a period of time.

Monolith Architecture

在整体操作系统架构中,称为内核的中心代码段负责操作系统的所有主要操作。此类操作包括文件管理、内存管理、设备管理等。内核是操作系统的主要组件,它向应用程序和系统程序提供操作系统的全部服务。

In monolith architecture operating system, a central piece of code called kernel is responsible for all major operations of an operating system. Such operations includes file management, memory management, device management and so on. The kernal is the main component of an operating system and it provides all the services of an operating system to the application programs and system programs.

内核可以访问所有资源,并且充当应用程序和底层硬件的接口。整体内核架构促进了分时、多编程模型并在旧银行系统中使用。

The kernel has access to the all the resources and it acts as an interface with application programs and the underlying hardware. A monolithic kernel architecture promotes timesharing, multiprogramming model and was used in old banking systems.

os monolith structure

Advantages

以下是整体操作系统架构的优点。

Following are advantages of a monolith operating system architecture.

  1. Easy Development - As kernel is the only layer to develop with all major functionalities, it is easier to design and develop.

  2. Performance - As Kernel is responsible for memory management, other operations and have direct access to the hardware, it performs better.

Disadvantages

以下是整体操作系统架构的缺点。

Following are disadvantages of a monolith operating system architecture.

  1. Crash Prone - As Kernel is responsible for all functions, if one function fails entire operating system fails.

  2. Difficult to enhance - It is very difficult to add a new service without impacting other services of a monolith operating system.

Micro-Kernel Architecture

与整体架构中有一个内核一样,在微内核中,我们有多个内核,每个内核都专门用于特定服务。每个微内核独立于其他内核开发,这使系统更加稳定。如果一个内核发生故障,操作系统将继续使用其他内核的功能。

As in case monolith architecture, there was single kernel, in micro-kernel, we have multiple kernels each one specilized in particular service. Each microkernel is developed independent to the other one and makes system more stable. If one kernel fails the operating sytem will keep working with other kernel’s functionalities.

Advantages

以下是微内核操作系统架构的优点。

Following are advantages of a microkernel operating system architecture.

  1. Reliable and Stable - As multiple kernels are working simultaneously, chances of failure of operating sytem is very less. If one functionlity is down, operating system can still provide other functionalities using stable kernels.

  2. Maintainability - Being small sized kernels, code size is maintainable. One can enhance a microkernel code base without impacting other microkernel code base.

Disadvantages

以下是微内核操作系统架构的缺点。

Following are disadvantages of a microkernel operating system architecture.

  1. Complex to Design - Such a microkernel based architecture is difficult to design.

  2. Performance Degradation - Multi kernel, Multi-modular communication may hamper the performance as compared to monolith architecture.

Exo-Kernel Architecture

外核架构操作系统在麻省理工学院设计和开发。此设计的目的是保持内核大小最小,同时允许应用程序直接管理硬件资源。删除硬件资源操作系统的抽象的目的是使应用程序程序员能够编写高性能代码,而外核则处理其他操作。

Exo-Kernal Architecture operating system was designed and developed at MIT. The aim of this design was to keep Kernel size minimal while allowing the application programs to manage hardware resources directly. The purpose of removing abstraction of operating system for hardware resources was to enable application programmer to write high performance code while exo-kernel handles other operations.

Advantages

以下是外核操作系统架构的优点。

Following are advantages of a exo-kernel operating system architecture.

  1. High Performance - As application program can allocate memory, a better designed code can make optimal use and perform better.

  2. Application Control - As resource management is not secured by operating system, application program has more control over system resources and can write custom operations on system resources.

Disadvantages

以下是外核操作系统架构的缺点。

Following are disadvantages of a exo-kernel operating system architecture.

  1. Unreliable and Unsafe - As security is in application program level, a poorly written code can ruin the system.

  2. Complex Design - Exo-Kernel designing is complicated.

Layered Architecture

在操作系统中实现模块化的办法之一就是采用分层方法。在这种方法中,最底层是硬件,最顶层是用户界面。

One way to achieve modularity in the operating system is the layered approach. In this, the bottom layer is the hardware and the topmost layer is the user interface.

演示分层方法的图像如下所示:

An image demonstrating the layered approach is as follows −

os layered structure

如图像所示,每一层都基于底层构建。所有层对上层隐藏一些结构、操作等。

As seen from the image, each upper layer is built on the bottom layer. All the layers hide some structures, operations etc from their upper layers.

分层架构的一个问题是需要仔细定义每一层。这是必需的,因为上层只能使用它们下层的那些功能。

One problem with the layered architecture is that each layer needs to be carefully defined. This is necessary because the upper layers can only use the functionalities of the layers below them.

Advantages

以下是分层操作系统架构的优点。

Following are advantages of a layered operating system architecture.

  1. High Customizable - Being layered, each layer implmentation can be customized easily. A new functionality can be added without impacting other modules as well.

  2. Verifiable - Being modular, each layer can be verified and debugged easily.

Disadvantages

以下是分层操作系统架构的缺点。

Following are disadvantages of a layered operating system Architecture.

  1. Less Performant - A layered structured operating system is less performant as compared to basic structured operating system.

  2. Complex designing - Each layer is to planned carefully as each layer communicates with lower layer only and a good design process is required to create a layered operating system.

Modular Architecture

模块化架构操作系统采用与单片机类似的原理工作,但设计更出色。一个中央内核负责操作系统的全部主要操作。这个内核具有一套核心功能,其他服务在操作系统启动时或在运行时作为模块动态加载到内核中。Sun Solaris 操作系统是模块化结构操作系统的一个示例。

Modular architecture operating system works on the similar princhiple as a monolith but with better design. A central kernal is responsible for all major operations of operating system. This kernal has set of core functionality and other services are loaded as modules dynamically to the kernal at boot time or at runtime. Sun Solaris OS is one of the example of Modular structured operating system.

Advantages

以下是模块化操作系统架构的优势。

Following are advantages of a modular operating system architecture.

  1. High Customizable - Being modular, each module implmentation can be customized easily. A new functionality can be added without impacting other modules as well.

  2. Verifiable - Being modular, each layer can be verified and debugged easily.

Disadvantages

以下是模块化操作系统架构的劣势。

Following are disadvantages of a modular operating system architecture.

  1. Less Performant - A modular architecture operating system is less performant as compared to basic structured operating system.

  2. Complex designing - Each module is to planned carefully as each module communicates with kernal. A communication API is to be devised to facilitate the communication.

Virtual Machine Architecture

在此类架构中,诸如 CPU、内存、硬盘之类的硬件被抽象为虚拟机。用户可以使用它们,并通过执行上下文实际配置它们。虚拟机占用大量的磁盘空间,且必须预置。可在单个物理机创建多个虚拟机。

In this kind of architecture, hardware like CPU, memory, hard disks are abstracted into virtual machines. User can use them with actually configure them using execution contexts. Virtual machine takes a good amount of disk space and is to be provisioned. Muliple virtual machines can be created on a single physical machine.

Advantages

以下是基于虚拟机的操作系统架构的优势。

Following are advantages of a virtual machine based operating system architecture.

  1. High Customizable - Being virtual, functionality are easily accessible, can be customized on need basis.

  2. Secure - Being virtual, and no direct hardware access, such systems are highly secured.

Disadvantages

以下是基于虚拟机的操作系统架构的劣势。

Following are disadvantages of a virtual machine based operating system architecture.

  1. Less Performant - A virtual structured operating system is less performant as compared to modular structured operating system.

  2. Complex designing - Each virtual component of the machine is to planned carefully as each component is to abstract underlying hardware.