2015年12月9日 星期三

Operating System - CH4 Threads

Process creation is heavy-weight
Thread creation is light-weight

multi-thread優點
  • responsiveness
  • resource sharing
  • economy
  • scalability 同一個process內的不同thread可以平行在不同CPUs上執行

multicore programming challenge
  • divide activities
  • balance
  • data splitting
  • data dependency
  • test and debugging

User Threads
Kernel Threads: kernel 知道每條thread


Operating System - CH3 Process

Process: a program in execution
  • program counter 
  • stack : temporary data
  • data section: global var
  • heap: containing memory allocated dynamicalling during run time

Process Control Block(PCB): kernel 為管理眾多processes, 會在kernel memory area中,針對每個process各自建立PCB, 紀錄process之related info.



Process Scheduling: 最大化CPU的使用,quickly switch process onto CPU from time sharing
  • job queue: all processes in system
  • ready queue: process in main memory, ready to execute
  • device queue: process waiting for an I/O devices

Process scheduler
  • long-term: 從 job queue 挑出進入ready queue
    • control the degree of multiprogramming
  • short-term: 從 ready queue挑出 準備進入CPU執行
  • medium term: 適合time-sharing, 可以調解CPU-bound and I/O-bound( spending more time doing I/O than computations, many short CPU bursts)

  • 當記憶體空間不足時,此時又有較高priority的process需要記憶體,scheduler就會將某些process swap out,等記憶體空間足夠時,才將之swap in 到ready queue


Operating System - CH2 Operating-System Structures

Command line interface or Command Interpreter allow direct command entry

System calls: programming interface to the services provide by the OS. 作為user processes與kernel之間的溝通介面,當執行中的user process需要OS提供的服務時,先發Trap通知OS, 並告訴OS要執行的服務項目, OS才執行一系列相關之system calls,完成該服務請求,並傳回結果給user process。

shells: 提供存取kernel的程式

OS design and implementation: 
  • user goals: convenient to use, learn, safe, fast
  • system goals: easy to design, implement and maintain

  • mechanism: how to do it
  • policy: what will be done?

Layered approach
  • 上層可以使用下層的服務,但下層不能使用上層
  • 上層為interface,下層為hardware
  • 優點: 模組化,可以分工加速系統開發,易測試與維護
  • 缺點: 難以界定層次的劃分

Microkernel system structure
  • 將OS kernel眾多模組中移除一些較非必要的模組,改成在user mode下 以system library(software)或user program來執行
  • use message passing
  • 優點
    • 容易extend
    • 移植到另一平台會更方便
    • more reliable(安全性提升)

Virtual Machines
  • OS 利用software技術, 創造出一份與底層硬體一模一樣的功能介面,此一abstract machine,稱為VM。
  • 很難去implement,must provide 底層硬體的複製,typically runs in user mode

core dump: application error log file
crash dump: os error log file