Download 2.01

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Security-focused operating system wikipedia , lookup

Library (computing) wikipedia , lookup

Mobile operating system wikipedia , lookup

MTS system architecture wikipedia , lookup

Distributed operating system wikipedia , lookup

Copland (operating system) wikipedia , lookup

Acorn MOS wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

DNIX wikipedia , lookup

OS 2200 wikipedia , lookup

Process management (computing) wikipedia , lookup

Batch file wikipedia , lookup

RSTS/E wikipedia , lookup

Burroughs MCP wikipedia , lookup

Spring (operating system) wikipedia , lookup

CP/M wikipedia , lookup

Unix security wikipedia , lookup

VS/9 wikipedia , lookup

Transcript
Chapter 2: System Structures
籃玉如
Chapter 2: System Structures
 Operating System Services
 User Operating System Interface
 System Calls
 Types of System Calls
 System Programs
 Operating System Design and Implementation ()
 Operating System Structure
 Virtual Machines ()
 Operating System Generation ()
 System Boot
 OS提供processes執行的環境。
 我們可以不同的的觀點來看OS:
1. focuses on the services that a system provides
2. on the interface that it makes available to users
and programmers
3. its components and their interconnections
2.1 Operating System Services
 OS提供的services主要有兩大類:
1. helpful to the users (方便易用)
2. 透過資源分享確保系統有效率的運作 (有
效的運用資源)
2.1 Operating System Services
 使用者介面
 程式的執行
 輸入和輸出作業
 檔案系統的使用
 通信
 錯誤的偵測
 資源的分配
 使用量統計
 保護和安全
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
–
CLI: where the user provides the input by typing a command string with
the computer keyboard and the system provides output by printing text on
the computer monitor. Used for system administration tasks etc.
–
GUI: which accept input via devices such as computer keyboard and
mouse and provide articulated graphical output on the computer monitor.
There are at least two different principles widely used in GUI design:
Object-oriented user interfaces (OOUIs) and application oriented
interfaces
–
Batch interfaces: are non-interactive user interfaces, where the user
specifies all the details of the batch job in advance to batch processing,
and receives the output when all the processing is done. The computer
does not prompt for further input after the processing has started.
Operating System Services
 One set of operating-system services provides functions that are
helpful to the user:

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.

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.
Operating System Services (Cont.)
 One set of operating-system services provides functions that are
helpful to the user (Cont):

Communications – Processes may exchange information, on the same
computer or between computers over a network


Communications may be via shared memory or 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
Operating System Services (Cont.)

Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing

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,mainmemory,
and file storage) may have special allocation code, others (such as I/O
devices) may have general request and release code.

Accounting - To keep track of which users use how much and what kinds
of computer resources

Protection and security - The owners of information stored in a multiuser
or networked computer system may want to control use of that information,
concurrent processes should not interfere with each other

Protection involves ensuring that all access to system resources is
controlled

Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access attempts

If a system is to be protected and secure, precautions must be
instituted throughout it. A chain is only as strong as its weakest link.
2.2 User Operating System Interface
 兩種基本的users與OS之間溝通的方法
 Command-line
interface (CLI) or
command interpreter:allows users to
directly enter commands that are to be
performed by the OS.
 Graphical
user interface (GUI):
provides a mouse-based window-andmenu system as an interface.
Command interpreter / CLI
 有些OS在Kernel中包含了command interpreter(命
令直譯程式)。而有些OS(例如 Windows XP &
Unix)將command interpreter視為一個特殊程式
(that is running when a job is initiated or when a
user first logs on interactive systems )。
 稱為shells
 To get and execute the next user-specified
command.
 利用CLI輸入指令。有很多情況是用來做檔案處
理,例如:create, delete, list, print, copy,
execute等等
 MS-DOS & Unix的shells用此方式運作
Command interpreter / CLI
 Implement方式

The command interpreter itself contains the code to
execute the command.
 The
number of commands that can be given
determines the size of the command
interpreter.

Implement most commands through system
programs
 The command interpreter 本身不了解此
command,it merely use the command to
identify a file to be loaded into memory and
executed..
 The
command interpreter, which can be small,
does not have to be changed for new
commands to be added.
Graphical User Interface / GUI
 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)
 Many systems now include both CLI and GUI
interfaces

例如:Microsoft Windows is GUI with CLI
“command” shell
2.3 System Calls
 Programming interface to the services provided
by the OS
 System calls: The mechanism used by an
application program to request service from the
OS
例如:在Unix-based and POSIX-based systems,
popular system calls are open, read, write, close,
kill, exit…
 Typically written in a high-level language (C or
C++)
Example of System Calls
 System call sequence to copy the contents of one file to another
