System Structure

A view of system structures
user and programs
[user interfaces]
[system calls]
[operating system services]
hardware

user interfaces
常見的有以下
CLI(command line interface)
GUI(graphic user interface)
Touchscreen interfaces

operating system services
常見的service有以下
program execution:載入程式進入memory並執行
I/O operations:
file-system manipulation
communications:processes may exchange information
error detection ex:error包括cpu過熱當機,memory損壞,…等
resource allocation:協調資源分配
accounting: 追蹤process的狀況
protection and security


…………………………………………………………………………..

system calls
programming interface to the services provided by the OS
ps:
大部份透過API來存取OS services,很少直接使用system calls

system call API
常見的有以下
win32 API, for ms windows
POSIX API, for unix,linux,mac os x
java API, for java virtual machine
ps:
API存取失敗時通常會回傳 -1

system call interface
主要分以下兩種
user mode:system call interface與user application溝通
kernel mode:system call interface與kernel溝通

system call parameter passing
常見方法有三種
registers:最簡單的方法,parameter放在registers
block:parameter存在block or table, memory,…等, linux,solaris使用該方法
stack:parameter透過program放在或pushed到stack

class of system calls 
主要依功能分為以下幾種

process control
常見工作如下
create/terminate process
get/set process attributes
wait for time,event,singal event
ex:
win: CreateProcess(),ExitProcess(),WaitForSingleObject()
unix: fork(),exit(),wait()

information maintenance
常見工作如下
get/set time or date
get/set system data
get/set process,file,device attributes
ex:
win: GetCurrentProcessID(),SetTimer(),Sleep()
unix: getpid(),alarm(),sleep()

file management
常見工作如下
craete/delete/open/close file
read/write/reposition device management
ex:
win: CreateFile(),ReadFile(),WriteFile(),CloseHandle()
unix: open(),read(),write(),close()

communications
常見工作如下
create/delete communication connection
message passing/shared-memory model
ex:
win: CreatePipe(),CreateFileMapping(),MapViewOfFile()
unix: pipe(),shmget(),mmap()

device management
常見工作如下
request/release/read/write device
get/set device attributes
ex:
win:SetConsoleMode(), ReadConsole(),WriteConsole()
unix:ioctl(),read(),write()

protections
常見工作如下
control access to resources
get/set permissions
allow/deny user access
ex:
win:SetFileSecurity(), InitlializeSecurityDescriptor(), SetSecurityDescriptorGroup()
unix:chmod(),umask(),chown()


………………………………


system kernel
作業系統最基本的部分
因使用頻率高,所以常駐於記憶體中
基本功能包含
 interrupt handling(處理中斷)
 process creation and destruction(處理單元的建立與中止)
 process state switching(處理單元的狀態轉換)
 dispatch(分配CPU 的使用權)
 process synchronization(處理單元之間的同步)
 I/O operation(處理輪出/輸入)
ps:
kernel 也稱為nucleus


System Structure
常見的有以下
Simple Structure(簡易架構)
 依當時的需求與環境直接設計
 優點:不需考量未知的難題,較容易設計
 缺點:無整體規劃,系統容易雜亂而互相干擾
 ex:MS-DOS
Layered Approach(階層架構)
 第 N 層的執行能力來自第 N-1 層提供的服務
 優點:整體系統沒有複雜牽扯的干擾
 ex:os/2
Microkernel(微核心)/Mach
 將所有在kernel中非必要的功能,以modules的方式呈現
 module也稱為Loadable Kernels(可載入核心)
 kernel也稱為core kernel
 優點:
  讓kernel變小也不會失去原有的功能
  可解決作業系統kernel太大時較難管理的問題
 ex:linux
ps:
hybrid 結構:表示兩個不同來源的OS作結合 
………………………………….

常見的OS系統結構

OS/2
architecture
layer4:application
layer3:application programming interface
layer2:subsystems
layer1:system kernel
layer0:device driver


Mac OS X
architecture

layer3: GUI
  Aqua
layer2: application enviroments and services
  Jaca,Cocoa,Quicktime,BSD
layer1: kernel enviroment
 Mach,BSD
 I/O kit,kernel extenions

iOS
修改後的Mac OS X
architecture
layer4: Cocoa Touch
layer3: Media Services
layer2: Core Services
layer1: Core OS

android
類似IOS,修改版的linux
architecture
layer2:application framework
layer1:
  libraries[SQLite,openGL,surface manager,media framework,webkit,libc]
  android runtime[Core Libraries,Dalvik virtual machine]