1 / 65

第一章 簡介

第一章 簡介. 鄧姚文 http://www.ywdeng.idv.tw. 大綱. 什麼是作業系統 作業系統的類型 作業系統概念 作業系統的結構. 簡介. 電腦的組成 硬體 (hardware) 系統程式 (system programs) OS 以 kernel mode 執行 Compiler, Editor 以 user mode 執行 應用程式 (application programs). 電腦的組成. 什麼是作業系統. 功能的延伸 Extended machine, virtual machine

Download Presentation

第一章 簡介

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第一章簡介 鄧姚文 http://www.ywdeng.idv.tw Tanenbaum作業系統2Ed

  2. 大綱 • 什麼是作業系統 • 作業系統的類型 • 作業系統概念 • 作業系統的結構 Tanenbaum作業系統2Ed

  3. 簡介 • 電腦的組成 • 硬體(hardware) • 系統程式(system programs) • OS 以 kernel mode 執行 • Compiler, Editor 以 user mode 執行 • 應用程式(application programs) Tanenbaum作業系統2Ed

  4. 電腦的組成 Tanenbaum作業系統2Ed

  5. 什麼是作業系統 • 功能的延伸 • Extended machine, virtual machine • Easier to program • 將底層繁瑣的工作隱藏起來 • 提供友善的、易於使用的介面給使用者 • 資源管理者(resource manager) • 資源(resource):CPU time, memory space,… • 誰可以取得某一項資源的使用權? 何時生效? 可以用多少? 可以用多久? • Time multiplexed, space multiplexed Tanenbaum作業系統2Ed

  6. 作業系統簡史 • 第一部數位計算機 analytical engine • 英國數學家 Charles Babbage • 純機械式,失敗! • 可程式化,第一位程式設計師:Ada Byron • 第一代:1945-55 • Vacuum tubes(真空管) & Plugboards • Programming in machine language • 沒有程式語言,沒有OS • 1950 punched card 打孔卡 Tanenbaum作業系統2Ed

  7. 作業系統簡史 • 第二代:1955-65 • Transistor(電晶體)& batch system(批次系統) • Mainframe 大型主機,商業用途 • 價格昂貴,只有大公司與政府機關負擔得起 • FORTRAN 程式語言 • 批次系統 • 減少設定時間 • 收集許多 job,一次做完 Tanenbaum作業系統2Ed

  8. Batch Systems 早期的批次系統 • bring cards to 1401 • read cards to tape • put tape on 7094 which does computing • put tape on 1401 which prints output Character-Oriented Character-Oriented Word-Oriented Tanenbaum作業系統2Ed

  9. 控制卡 • Structure of a typical FMS job – 2nd generation Tanenbaum作業系統2Ed

  10. 作業系統簡史 • 第三代: 1965-1980 • IC(積體電路)&multiprogramming • IBMSystem/360 • OS/360, written in assembly language 組合語言 • Multiprogramming 多重程式 • 提高資源使用率 • Spooling (simultaneous peripheral operation on line) • CTSS (compatible time sharing system) Tanenbaum作業系統2Ed

  11. Multiprogramming 多重程式 • Multiprogramming system • three jobs in memory – 3rd generation Tanenbaum作業系統2Ed

  12. 作業系統簡史第四代: 1980 至今 • LSI (Large Scale IC), VLSI • Microprocessor 微處理器 • Intel 4004, 8008, 8080, 8086, 80286, 80386, 80486, Pentium • Apple 蘋果電腦 • Steve Jobs • IBM PC • Microsoft 微軟: MS-DOS, Windows • IBM OS/2 Tanenbaum作業系統2Ed

  13. The Operating System Zoo • 大型主機 Mainframe operating systems • 伺服器 Server operating systems • 多重處理 Multiprocessor operating systems • 個人電腦 Personal computer operating systems • 即時 Real-time operating systems • 嵌入式 Embedded operating systems • 智慧卡 Smart card operating systems Tanenbaum作業系統2Ed

  14. Mainframe OS • 特點:容量大 • 數 TB 記憶體 • 數千顆硬碟 • 服務模式 • Batch:不與使用者互動 • Transaction processing:large number of small requests, thousands per second • Timesharing:多位使用者同時使用電腦 • OS/390 Tanenbaum作業系統2Ed

  15. UNIX 簡史 • MULTICS: MULTiplexed Information and Computing Service • MIT, Bell Labs, GE 奇異電器 • GE-645 只比 386 PC 強一點 • Envisioned one machine providing computing power for everyone in the Boston area. • Written in PL/I • Bell Labs 退出,MIT 把 MULTICS 完成 • GE 把電腦部門賣給 Honeywell Tanenbaum作業系統2Ed

  16. UNIX 簡史(cont’d) • 1961 DEC PDP-1 • 4K of 18-bit words, $120,000 • AT&T Bell Labs Ken Thompson • PDP-7 • UNIX: a stripped-down, one-user version of MULTICS • 公開給學校使用 Tanenbaum作業系統2Ed

  17. Server OS • Servers ~ large personal computers, workstations, mainframes • Serve multiple users at once over a network • 資源的分享 • 提供各種服務 • UNIX(Linux, FreeBSD, Solaris, AIX), Windows Server 2000/2003 Tanenbaum作業系統2Ed

  18. Multiprocessor OS多重處理作業系統 • 使用多顆 CPU 以提高計算能力 • 平行處理電腦 • Parallel computers • Multi-computers • Multiprocessors • 伺服器作業系統大多數都支援多顆CPU • 雙核心、四核心、八核心? Tanenbaum作業系統2Ed

  19. PC 作業系統 • 主要任務: • 提供一個好用的介面 • 只服務一個使用者 • 應用程式種類繁多 • 文書處理 • 試算表 • 遊戲 • Windows 系列、MAC OS、Linux Tanenbaum作業系統2Ed

  20. Real-Time OS即時作業系統 • 時間最要緊 • 在規定的時間完成指定的工作 • Hard real-time • 不容許時間上的誤差 • 容許誤差值在一定的範圍內 • Soft real-time • 偶爾錯過時間也不要緊 • VxWorks, QNX Tanenbaum作業系統2Ed

  21. Embedded OS嵌入式作業系統 • 體積小 • PDA: personal digital assistant • 手機作業系統 • Palm OS • Linux • Windows CE • Consumer electronics Tanenbaum作業系統2Ed

  22. Smart Card OS智慧卡作業系統 • 最小型 • 大部分只提供單一功能 • 電子錢包付費 • JAVA oriented Tanenbaum作業系統2Ed

  23. 電腦硬體 • PC 硬體組成 硬碟 螢幕 軟碟 鍵盤 記憶體 匯流排 Bus Tanenbaum作業系統2Ed

  24. CPU 中央處理器 • Register 暫存器 • 一般用途暫存器:儲存運算中的資料 • Program Counter (PC) 程式計數器 • Stack Pointer (SP) 堆疊指標 • Program Status Word (PSW) 程式狀態暫存器 • 指令執行週期 • Fetch 擷取 • Decode 解碼 • Execute 執行 Tanenbaum作業系統2Ed

  25. CPU 中央處理器指令執行週期 Tanenbaum作業系統2Ed

  26. CPU 中央處理器Pipeline 管線 Tanenbaum作業系統2Ed

  27. CPU 中央處理器Superscalar 超純量架構 (a) A three-stage pipeline (b) A superscalar CPU Tanenbaum作業系統2Ed

  28. Memory 記憶體 • 典型的記憶體階層架構 • 越靠近 CPU 的記憶體越快、越貴、越小 容量 存取時間 暫存器 快取 主記憶體 磁碟 磁帶 Tanenbaum作業系統2Ed

  29. Memory 記憶體 • RAM: random access memory 隨機存取記憶體 • Volatile 電源中斷資料便消失 • ROM: readonly memory 唯讀記憶體 • Non-volatile 電源中斷後仍保留資料 Tanenbaum作業系統2Ed

  30. 磁碟架構 讀寫頭 讀寫臂移動方向 Sector:磁區 Track: 磁軌 Cylinder:磁柱 Tanenbaum作業系統2Ed

  31. 記憶體存取 • 記憶體保護 • 防止一支程式存取其他程式所使用的記憶體空間 • 記憶體重定址 memory relocation • 無法保證將程式載入到特定的記憶體位置 • Base Register 基底暫存器 • Limit Register 限制暫存器 • Virtual Address 虛擬位址 • Physical Address 實體位址 • Memory Management Unit (MMU) 記憶體管理單元 • Context Switch 內容切換 Tanenbaum作業系統2Ed

  32. 記憶體空間一對 base-limit 和 兩對 base-limit Tanenbaum作業系統2Ed

  33. I/O 裝置 • Device Driver 驅動程式 • 在 kernel mode 執行(大部分) • 在 user mode 執行(少見) • 裝置暫存器 • 主機與 I/O 裝置溝通的媒介 • 對映到主機記憶體空間,不需要 I/O 指令 • 對映到 I/O port 空間,需要 I/O 指令 • Busy Waiting: 以迴圈持續讀取裝置狀態 • Interrupt(中斷): 事件驅動 • DMA(Direct Memory Access) Tanenbaum作業系統2Ed

  34. I/O 裝置 & 中斷 (a) Steps in starting an I/O device and getting interrupt (b) How the CPU is interrupted Tanenbaum作業系統2Ed

  35. Bus 匯流排Pentium 系統匯流排架構 Tanenbaum作業系統2Ed

  36. 作業系統概念 • Process 行程 • Deadlocks 死結 • Memory management 記憶體管理 • Input/Output 輸出輸入 • Files 檔案系統 • Security 系統安全 • The shell 使用者介面、殼層 Tanenbaum作業系統2Ed

  37. Processes 行程 • A process is an instance of a program in execution. 執行中的程式 • Child process(子行程): created by its parent process • Interprocess communication: 行程間通訊 • Signal 信號(軟體中斷) • UID: user id(使用者識別碼) • GID:group id(群組識別碼) Tanenbaum作業系統2Ed

  38. Processes 行程 • A process tree • A created two child processes, B and C • B created three child processes, D, E, and F Tanenbaum作業系統2Ed

  39. Deadlocks 死結 (a) A potential deadlock. (b) an actual deadlock. Tanenbaum作業系統2Ed

  40. Deadlock 死結 • P1索取R1,配置成功 • P2索取R2,配置成功 • P1索取R2,等待 • P2索取R1,等待 R1 4 1 P2 P1 2 3 R2 • 如何避免死結發生? • 如何知道系統中有死結? • 如何解開死結? Tanenbaum作業系統2Ed

  41. Memory Management 記憶體管理 • Address Space: 定址空間 • 32位元CPU的定址空間: 232(4GB) • 64位元CPU的定址空間: 264(16EB) • 你的電腦有多少記憶體? • Virtual Memory虛擬記憶體 • 以硬碟存放記憶體中暫時不用的部分 • Linux: swap partition, swap file • Windows: swap file Tanenbaum作業系統2Ed

  42. File system 檔案系統 File system for a university department Tanenbaum作業系統2Ed

  43. UNIX 檔案系統掛載(mount) • Before mounting, • files on floppy are inaccessible • After mounting floppy on b, • files on floppy are part of file hierarchy Tanenbaum作業系統2Ed

  44. 檔案系統名詞 • Root directory: 根目錄, 目錄樹狀結構的最頂層 • Home directory: 家目錄, 系統指派給使用者的預設活動空間, 使用者登入系統後看到的第一個目錄 • Working directory: 工作目錄, 程式執行時所在的目錄 Tanenbaum作業系統2Ed

  45. 檔案和 I/O 的關係 • UNIX 系統把所有的 I/O 裝置都包裝成檔案 • Block special file: 區塊特殊檔, 以區塊為單位做 I/O • /dev/hdb2 第2顆 IDE 硬碟的第2個磁碟分割 • Character special file: 以字元為單位做 I/O • /dev/console 主控台 • Pipe 管道: 連接兩個行程, 行程間通訊 Tanenbaum作業系統2Ed

  46. Interprocess communication 行程間通訊 Two processes connected by a pipe Tanenbaum作業系統2Ed

  47. Security 安全性 • 機密資料 • 電子郵件 • 帳號, 密碼 • 資料檔案 • 存取權限 • UNIX 使用 rwx 位元 • ACL:access control list 存取控制清單 Tanenbaum作業系統2Ed

  48. Shell 殼層 • 使用者與 OS 互動的介面 • UNIX • sh, csh, bash, tcsh, ksh, zsh • Windows • command.com, cmd.exe • I/O redirection 重新導向 • date > file • sort < inputdata > outputdata • ps -elf | grep httpd Tanenbaum作業系統2Ed

  49. System Calls 系統呼叫 • 使用者程式與 OS 之間的溝通介面 • POSIX 國際標準 9945-1 • int count = read(fd, buffer, nbytes); • trap 指令將系統由使用者模式切換到核心模式 Tanenbaum作業系統2Ed

  50. 系統呼叫read (fd, buffer, nbytes) 的11步 Tanenbaum作業系統2Ed

More Related