file
Fig. 2.1 Example of how system calls are used.
Application programming interface (API)
 Mostly accessed by programs via a high-level
Application Program Interface (API) rather than
direct system call use
應用程序介面為:「『電腦作業系統』或『程式
函式庫』提供給應用程式呼叫使用的原始碼」。
其主要目的是讓應用程式開發人員得以呼叫一組
常式功能,而無須考慮其底層的原始碼為何、或
理解其內部工作機制的細節。API本身是抽象的
,它僅定義了一個介面,而不涉入應用程式如何
實現的細節。
Application programming interface (API)
 Why use APIs rather than system calls?

Concerns program portability
一個程式設計者希望他用API設計的程式可以
在其他能支援相同API的系統中執行。

對程式設計者而言,API比實際system calls簡易
多了
Example of Standard API

Consider the ReadFile() function in the

Win32 API—a function for reading from a file

A description of the parameters passed to ReadFile()

HANDLE file—the file to be read

LPVOID buffer—a buffer where the data will be read into and written
from

DWORD bytesToRead—the number of bytes to be read into the buffer

LPDWORD bytesRead—the number of bytes read during the last read

LPOVERLAPPED ovl—indicates if overlapped I/O is being used
System-Call Interface
 Serves as the link to system calls made available by the operating
system.
 Intercepts function calls in the API and invokes the necessary
system call within the OS
 a number is associated with each system call, and the system-call
interface maintains a table indexed according to these numbers
The system call interface invokes the intended system call in the OS
kernel and returns the status of the system call and any return
values.
System Call Implementation
 The caller need know nothing about how the system call is
implemented

Just needs to obey API and understand what OS will do as a
result call

Most details of OS interface hidden from programmer by API

Managed by run-time support library (set of functions built
into libraries included with compiler)
API – System Call – OS Relationship
Fig. 2.2 The handling of a user application invoking the open() system call.
System Call Parameter Passing
 Often, more information is required than simply
identity of desired system call

Exact type and amount of information vary
according to OS and call
System Call Parameter Passing
 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 (next approach)
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 (therefore some OS
prefer these two approaches)
Parameter Passing via Table
Fig. 2.3 Passing of parameters as a table.
2.4 Types of System Calls
系統呼叫可概略分成五類: p. 47
 Process control
 File management
 Device management
 Information maintenance
 Communications
2.4 Types of System Calls
行程的控制(process control)
 正常結束,中止執行(end, abort)
 載入,執行(load, execute)
 建立行程,終止行程(create process, terminate process)
 獲取行程屬性,設定行程屬性(get process attributes,set process
attributes)
 等待時間(wait for time)
 等待事件,顯示事件(wait event, signal event)
 配置及釋放記憶體空間(allocate and free memory)
檔案的管理(File management)
 建立檔案,刪除檔案(create file, delete file)
 開啟,關閉(open,Close)
 讀出,寫入,重定位置(read, write, reposition)
 獲取檔案屬性,設定檔案屬性(get file attributes, set file attributes)
Operating System Concepts
2.26
Silberschatz, Galvin and Gagne ©2005
2.4 Types of System Calls
裝置的管理(Device management)
 要求裝置,釋回裝置(request device, release device)
 讀出,寫入,重定位置(read, write, reposition)
 獲取裝置屬性,設定裝置屬性(get device attributes, set device
attributes)
 遇輯上地加入或移去裝置(logically attach or detach devices)
資訊維護(Information maintenance)
 取得時間或日期,設定時間或日期(get time or date, set time or
date)
 取得系統資料,設定系統資料(get system data, set system data)
 取得行程、檔案或裝置的屬性(get process, file, or device
attributes)
 設定行程、檔案或裝置的屬性(set process,file,or device
attributes)
Operating System Concepts
2.27
Silberschatz, Galvin and Gagne ©2005
2.4 Types of System Calls
通信(communication)
 建立,刪除通信連接(create, delete communication
connection)
 傳送,接收訊息(send, receive messages)
 傳輸狀況訊息(transfer status information)
 連接或分離遠程裝置(attach or detach remote devices)
Operating System Concepts
2.28
Silberschatz, Galvin and Gagne ©2005
2.5 System Programs
 System programs provide a convenient environment for program
development and execution. The can be divided into:

File manipulation

Status information

File modification

Programming language support

Program loading and execution

Communications

Application programs
 Most users’ view of the operation system is defined by system
programs, not the actual system calls
System Programs

Provide a convenient environment for program development and execution

