# Chp 1 Introduction ###### tags: `作業系統` [TOC] ### Operation System * Computer Structure ![](https://i.imgur.com/bRwPwAA.png =80%x) “The one program running at all times on the computer” is the kernel. ### Program, Proccese, Thread Ref: [Program/Process/Thread 差異](https://medium.com/@totoroLiu/program-process-thread-差異-4a360c7345e5) * **Program**: 還尚未load入記憶體的 code (工廠藍圖) * 相同 Program 的 Process 可以多個同時存在 * Passive Entity * **Process**: 已經執行並且 load 到記憶體中的 Program (運作之工廠) * Active Entity * Process 是電腦中已執行 Program 的實體 * 一個 CPU 一次只能執行一個 Process,每一個 Process 互相獨立 * Process 的運行量總量不會少於 CPU 的總量 * **Thread**: Process 是 Thread 的容器 (工廠工人) * 同一個 Process 可以同時存在多個 Thread * ~~同一個 Process 底下的 Thread 共享資源,不同的Process 則否~~ * 兩個以上執行緒若同時存取或改變全域變數(Global Variable),則可能發生同步(Synchronization,恐龍本第六章)問題。 * 若執行緒之間互搶資源,則可能產生死結(Deadlock,恐龍本第七章) >[color=#ff00ff]不同的Process一樣可以共享資源,這可以藉由share memory或是message passing model達成,message passing model可以是socket或是其他的通訊方式 >不管是thread或是process之間,要共享資源就要解決互搶資源的現象,如同Thread第3,4點所述,解決的方式可以藉由添加互斥鎖,之後會教。 >[name=Neko] * **program counter** * specifying location of next instruction to execute * one program counter per thread ### Interrupt * **Polling** * Idle 時,固定隔一段時間從`Queue`檢查是否有`interrupt` >[color=#ff00ff]說Queue好像有點怪怪的,但是總之就是固定去檢查裝置 >[name=Neko] * **vectored interrupt** system * [vectored v.s. non-vectored interrupt](https://vivadifferences.com/difference-between-vectored-and-non-vectored-interrupts/) * Interrupt v.s Trap(or exception) - **Interrupt** * hardware-generated - **Trap**: * software-generated ### I/O Structure * System call - request to the OS to allow user to wait for I/O completion. * Device-status table - 同時有很多I/O運作,儲存各個I/O狀態在此 ### Storage * Storage Hierarchy - Speed - Cost - Volatility (need extra power to store the data) ![](https://i.imgur.com/twsyCvU.png) * **Main Memory** - Random access - Volatile * **Caching** - Copying information into faster storage system * **Direct Memory Access(DMA)** - Transfers blocks of data from buffer storage directly to main memory without CPU. - Close to the memory speeds ### Computer-System Architecture * **DEFINITION** * **Core** — The basic computation unit of the CPU. * **CPU** — The hardware that executes instructions. * **Processor** — A physical chip that contains one or more CPUs. * **Multiprocessors** * parallel systems, tightly-coupled systems * [Types & Difference](https://techdifferences.com/difference-between-symmetric-and-asymmetric-multiprocessing.html) * Asymmetric Multiprocessor * Only Master processor run the tasks of OS * Master processor allocate work to slave processor * No-shared memory * Symmetric Multiprocessor * Each processor run the tasks in OS * shared memory * **Multi-chip, Multicores** ![](https://i.imgur.com/KkRtq5A.png =60%x) * **Multiprocessor VS Multicore** | | Multicore | Multiprocessor | | -------- | -------- | -------- | | Definition | a **single CPU** with <br> multiple execution unit | a system that <br> has **two or more CPUs** | | Advantage | execute single program faster | execute multiple program faster | | Reliablility | not reliable | more reliable<br>CPU won't affect the other| * **Multiprogramming (Batch system)** * organizes jobs to keep CPU executing * require **job scheduling** * **Timesharing (multitasking)** * CPU switches jobs frequently to create **interactive** computing * require **CPU scheduling** * **Clustered Systems** * multiple systems working together * **parallelization** required * **distributed lock manager** (DLM) avoid conflict operations * Type * Asymmetric * one machine in hot-standby mode * a hot standby node is part of the system . The hot standby node continuously monitors the server and if it fails, the hot standby node takes its place. * Symmetric * multiple nodes running, monitoring each other >[color=#00ff00]Network 的概念? > >[name=Omnom] ### Dual-Mode * **Purpose:** Allow OS to protect itself and other system components. * **user mode (mode bit=1)** and **kernel mode (mode bit=0)** * Some privileged instructions only excutable in kernel mode ![](https://i.imgur.com/14uqKhP.png) ### Network * **Distributed Computing (TCP/IP)** - Local Area Network (LAN) - Wide Area Network (WAN) - Metropolitan Area Network (MAN) - Personal Area Network (PAN) * **Client-Server** - Compute-server: clients request services - File-server: clients store and retrieve files * **Peer-to-Peer** - no distinguish clients and servers - Broadcast request via **discovery protocol** ### Virtualization [Simulator and Emulator](https://hwchen18546.wordpress.com/2014/03/06/vm-simulator-and-emulator/)