這是我自己讀OPERATING SYSTEM CONCEPTS (6th Edition)的筆記,本來讀的進度很緩慢,直到有一天在網路上看到冼鏡光老師分享上課的slide(OS第7版),唸起OS就愈來有趣啦。
    筆記的章節是依OS第6版整理的,圖片則都是從冼鏡光老師的slide貼上來的,感謝冼老師無私的分享,讓我有機會一窺OS的奧妙。
   
(如有著作權相關問題,請惠予通知)


3.     Operating-System Structures
3.1    System Components
        3.1.1  Process Management
    • A process can be thought of as a program in execution.
    • At any time, at most one instruction is executed on behalf of the process.
    • A process is the unit of work in a system.
    • The OS is responsible for the following activities in connection with process management:
      • Creating and deleting both user and system processes.
      • Suspending and resuming processes.
      • Providing mechanisms for process synchronization.
      • Providing mechanisms for process communication.
      • Providing mechanisms for deadlock handling.
        3.1.2  Main-memory Management
    • The OS is responsible for the following activities in connection with memory management:
      • Keeping track of which parts of memory are currently being used and by whom.
      • Deciding which processes are to be loaded into memory when memory space becomes available.
      • Allocating and deallocating memory space as needed.
        3.1.3  File Management
    • The OS abstracts from the physical properties of its storage devices to define a logical storage unit, the file.
        3.1.4  I/O-System Management
    • One of the purposes of an OS is to hide the peculiarities of specific hardware devices from the user.
    • In UNIX, the peculiarities of I/O devices are hidden from the bulk of the OS itself by the I/O subsystem. The I/O subsystem consists of:
      • A memory-management component that includes buffering, caching, and spooling.
      • A general device-driver interface.
      • Drivers for specific hardware devices.
    • Only the device driver knows the peculiarities of the specific device to which it is assigned
        3.1.5  Secondary-Storage Management
        3.1.6  Networking
        3.1.7  Protection system
        3.1.8  Command-Interpreter System
    • Command-line interpreter (shell) is the interface between the user and the OS
3.2    Operating-System Services
  • User Interface (e.g., command processor –shell and GUI – Graphical User Interface)
  • Program execution
  • I/O Operations
  • File-system manipulation
  • Communications
  • Error detection
  • Resource allocation
  • Accounting
  • Protection
3.3    System Calls
         
         
  • System calls provide an interface to the services made available by an operating system.
  • Certain systems allow system calls to be made directly from a higher-level language program, they may generate a call to a special run-time routine that makes the system call, or the system call may be generated directly in-line.
  • The run-time support system (the set of functions built into libraries included with a compiler) for most programming languages provides a much simpler interface which hides the details of system calls.
  • Most of the details of the OS interface are hidden from the programmer by the compiler and by the run-time support package.
  • Three methods are used to pass parameters to the OS:
    • Pass the parameters in registers.
    • The parameters are generally stored in a block or table in memory and the address of the block is passed as a parameter in a register (Linux).
    • Parameters can also be placed, or pushed, onto the stack by the program, and popped off the stack by the OS.
  • System calls can be grouped roughly into five categories: process control, file management, device management, information maintenance, and communications.
  • The types of requests varies; the system-call level must provide the basic functions, such as process control and file and device management, higher-level requests, satisfied by the command interpreter or system programs, are translated into a sequence of system calls.
        3.3.1  Process Control
    • End, abort
    • Load, execute
    • Create / terminate process
    • Get / set process attributes
    • Wait for time
    • Wait event, signal event
    • Allocate / free memory
    • Some microprocessors provide a CPU mode known as single step, in which a trap is executed by the CPU after every instruction; the trap is usually caught by a debugger.
    • Many operating systems provide a time profile of a program. A time profile requires either a tracing facility or regular timer interrupts.
    • In FreeBSD, to start a new process, the shell executes a fork system call, then, the selected program is loaded into memory via an exec system call, and the program is then executed. When the process is done, it executes an exit system call to terminate, returning to the invoking process a status code of 0, or a nonzero error code.
        3.3.2  File Management
    • Create / delete file
    • Open ,close
    • Read, write, reposition
    • Get / set file attributes
        3.3.3  Device Management
    • Request / release device
    • Read, write, reposition
    • Get / set device attributes
    • Logically attach or detach devices
    • Files can be thought of as abstract or virtual devices, and, the similarity between I/O devices and files is so great that many operating systems, including UNIX and MS-DOS, merge the two into a combined file-device structure. In this case, I/O devices are identified by special file names.
        3.3.4 Information Maintenance
    • Get / set time or date
    • Get / set system data
    • Get / set process, file, or device attributes
        3.3.5  Communication
    • Create, delete communication connection
    • Send, receive messages
    • Transfer status information
    • Attach or detach remote devices
    • Two common models:
      • In the message-passing model, information is exchanged through an interprocess-communication facility provided by the OS.
      • In the shared-memory model, processes use map memory system calls to gain access to regions of memory owned by other processes. Normally, the OS tries to prevent one process from accessing another process’ memory.
