Operating System Concepts 作業系統原理 Authors: Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Chapter 1: Introduction Instructor : Min-Shiang Hwang (黃明祥) Office: I-420 Tel : 1864 E-mail : mshwang@asia.edu.tw Skype: minshiang Facebook:http://www.facebook.com/mshwang (mshwang@nchu.edu.tw) Modified by Min-Shiang Hwang (亞大黃明祥) ©2013 Chapter 1: Introduction What Operating Systems Do Computer-System Organization Computer-System Architecture Operating-System Structure Operating-System Operations Process Management Memory Management Storage Management Protection and Security Distributed Systems Special-Purpose Systems Computing Environments Open-Source Operating Systems Operating System Concepts – 8th Edition 1.2 Modified by Min-Shiang Hwang ©2013 Objectives To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization 使學生瞭解一個作業系統的組成及電腦 系統基本結構 Operating System Concepts – 8th Edition 1.3 Modified by Min-Shiang Hwang ©2013 1.1 What Operating Systems Do What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware Operating system goals: Execute user programs and make solving user problems easier Make the computer system convenient to use Use the computer hardware in an efficient manner 作業系統 (Operating system) 是介於使用者與電腦硬體之間的管理 軟體。 目的在於提供使用者—便利有效的執行程式環境。做為計算機系統 資源的管理者,以有效的管理方式來使用硬體的原動力,提供使用者 可執行程式的方便環境。 Operating System Concepts – 8th Edition 1.4 Modified by Min-Shiang Hwang ©2013 Four Components of a Computer System 一個電腦系統分成四個單元:硬體(Hardware)、作業系統(Operating System)、應用程式(Application Program)、使用者(User)。 編譯程式 組譯程式 本文編輯器 資料庫系統 CPU (Central Processing Unit)、 記憶體(Memory)、輸入/輸出裝置(I/O) Operating System Concepts – 8th Edition 1.5 Modified by Min-Shiang Hwang ©2013 Computer System Structure Computer system can be divided into four components Hardware – provides basic computing resources CPU, memory, I/O devices Operating system Controls and coordinates use of hardware among various applications and users Application programs – define the ways in which the system resources are used to solve the computing problems of the users Word processors, compilers, web browsers, database systems, video games Users People, Operating System Concepts – 8th Edition machines, other computers 1.6 Modified by Min-Shiang Hwang ©2013 1.1.1 User View of Operating Systems Mainframe view: to maximize “resource utilization”, to that all available CPU time, memory, and I/O are used efficiently, and that no individual user takes more than her fair share. 大型電腦的使用者認為 OS 應做資源使用的最大化 Workstation or Server view: to compromise between individual usability and resource utilization 兼顧使用方便性與有效的管理資源 PC view: OS is designed mostly for “ease of use”, with some attention paid to performance, and none paid to resource utilization 個人用電腦使用者認為 OS 應提供容易使用的介面 Operating System Concepts – 8th Edition 1.7 Modified by Min-Shiang Hwang ©2013 User View of Operating Systems Handheld view: mostly for individual usability, but performance per amount of battery life is important. 有使用電池及顯示螢幕大小的限制,因此OS 應只考 慮使用的方便性以及電池的壽命的問題。 Embedded system view: (嵌入式系統) have little or no user view. OS is designed to run without user intervention 根本不需要使用者介面 資源(軟硬體)容易使用(ease of use)、有效分享發揮 資源(resource utilization) Operating System Concepts – 8th Edition 1.8 Modified by Min-Shiang Hwang ©2013 1.1.2 System View of Operating System OS is a resource allocator - Manages all resources - Decides between conflicting requests for efficient and fair resource use 是資源分配者,會以有效率且公平的方式來管理與分配 系統資源。 OS is a control program Controls execution of programs to prevent errors and improper use of the computer 監督使用者程式的執行,避免程式發生錯誤或使用不當。 資源分配者(resource allocator) ; 控制程式(control program) - CPU時間、記憶體空間、檔案儲存空間、 I/O裝置 Operating System Concepts – 8th Edition 1.9 Modified by Min-Shiang Hwang ©2013 1.1.3 Defining Operating System No universally accepted definition “Everything a vendor ships when you order an operating system” is good approximation But varies wildly “The one program running at all times on the computer” is the kernel. Everything else is either a system program (ships with the operating system) or an application program 一個在電腦內部隨時都在執行的程式(核心 Kernel)(系統程式 & AP) 對於OS 並沒有一個完整適合的定義,通常說 OS 是用來 Controlling 與 Allocating 系統資源。 OS 是一個 Kernel ( 核心程式),因為隨時須要有它的存在。 一個 OS 是使用者與硬體的介面,做為電腦系統資源的管理者 ,以有效的管理方式來使用硬體,提供使用者可執行程式的環 境。 Operating System Concepts – 8th Edition 1.10 Modified by Min-Shiang Hwang ©2013 1.2 Computer-System Organization 1.2.1 Computer-system operation (計算機系統的運作) One or more CPUs, device controllers connect through common bus providing access to shared memory Concurrent execution of CPUs and devices competing for memory cycles 近代電腦系統包含單一或多個CPU和一些裝置控制器。經由 公用Bus(匯流排)存取共用記憶體。 監視器 磁碟控制器 Operating System Concepts – 8th Edition USB控制器 1.11 圖形顯示卡 Modified by Min-Shiang Hwang ©2013 Computer-System Operation I/O devices and the CPU can execute concurrently Each device controller is in charge of a particular device type Each device controller has a local buffer CPU moves data from/to main memory to/from local buffers I/O is from the device to local buffer of controller Device controller informs CPU that it has finished its operation by causing an interrupt 每一種I/O device 有專屬的device controller 實際操作 設備的使用程序。 device controller 需要專屬軟體來指揮它們,這些軟體 叫做驅動程式(device driver)。驅動程式對controller 下命令指揮它們完成輸出入工作。 因此,OS 透過driver 來控制與指揮device controller 對週邊設備做實際的I/O 動作。Controller 利用「中斷 (Interrupt)」告訴 OS 工作已完成。 Operating System Concepts – 8th Edition 1.12 Modified by Min-Shiang Hwang ©2013 Computer Startup bootstrap program (啟動程式) is loaded at power-up or reboot Typically stored in ROM or EPROM, generally known as firmware (軔體) Initializes all aspects of system Loads operating system kernel and starts execution 啟動OS 執行的最初程式稱為initial program 或bootstrap program 或IPL (Initial Program Loading),俗稱為開機程式。 啟動程式(bootstrap program)存於唯讀記憶體(ROM: Read-only Memory)或 可消除式唯讀記憶體(EEPROM: Electrically Erasable Programmable ROM)[通常稱為韌體firmware]。 開機後OS 會偵測系統的週邊設備,逐一載入每一種設備的驅動程式 (Driver)。 開機程式的作用是: (a) 設定系統初值或參數,包括CPU registers, device controllers,memory等等。(b) 從硬碟將作業系統核心載入記憶體 。(c) 啟動OS 的執行。 啟動OS 後所執行的第一個process 稱為init,init 會產生許多幕後的 login process 在那兒等候事件的發生,完成開機的程序。 Operating System Concepts – 8th Edition 1.13 Modified by Min-Shiang Hwang ©2013 The Concept of Interrupts The occurrence of an event is signaled by an interrupt from either hardware or software. Hardware may trigger an interrupt at any time by sending a signal to CPU. Software may trigger an interrupt by system call (monitor call) I/O device 產生的中斷訊號來告訴OS 現在I/O 工作已經完 成,I/O devices 包括滑鼠與鍵盤。 Software interrupt 又稱為trap (陷阱),是經由system call 產生的中斷。常見的trap有:(a) divide-by-zero ,(b) invalid memory access,(c) illegal instruction,(d) a request for OS service。 Operating System Concepts – 8th Edition 1.14 Modified by Min-Shiang Hwang ©2013 Common Functions of Interrupts Interrupt transfers control to the interrupt service routine generally, through the interrupt vector (中斷向量), which contains the addresses of all the service routines (中斷服務程式). Interrupt architecture must save the address of the interrupted instruction Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt A trap is a software-generated interrupt caused either by an error or a user request An operating system is interrupt driven OS 是中斷驅動,藉由interrupts 來產生相關的動作。中斷 是當代計算機的重要結構設計。 Operating System Concepts – 8th Edition 1.15 Modified by Min-Shiang Hwang ©2013 Interrupt Handling The operating system preserves the state of the CPU by storing registers and the program counter Determines which type of interrupt has occurred: polling vectored interrupt system Separate segments of code determine what action should be taken for each type of interrupt 中斷發生時,硬體將被中斷程式的暫存器以及return address 儲存在一個固定位置上,以便將來能夠恢復原來的 執行工作。 中斷的處理程序是:CPU 暫時終止目前的工作,立即移轉到 固定的記憶體位置上,此位置含有interrupt vector, interrupt vector 儲存interrupt service routine的起始 位址。CPU 根據這個位址去執行相關的服務工作。 Operating System Concepts – 8th Edition 1.16 Modified by Min-Shiang Hwang ©2013 Interrupt Timeline 硬體可以在任何時間藉由送給 CPU 一個信號觸發中斷。 軟體可以藉由執行一項特殊的系統呼叫(system call,也 叫做 monitor call) 觸發中斷。 Process: 行程、處理 CPU 與I/O 可同時進行,CPU 啟動I/O 動作,I/O 完成後會 發出中斷給CPU。 Operating System Concepts – 8th Edition 1.17 Modified by Min-Shiang Hwang ©2013 1.2.2 Storage Structure Main memory – only large storage media that the CPU can access directly Secondary storage – extension of main memory that provides large nonvolatile storage capacity Magnetic disks – rigid metal or glass platters covered with magnetic recording material Disk surface is logically divided into tracks, which are subdivided into sectors The disk controller determines the logical interaction between the device and the computer 任何要被執行的程式都必須儲存在可複寫記憶體,稱之為主記憶體 又叫做隨機存取記憶體 (Random-Access Memory或RAM)。以動態隨機 存取記憶體(DRAM: Dynamic RAM)的半導體技術製作而成。 load 指令從主記憶體搬移一個字元組(Byte)到 CPU 內部的暫存器, 而 store 指令則是搬移暫存器的內容到主記憶體。 大部份電腦系統提供輔助記憶體 ( secondary storage) 做為主記憶 體的延伸。輔助記憶體的主要要求是能夠永久保存大量的資料。 Operating System Concepts – 8th Edition 1.18 Modified by Min-Shiang Hwang ©2013 Magnetic Disk Operating System Concepts – 8th Edition 1.19 Modified by Min-Shiang Hwang ©2013 Storage Hierarchy Storage systems organized in hierarchy Speed Cost Volatility Caching – copying information into faster storage system; main memory can be viewed as a last cache for secondary storage 不同儲存系統間的主要差別是︰速度、價格、大小和揮發性 (Volatile)。揮發性:Power Off Data Lose 裝置快取記憶體(Cache)可以改善因為兩種元件之間的存取時間或傳輸 速率差別所造成的性能差別。 Cache 又稱為buffer memory 是一種成本高且速度快的儲存 設備。CPU 欲讀取資料會先檢查資料是否在cache,若是稱 之為hit,可立即取出使用;否則稱之為no hit,必須到記 憶體取出資料同時更新cache 的內容。 Operating System Concepts – 8th Edition 1.20 Modified by Min-Shiang Hwang ©2013 Storage-Device Hierarchy Cost 價格 Speed 速度 Capacity 容量 Volatile ------------Nonvolatile 慢 Operating System Concepts – 8th Edition 低 1.21 大 Modified by Min-Shiang Hwang ©2013 Electronic Disk 電子磁碟(electronic disk) 被設計成同時具有 volatile 與nonvolatile storages,這是由一個很大的 DRAM array 及一個隱藏的硬碟所組成的。通常資料只儲 存於DRAM,當停電或關機時,資料才被儲存於硬碟上。 Flash memory 也是屬於電子磁碟,常用於digital camera 與PDA中,存取速度比DRAM 慢,但不耗電可保存 資料。 NVRAM (Non-Volatile RAM)是DRAM 加上電池組,是 nonvolatile,速度比DRAM快。 Operating System Concepts – 8th Edition 1.22 Modified by Min-Shiang Hwang ©2013 1.2.3 I/O Structure How a Modern Computer Works 指令執行週期 執行的執行緒 指令與資料 每一種裝置控 (用在處理 制器負責特定 小量資料) DMA: Direct Memory Access (Device與記憶體直接存取) 週邊設備的輸 Device SCSI: Small Computer Systems Interface 出入工作,每 (用在處理大量資料) 一個裝置控制 器有自己的 local buffer Device Driver 所有的I/O 是由CPU 啟動的。CPU 根據I/O 的類別呼叫相 及一些暫存器 關的device driver,由device driver 將訊息與參數載 ,負責處理I/O 入於device controller 的registers中,並對 與local controller下達輸出入命令,由device controller 對週 buffer之間的 邊設備做實際I/O 動作。I/O 完成後由device 資料搬動。 controller 發出interrupt 訊號告訴CPU。 Operating System Concepts – 8th Edition 1.23 Modified by Min-Shiang Hwang ©2013 Direct Memory Access Structure Used for high-speed I/O devices able to transmit information at close to memory speeds Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention Only one interrupt is generated per block, rather than the one interrupt per byte DMA 是一種專門為high speed devices 做輸出入的設備。 它的作業程序是:首先由CPU 預設好I/O 所需要的buffer、 pointer 與counter 後,由CPU啟動DMA controller,讓DMA 自行去做記憶體與buffer 之間的大量資料讀寫的工作,而 不用CPU 的干預。每當讀寫完一筆資料後,才由DMA controller 發出中斷告訴CPU 工作已完成,接著再由CPU 重新設定buffer、pointer 與counter,繼續啟動DMA 做後 續的輸出入工作。 Operating System Concepts – 8th Edition 1.24 Modified by Min-Shiang Hwang ©2013 Caching Important principle, performed at many levels in a computer (in hardware, operating system, software) Information in use copied from slower to faster storage temporarily Faster storage (cache) checked first to determine if information is there If it is, information used directly from the cache (fast) If not, data copied to cache and used there Cache smaller than storage being cached Cache management important design problem Cache size and replacement policy Operating System Concepts – 8th Edition 1.25 Modified by Min-Shiang Hwang ©2013 1.3 Computer-System Architecture (電腦系統架構) 1.3.1 Single-Processor Systems (單一處理器系統) - Most systems use a single general-purpose processor (PDAs through mainframes) - Most systems have special-purpose processors as well 僅有一個一般處理器執行使用者的處理行程之系統。 Operating System Concepts – 8th Edition 1.26 Modified by Min-Shiang Hwang ©2013 1.3.2 Multiprocessor Systems (多處理器系統) Multiprocessors systems growing in use and importance Also known as parallel systems, tightly-coupled systems Advantages include 1. Increased throughput 2. Economy of scale 3. Increased reliability – graceful degradation or fault tolerance Two types 1. Asymmetric Multiprocessing 2. Symmetric Multiprocessing 擁有一個以上的處理器,共同使用匯流排、時脈、記憶體、 周邊裝置。 使用多處理器系統有三個優點:1. 增加產量 2.經濟度量 (共用周邊設備) 3. 增加可信度(容錯性: Fault Tolerant)。 Operating System Concepts – 8th Edition 1.27 Modified by Min-Shiang Hwang ©2013 Symmetric Multiprocessing Architecture 目前有兩種類別:1. 非對稱多元處理(asymmetric multiprocessing)-主處理器會指定每個處理器不同之任務, 有主從關係 2.對稱多元處理(symmetric multiprocessing, SMP)-每個處理器執行相同之任務,沒有主從關係。 Operating System Concepts – 8th Edition 1.28 Modified by Min-Shiang Hwang ©2013 A Dual-Core Design (雙核心設計) 單一晶片 雙核心設計比二元處理器還有效率(內部通信)及省電。 Operating System Concepts – 8th Edition 1.29 Modified by Min-Shiang Hwang ©2013 1.3.3 Clustered Systems (集成式系統) Like multiprocessor systems, but multiple systems working together Usually sharing storage via a storage-area network (SAN) Provides a high-availability service which survives failures Asymmetric clustering has one machine in hot-standby mode Symmetric clustering has multiple nodes running applications, monitoring each other Some clusters are for high-performance computing (HPC) Applications must be written to use parallelization 集成式電腦分享儲存裝置,經由區域網路、無線寬頻網路彼此相連,可 提供高的取得率(high-availability) 。 非對稱集成系統(asymmetric clustering)- 一台機器處於熱待機狀態 (hot-standby mode)為一監督工作的伺服器, 其他機器則執行應用程式。 對稱集成系統(symmetric clustering)- 所有機器均執行應用程式並互 相監督。 Operating System Concepts – 8th Edition 1.30 Modified by Min-Shiang Hwang ©2013 Operating System Concepts – 8th Edition 1.31 Modified by Min-Shiang Hwang ©2013 1.4 Operating System Structure (作業系統架構) Multiprogramming needed for efficiency Single user cannot keep CPU and I/O devices busy at all times Multiprogramming organizes jobs (code and data) so CPU always has one to execute A subset of total jobs in system is kept in memory One job selected and run via job scheduling (工作排班) When it has to wait (for I/O for example), OS switches to another job Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Response time should be < 1 second Each user has at least one program executing in memory process If several jobs ready to run at the same time CPU scheduling If processes don’t fit in memory, swapping moves them in and out to run Virtual memory allows execution of processes not completely in memory Operating System Concepts – 8th Edition 1.32 Modified by Min-Shiang Hwang ©2013 Memory Layout for Multiprogrammed System 作業系統提供執行程式的環境, 工作排班的最重要觀念就是多元 程式規劃的能力。多元程式規劃 (multiprogramming)的目的就是 讓CPU始終有工作做,以增加CPU 的使用率。 作業系統在同一時間存放數項工 作在記憶體中,這一組工作是工 作池(job pool)中所有工作的部 份集合,作業系統把工作池中的 一項工作挑出來並且開始執行。 Time Sharing(分時)或 Multitasking(多工)是常用的多 元程式規劃技術。 Operating System Concepts – 8th Edition 1.33 Modified by Min-Shiang Hwang ©2013 1.5 Operating-System Operations (作業系統的運作) Interrupt driven by hardware Software error or request creates exception or trap Division by zero, request for operating system service Other process problems include infinite loop, processes modifying each other or the operating system 現代作業系統是中斷驅動式 (interrupt driven),如果沒有行程要 執行,沒有I/O裝置要服務和沒有使用者需要回應,則作業系統將安 靜進入等待事件發生;事件通常都是由於中斷或陷阱(Trap)的發生 (如被0除)而被通知。 因為作業系統和使用者共用電腦系統中硬體和軟體的資源,在共用的 情況下,一個程式中的錯誤(如Infinite Loop)可能會使許多工作受 到不利影響。 一個設計正確的作業系統必須保證一個不正確的 (或蓄意破壞的)程 式不會造成其他程式不正確的執行。 Operating System Concepts – 8th Edition 1.34 Modified by Min-Shiang Hwang ©2013 1.5.1 Dual-mode Operation (雙模式運作) Dual-mode operation allows OS to protect itself and other system components User mode and kernel mode Mode bit provided by hardware Provides ability to distinguish when system is running user code or kernel code Some instructions designated as privileged, only executable in kernel mode System call changes mode to kernel, return from call resets it to user 為了確保作業系統正常操作,一定要能夠區別作業系統程式碼和使用者 定義程式碼的操作。 使用者模式 (user mode)和核心模式 (kernel mode或 supervisor mode,也稱為系統模式,system mode或特權模式,privileged mode)。 在系統啟動時,硬體必須由核心模式開始。然後載入作業系統,接者在 使用者模式開始執行使用者應用程式。每當一個插斷或中斷(Interrupt) 發生時,硬體從使用者模式轉換到核心模式,作業系統得到電腦的控制 權時,電腦就是在核心模式中。使用者程式再將控制權交給一個使用者 程式之前, 轉換到使用者模式。 Operating System Concepts – 8th Edition 1.35 Modified by Min-Shiang Hwang ©2013 1.5.2 Timer (計時器) Timer to prevent infinite loop / process hogging resources Set interrupt after specific period Operating system decrements counter When counter zero generate an interrupt Set up before scheduling process to regain control or terminate program that exceeds allotted time 必須保證作業系統維持控制;必須防止使用者程式陷入一個無窮迴路之中, 而永遠不把控制權交還給作業系統。為達成此目的,可以使用一個計時器 (timer) Transition from User to Kernel Mode Operating System Concepts – 8th Edition 1.36 Modified by Min-Shiang Hwang ©2013 計時器設定在某段時間之後中斷電腦。其週期可以是固 定的 (例如,1/60秒)或可變的(例如,從1毫秒到1秒)。 用計時器來防止使用者程式執行太久。簡單的技巧是用 程式允許的時間量設定計數器之初值。例如,具有 7分 鐘時間限制的程式設定計數器初值為420。每過 1秒鐘, 計時器就會發出中斷且計數器值減 1。只要計數器值為 正,控制權仍回到使用者程式。當計數器值擴成負值時, 作業系統因為程式超過其時間限制而終止執行。 37 Operating System Concepts – 8th Edition 1.37 Modified by Min-Shiang Hwang ©2013 1.6 Process Management (行程管理) A process is a program in execution. It is a unit of work within the system. Program is a passive entity, process is an active entity. Process needs resources to accomplish its task CPU, memory, I/O, files Initialization data Process termination requires reclaim of any reusable resources Single-threaded process has one program counter specifying location of next instruction to execute Process executes instructions sequentially, one at a time, until completion Multi-threaded process has one program counter per thread Typically system has many processes, some user, some operating system running concurrently on one or more CPUs Concurrency by multiplexing the CPUs among the processes / threads 行程(process)可以視為執行中的程式,行程需要某些特定的 資源,包括 CPU時間、記憶體、檔案和I/O裝置等,以完成其 工作。這些資源在行程產生或執行時就會配置給它,除了實 體資源和邏輯資源的配置之外,有些起始資料 (輸入)也可能 會隨著行程的產生而產生。 Operating System Concepts – 8th Edition 1.38 Modified by Min-Shiang Hwang ©2013 Process Management Activities The operating system 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 行程管理方面,作業系統必須提供下列的功能: 在CPU上的行程及執行緒排班 使用者和系統行程的產生與刪除 行程的暫停和恢復 提供行程同步機制(process synchronization) 提供行程通信機制(process communication) Operating System Concepts – 8th Edition 1.39 Modified by Min-Shiang Hwang ©2013 1.7 Memory Management (主記憶體管理) All data in memory before and after processing All instructions in memory in order to execute Memory management determines what is in memory when Optimizing CPU utilization and computer response to users Memory management activities Keeping track of which parts of memory are currently being used and by whom Deciding which processes (or parts thereof) and data to move into and out of memory Allocating and deallocating memory space as needed 程式執行時,主記憶體必須映對到絕對位址並且載入主記憶體之中。 程式執行時,藉由產生程式指令和資料的絕對位址,才能從記憶體存取。程 式結束時,它釋放出記憶體為可用狀態,以及載入下一個程式並且執行它。 記憶體管理方面,作業系統必須具有下列的功能: 記錄正在使用的記憶體部份以及是誰在使用 在記憶體空間可用時決定載入的行程 在需要時配置和回收記憶體空間 1.40 Operating System Concepts – 8 Edition th Modified by Min-Shiang Hwang ©2013 1.8 Storage Management (儲存體管理) OS provides uniform, logical view of information storage Abstracts physical properties to logical storage unit file Each medium is controlled by device (i.e., disk drive, tape drive) Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random) 作業系統提供資訊儲存一個一致性的邏輯觀點,目的是為 了讓使用者能更方便的使用電腦系統。 作業系統摘取儲存裝置的實體特性並將之定義成邏輯儲存 單元,也就是檔案 Operating System Concepts – 8th Edition 1.41 Modified by Min-Shiang Hwang ©2013 1.8.1 File-System Management (檔案系統管理) Files usually organized into directories Access control on most systems to determine who can access what OS activities include Creating and deleting files and directories Primitives to manipulate files and dirs Mapping files onto secondary storage Backup files onto stable (non-volatile) storage media 檔案的建立與刪除 檔案的目錄建立與刪除 處理(操作)檔案和目錄 檔案與輔助記憶體的對映(Mapping) 穩定(非揮發性non-volatile)儲存裝置上的檔案備份 Operating System Concepts – 8th Edition 1.42 Modified by Min-Shiang Hwang ©2013 1.8.2 Mass-Storage Management (大量儲存體管理) Usually disks used to store data that does not fit in main memory or data that must be kept for a “long” period of time Proper management is of central importance Entire speed of computer operation hinges on disk subsystem and its algorithms OS activities Free-space management (可用空間管理) Storage allocation (記憶體配置) Disk scheduling (磁碟排班) Some storage need not be fast Tertiary storage includes optical storage, magnetic tape Still must be managed Varies between WORM (write-once, read-many-times) and RW (readwrite) Operating System Concepts – 8th Edition 1.43 Modified by Min-Shiang Hwang ©2013 1.8.3 Caching (快取記憶體) Movement between levels of storage hierarchy can be explicit or implicit Performance of Various Levels of Storage Operating System Concepts – 8th Edition 1.44 Modified by Min-Shiang Hwang ©2013 Migration of Integer A from Disk to Register Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy 硬體功能 作業系統 Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache Distributed environment situation even more complex Several copies of a datum can exist Various solutions covered in Chapter 17 Operating System Concepts – 8th Edition 1.45 Modified by Min-Shiang Hwang ©2013 1.8.4 I/O Subsystem (I/O 系統) One purpose of OS is to hide peculiarities (特質) of hardware devices from the user I/O subsystem responsible for Memory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs) (記憶體管理構成要素包括緩衝(buffering)、快取和連線同時週邊作業。) General device-driver interface (通用裝置驅動程式(Driver)介面) Drivers for specific hardware devices (特定硬體裝置驅動程式) Operating System Concepts – 8th Edition 1.46 Modified by Min-Shiang Hwang ©2013 1.9 Protection and Security (保護與安全) Protection – any mechanism for controlling access of processes or users to resources defined by the OS Security – defense of the system against internal and external attacks Huge range, including denial-of-service, worms, viruses, identity theft, theft of service Systems generally first distinguish among users, to determine who can do what User identities (user IDs, security IDs) include name and associated number, one per user User ID then associated with all files, processes of that user to determine access control Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file Privilege escalation allows user to change to effective ID with more rights 電腦系統有許多使用者並且允許同時執行多個行程,則存取資料必須井 然有序。 為了這個目的,必須提供一些功能以確保檔案、記憶體區段、CPU和其它 的資源只能經由作業系統所認可並授權的行程適當地操作。 Operating System Concepts – 8th Edition 1.47 Modified by Min-Shiang Hwang ©2013 1.10 Distributed Systems Distributed systems depend on networking for their functionality. Loosely coupled system – each processor has its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines. Advantages of distributed systems. - Resources Sharing - Computation speed up – load sharing - Reliability - Communications Requires networking infrastructure. Using Local area networks (LAN) or Wide area networks (WAN) or Metropolitan area networks (MAN) LAN 要求傳輸之速度快且錯誤率低,速度從1Mbps 到1Gbps,通常 Ethernet 是10BaseT (10Mbps) 以及100BaseT (100Mbps)。WAN通常透過 電話系統連結,典型的是T1 (1.544Mbps),T3 (28T1、45Mbps)。 Operating System Concepts – 8th Edition 1.48 Modified by Min-Shiang Hwang ©2013 1.11 Special-Purpose Systems (特殊用途系統) 1.11.1 即時嵌入系統(Real-time Embedded System) 嵌入式計算機是現存最普遍形式的計算機。這些裝置到處都可發現, 從汽車引擎和製造用機器人到VCRs 和微波爐。監督和管理硬體裝置。 嵌入式系統通常大部份執行即時作業系統(real-time operating systems)。 即時系統是使用在使用者對於處理器的操作或資料的傳送在時間要求 上很嚴謹,因此它通常是用在專門應用範圍中的控制裝置。 感應器將資料傳送給電腦。電腦必須將資料加以分析,而且可能控制 調整以便修正感應器輸入。 控制科學實驗、醫學影像系統、工業控制系統,以及一些顯示系統都 屬於即時系統的例子。其它還有自動引擎燃料噴射系統、家用器具控 制器,以及武器系統也是即時系統。 Operating System Concepts – 8th Edition 1.49 Modified by Min-Shiang Hwang ©2013 1.11.2 多媒體系統(Multimedia System) 大多數的作業系統被設計成處理傳統的資料,像是文字檔、程式、 處理文字文件和試算表。 多媒體:MP3、DVD、視訊會議等。 1.11.3 手持系統(Handheld System) 手持系統包括了個人數位助理 (Personal digital assistants, PDAs),例如掌上型電腦與行動電話和許多使用特殊用途嵌入式作 業系統。 手持系統和應用的發展者面臨到許多挑戰,大部份的限制都是因為 這些裝置尺寸限制。 Operating System Concepts – 8th Edition 1.50 Modified by Min-Shiang Hwang ©2013 1.12 Computing Environments (計算環境) 1.12.1 Traditional computer (傳統計算Centralized System集中式) Blurring over time Office environment PCs connected to a network, terminals attached to mainframe or minicomputers providing batch and timesharing Now portals allowing networked and remote systems access to same resources Home networks Used Now to be single system, then modems firewalled, networked 系統不是整批式(Batch)就是交談式(Interactive)。整批式系統以預定方 式輸入(從檔案或其它資料來源),處理了大多數的工作,交談式系統等候 來自使用者的輸入。為了將計算資源的使用最佳化,多個使用者共用系統 的時間。分時系統對這些系統使用了計時器和排班演算法以便快速地經過 中央處理器循環程序給予每個使用者資源的分享。(Compiler vs. Interpreter) Operating System Concepts – 8th Edition 1.51 Modified by Min-Shiang Hwang ©2013 Computing Environments (Cont) 1.12.2 Client-Server Computing (客戶-伺服器系統) Dumb terminals supplanted by smart PCs Many systems now servers, responding to requests generated by clients Compute-server (計算伺服器系統) provides an interface to client to request services (i.e. database) File-server (檔案伺服器系統) provides interface for clients to store and retrieve files Operating System Concepts – 8th Edition 1.52 Modified by Min-Shiang Hwang ©2013 1.12.3 Peer-to-Peer Computing (對等式運算) Another model of distributed system P2P does not distinguish clients and servers Instead all nodes are considered peers May each act as client, server or both Node must join P2P network Registers its service with central lookup service on network, or Broadcast request for service and respond to requests for service via discovery protocol Examples include Napster and Gnutella 當節點參與網路,以集中式分佈服務在網路註冊它的服務。任何節點需 要服務,首先接觸這個集中式分佈服務,來決定那一個節點提供服務, 剩下來的通信在客戶端和服務提供者之間發生。 表現像客戶端的點,必須首先發現那一個節點提供需求服務,藉由播送 服務的需求,給網路上所有其它的節點。節點提供回應需求的服務,為 了支持這個方法,必須提供搜尋協定,讓點發現在網路上其它點所提供 的服務。 Operating System Concepts – 8th Edition 1.53 Modified by Min-Shiang Hwang ©2013 1.12.4 Web-Based Computing (網頁為基礎的計算) Web has become ubiquitous PCs most prevalent devices More devices becoming networked to allow web access New category of devices to manage web traffic among similar servers: load balancers Use of operating systems like Windows 95, client-side, have evolved into Linux and Windows XP, which can be clients and servers 雲端作業系統Chrome 網頁客戶端(Windows 95,98)伺服器(Windows XP, Linux)。 Operating System Concepts – 8th Edition 1.54 Modified by Min-Shiang Hwang ©2013 1.13 Open-Source Operating Systems Operating systems made available in source-code format rather than just binary closed-source. Counter to the copy protection and Digital Rights Management (DRM) movement. Started by Free Software Foundation (FSF), which has “copyleft” GNU Public License (GPL). Examples include GNU/Linux, BSD UNIX (including core of Mac OS X), and Sun Solaris. Operating System Concepts – 8th Edition 1.55 Modified by Min-Shiang Hwang ©2013