2013年11月5日 星期二

[IOS] Ch2 System Structures #1


       We can view an operating system from several vantage points. One view
focuses on the services that the system provides; another, on the interface that it makes available to users and programmers; a third, on its components and their interconnections. In this chapter, we explore all three aspects of operating systems, showing the viewpoints of users, programmers, and operating-system designers. We consider what services an operating system provides, how they are provided, how they are debugged, and what the various methodologies are for designing such systems. Finally, we describe how operating systems are created and how a computer starts its operating system.


-- Operating System Concepts 8th, by Silberschatz, Galvin, Gagne




Operating System Services 


One set of operating-system services provides functions that are helpful to the user:

  • User interface: Almost all operating systems have a user interface (UI)Varies between:
    •  Command-Line (CLI)
    • Graphics User Interface(GUI)
    • Batch: in which commands and directives to control those commands are entered into files, and those files are executed.
  • Program execution: The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)
  • I/O operations: A running program may require I/O, which may involve a file or an I/O device. For efficiency and protection, users usually cannot control I/O devices directly. Therefore, the operating system must provide a means to do I/O.
  • File-system manipulation: The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
  • Communications: Processes may exchange information, on the same
    computer or between computers over a network.
    • may be via shared memory
    • through message passing (packets moved by the OS)
  • Error detection: OS needs to be constantly aware of possible errors:
    • May occur in the CPU and memory hardware, in I/O devices, in user
      program
    • For each type of error, OS should take the appropriate action to ensure correct and consistent computing
    • Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system



Another set of operating-system functions exists not for helping the user
but rather for ensuring the efficient operation of the system itself
. Systems with multiple users can gain efficiency by sharing the computer resources among the users.
  •  Resource allocation: When multiple users or multiple jobs running concurrently, resources must be allocated to each of them.
    • Many types of resources: Some (such as CPU cycles, main memory,
      and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code. (CPU-scheduling)
  • Accounting: To keep track of which users use how much and what kinds
    of computer resources.



Batch files: 在DOSOS/2微軟視窗系統中,批次檔英語Batch file)是一種用來當成腳本語言運作程式的檔案。它本身是文字文件,其中包含了一系列讓具備命令列介面直譯器讀取並執行的指令。它相當於是類Unix系統下的Shell script。在DOSWindows 9x作業系統家族中,批次檔的副檔名為 .bat。在OS/2Windows NT作業系統家族,批次檔的副檔名為 .cmd。當執行批次檔時,shell程式(通常是COMMAND.COMcmd.exe)會讀取檔案內容,之後通常是以逐行的方式,執行它的命令。


User Operation System Interface

Command Interpreter

Command Line Interface (CLI) or command interpreter allows direct command entry

  • Sometimes implemented in kernel
  • Sometimes by systems program
    • Such as Windows XP and UNIX
    • running when a job is initiated or when a user first logs on
      (on interactive systems)

  • Sometimes multiple flavors implemented – shells
    • On UNIX and Linux systems, a user may choose among several different shells, including the Bourne shell, C shell, Bourne-Again shell, Korn shell, and others.

  • Primarily fetches a command from user and executes it
    • Sometimes commands built-in
      • command interpreter itself contains the code to execute the command
      • For example, a command to delete a file may cause the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call
      • In this case, the number of commands that can be given determines the size of the command interpreter, since each command requires its own implementing code.
    • sometimes just names of programs
      • command interpreter does not understand the command in any way
      • Adding new features doesn’t require shell modification
      • uses the command to identify a file to be loaded into memory and executed.
      • The UNIX command to delete a file rm file.txt would search for a file called rm, load the file into memory, and execute it with the parameter file. txt. The function associated with the rm command would be defined completely by the code in the file rm. In this way, programmers canadd new commands to the system easily by creating new files with the proper names.

Graphical User Interface

  • User-friendly desktop metaphor interface
    • Usually mouse, keyboard, and monitor
    • Icons represent files, programs, actions, etc
    • Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder)
    • Invented at Xerox PARC
  • Many systems now include both CLI and GUI interfaces
    • Microsoft Windows is GUI with CLI "command" shell
    • Apple Mac OS X as "Aqua" GUI interface with UNIX kernel underneath and shells available
    • Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

System Calls


  • Programming interface to the services provided by the OS
  • Typically written in C or C++,although certain low-level tasks (for example, tasks where hardware must be accessed directly), may need to be written using assembly-language instructions.
  • Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use
  • Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)
  • Why use APIs rather than system calls? 
    • An application programmer designing a program using an API can expect her program to compile and run on any system that upports
      the same API (although in reality architectural differences often make this more difficult than it may appear). 
    • Actual system calls can often be more detailed and difficult to work with than the API available to an application programmer. 
    • There often exists a strong correlation between a function in the API and its associated system call within the kernel.
  • (Note that the system-call names used throughout this text are generic)


# man gcc
-g  Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information.

  • Often, more information is required than simply identity of desired system call
    • Exact type and amount of information vary according to OS and call
  • Three general methods used to pass parameters to the OS
    • Simplest: pass the parameters in registers
      • In some cases, may be more parameters than registers
      • Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register
      • This approach taken by Linux and Solaris
    • Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system
    • Block and stack methods do not limit the number or length of parameters being passed


Reference:  
Operating System Concepts 8th, by Silberschatz, Galvin, Gagne
Wikipedia

沒有留言:

張貼留言