3.4    System Programs
  • File management (e.g., create, delete files)
  • Status management (e.g., date/time, available memory and disk space)
  • File modification (e.g., editors)
  • Programming language support (e.g., assemblers, compilers, interpreters)
  • Program loading and execution (e.g., loaders, linkage editors)
  • Communications (e.g., connections between processes, sending/receiving e-mails)
  • Implementation of command interpreter:
    • The command interpreter itself contains the code to execute the command.
    • The command interpreter uses the command to identify a file to be loaded into memory and executed (UNIX).
3.5    System Structure
        3.5.1  Simple Structure
                     
    • Simple structure systems do not have well-defined structures.
    • The UNIX only had limited structure: kernel and system programs.
    • Everything between the system call interface and physical hardware is the kernel.
        3.5.2  Layered Approach
                     
                     
    • The operating system is broken up into a number of layers (or levels), each on top of lower layers.
    • Each layer is an implementation of an abstract object that is the encapsulation of data and operations that can manipulate these data.
    • The bottom layer (layer 0) is the hardware.
    • The main advantage of layered approach is modularity.
    • The lowest layer is process management.
    • Each layer only uses the operations provided by lower layers and does not have to know their implementation/
    • Each layer hides the existence of certain data structures, operations and hardware from higher-level layers. Think about OO.
    • It is difficult to organize (define) the system in layers, because a layer can use only layers below it. Example: virtual memory (lower layer) uses disk I/O (upper layer).
    • Layered implementations tend to be less efficient than other types. Example: there may be too many calls going down the layers: user to I/O layer to memory layer to process scheduling layer.
    • The layered approach may also represented as a set of concentric rings.
    • The first OS based on the layered approach was THE, developed by E. Eijkstra.
        3.5.3  Microkernels
                     
    • Only absolutely essential core OS functions should be in the kernel.
    • Less essential services and applications are built on the kernel and run in user mode.
    • Many functions that were in a traditional OS become external subsystems that interact with the kernel and with each other.
    • In general, microkernels typically provide minimal process and memory management, in addition to a communication facility.
    • The main function of the microkernel is to provide communication facility between the client program and various services.
    • Communication is provided by message passing.
    • Uniform interfaces: message passing.
    • Extensibility: adding new services is easy.
    • Flexibility: existing services can be taken out easily to produce a smaller and more efficient implementation.
    • Portability: all or at least much of the processor specific code is in the small kernel.
    • Security, Reliability: A small and modular designed kernel can be tested easily. Most services are running as user-rather than kernel-processes, if a service fails, the rest of the operating system remains untouched.
    • Distributed system support: client and service processes can run on networked system.
    • But, microkernels do have a problem:
      • As the number of system functions increases, overhead increases and performance reduces.
      • Most microkernel systems took a hybrid approach, a combination of microkernel and something else (e.g., layered).
                     
        3.5.4  Modules
                     
    • The OO technology can be used to create a modular kernel.
    • The kernel has a set of core component and dynamically links in additional services either during boot time or during run time.
    • The module approach looks like the layered approach as each module has a precise definition; however, the former is more flexible in that any module can call any other module.
    • The module approach is also like the microkernel approach because the core module only includes the core functions. However, the module approach is more efficient because no message passing is required.