Some of them are simply user interfaces to system calls; others are
considerably more complex

File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories

Status information

Some ask the system for info - date, time, amount of available memory,
disk space, number of users

Others provide detailed performance, logging, and debugging
information

Typically, these programs format and print the output to the terminal or
other output devices

Some systems implement a registry - used to store and retrieve
configuration information
System Programs (cont’d)
 File modification

Text editors to create and modify files
 Special commands to search contents of files or perform
transformations of the text
 Programming-language support - Compilers, assemblers,
debuggers and interpreters sometimes provided
 Program loading and execution- Absolute loaders, relocatable
loaders, linkage editors, and overlay-loaders, debugging systems
for higher-level and machine language
 Communications - Provide the mechanism for creating virtual
connections among processes, users, and computer systems
 Allow users to send messages to one another’s screens,
browse web pages, send electronic-mail messages, log in
remotely, transfer files from one machine to another
2.7 Operating-System Structure
 一個像現代作業系統這麼龐大&複雜的系統,如果
要有合適且易於修改的功能,就必須小心的規劃。
 A common approach it to partition the task into
small components rather than have one monolithic
system.
 Each of these module should be a well-defined
portion of the sytem, with carefully defined inputs,
outputs, and functions
2.7 Operating-System Structure
Simple Structure:
MS-DOS – written to provide the most functionality in
the least space

Not divided into modules

Although MS-DOS has some structure, its
interfaces and levels of functionality are not
well separated
MS-DOS Layer Structure
Application programs are
able to access the basic
I/O routines to write
directly to the display and
disk drives.
Such freedom leaves
MS-DOS vulnerable to
errant (or malicious)
programs, causing entire
system creashes when
user programs fail.
Hareware limitation: Intel
8088 provides no dual mode
and no hardware protection.
Fig. 2.7 MS-DOS layer structure.
Layered Approach
 The operating system is divided into a number of
layers (levels), each built on top of lower layers.
The bottom layer (layer 0), is the hardware; the
highest (layer N) is the user interface.
 With modularity, layers are selected such that
each uses functions (operations) and services of
only lower-level layers
Layered Operating System
Fig. 2.9 A layered operating system.
The Advantages of the Layered Approach
 分層方式最主要的好處是結構簡單和除錯。層次選定之後
,每一個層次只能使用較低層的功能與服務。這種方式更
容易做系統的除錯與驗證。第一層改正時,不必考慮系統
的其餘部份,因為根據定義,它只甩了基礎的硬體 (假設
它是正確的)去完成它的功能。一旦第一層改正後,在第二
層的工作可以假設它的功能正確。在特定層次除錯時,如
果發現錯誤,我們可以知道錯誤必定在那一層,因為在它
底下的層都已改正。如此一來,當系統分層時,系統的設
計與製作都可以簡化。
Operating System Concepts
2.37
Silberschatz, Galvin and Gagne ©2005
The Problems of the Layered Approach
 如何適當的定義每一個層次:因為每ㄧ層只可以使用比自
己低的層。

例如:備用儲存體的裝置驅動程式(disk space used by
virtual-memory algorithms)必須在比memory-management
routines還低層,因為記憶體管理需要使用備用儲存體
的ability.
 比較沒有效率:因為需要一層一層往下呼叫
Microkernels & Modules的設計概念
Operating System Concepts
2.38
Silberschatz, Galvin and Gagne ©2005
UNIX System Structure
Fig. 2.8 UNIX system structure.
Microkernel System Structure
 Moves as much from the kernel into “user” space (移去kernel非必
要的元件將OS結構系統化)
 主要功能:提供client program和同樣在使用者空間執行的 various
services之間通訊的便利

Communication takes place between user modules using
message passing

如果client program需要存取一個檔案,就必須和檔案伺服器聯
絡。The client progarm和服務者從未直接通訊。
Microkernel System Structure
 Benefits:

Easier to extend a microkernel

Easier to port the operating system to new architectures

More reliable (less code is running in kernel mode)

More secure
 Detriments:

Performance overhead of user space to kernel space
communication (The first release of Windows NT)

Windows NT 4.0 paratially redressed the performce problem by
moving layers from user space to kernel space and integrating
them more closely.
Modules
 Most modern operating systems implement kernel modules

Uses object-oriented approach

Each core component is separate

Each talks to the others over known interfaces

Each is loadable as needed within the kernel
 Overall, similar to layers but with more flexible
Solaris Modular Approach
Fig. 2.10 Solaris loadable modules.
Mac OS X Structure
Fig. 2.11 The Mac OS X structure.