3.6    Virtual Machines
         
  • The kernel running at the level above the hardware uses the hardware instructions to create a set of system calls for use by outer layers.
  • The system programs above the kernel are therefore able to use either system calls or hardware instructions, and in some ways these programs do not differentiate between these two.
  • Although the system programs are at a level higher than that of the other routines, the application programs may view everything under them in the hierarchy as though the latter were part of the machine itself. This layered approach is taken to its logical conclusion in the concept of a virtual machine.
  • The virtual-machine approach does not provide any additional functionality, but rather provides an interface that is identical to the underlying bare hardware. Each process is provided with a (virtual) copy of the underlying computer.
  • A virtual machine, VM, is a software between the kernel and hardware.
  • Thus, a VM provides all functionalities of a CPU with software simulation.
  • A user has the illusion that s/he has a real processor that can run a kernel.
  • Self-Virtualized VM: the VM is identical to the hardware, Example: IBM’s VM/370 and VMware (creating a VM under Linux to run Windows).
  • Non-Self Virtualized VM: the VM is not identical to the hardware. Example: Java Virtual Machine JVM and SoftWindow.
  • It can be proved that all third-generation CPUs can be virtualized.
        3.6.1  Implementation
    • VM are difficult to implement because they must duplicate all hardware functions.
        3.6.2  Benefits
    • VM provides a robust level of security.
    • VM permits system development to be done without disrupting normal system operation.
    • VM allows multiple operating systems to run on the same machine at the same time.
    • VM can make system transition / upgrade much easier.
        3.6.3  JAVA
    • For each Java class, the Java compiler produces an architecture-neutral bytecode output (.class) file that will run on any implementation of the JVM.
    • The JVM consists of a class loader, a class verifier, and a Java interpreter that executes the architecture-neutral bytecodes.
    • The JVM also automatically manages memory by performing garbage collection-the practice of reclaiming memory from objects no longer in use and returning it to the system.
    • The Java interpreter may be a software module that interprets the bytecodes one at a time, or it may be a just-in-time (JIT) compiler that turns the architecture-neutral bytecodes into native machine language for the host computer. In other instances, the interpreter may be implemented in hardware that executes Java bytecodes natively.
3.7    System Design and Implementation
        3.7.1  Design Goals
    • Goals and specifications will be affected by hardware and the type of the system (e.g., batch, time-sharing, real-time, etc).
    • Requirements: user goals and system goals.
      • User goals: easy of use, reliable, safe, fast.
      • System goals: easy to design, implement and maintain, and flexible, reliable, efficient, etc.
    • There is no unique way to achieve all goals, and some compromises must be taken.
        3.7.2  Mechanisms and Policies
    • Mechanisms determine how to do something.
    • Policies determine what will be done.
    • Policies and mechanisms are usually separated: the separation of mechanism and policy principle.
      • It is for efficiency purpose. Policies are likely to change over time.
      • If a more general mechanism is available, the impact of changing policy on mechanism is reduced.
      • Microkernel-based systems implement a basic set of building blocks, which are almost policy free. Thus, advanced policies and mechanisms can be added to user-created kernel modules.
        3.7.3  Implementation
    • The assembly vs. high-level language issue
      • Advantages of high-level languages: easy to use and maintain, and more available programming tools.
      • Disadvantages of high-level languages: slower and more space.
    • Many systems were written in both with a small percentage (e.g., 10%) of assembly language for the most speed demanding low level portion.
    • Better data structures and algorithms are more important than tweaking assembly instructions.
    • Porting: to move to some other hardware.
    • The memory manager and the CPU scheduler are probably the most critical routines.
3.8    System Generation
  • Operating systems are designed to run on any of a class of machines at a variety of sites with a variety of peripheral configurations. The system must then be configured or generated for each specific computer site, a process sometimes known as system generation (SYSGEN).
  • When the system is powered on, a small program, usually stored in ROM (i.e., read only memory), will be executed. This initial program is usually referred to as a bootstrap program or an Initial Program Loader (IPL).
  • The bootstrap program reads in and initializes the operating system. The execution is then transferred to the OS.
  • The procedure of starting a computer by loading the kernel is known as booting the system. The bootstrap program is able to locate the kernel, load it into main memory, and start its execution.

arrow
arrow
    全站熱搜

    nix 發表在 痞客邦 留言(0) 人氣()