操做系統學習筆記

Udacity Introduction to Operating System

Introduction

What is operating system?

OS Elements

OS Design Principles

OS Services

Different OS design

  • Modular OS
  • Monolithic OS
  • Microkernel

Linux and Mac OS Architectures

Processes and Process Management

What is a process?

Process == state of a program when executing loaded in memorylinux

If the same program is launched more than once, multiple processes will be created面試

page table, do the mapping of the virtual address to the physical address併發

What does a process look like?

Data and text: 靜態信息
page table
stack: 記錄位置信息
heapapp

Process Control Block

process state
process number
registersui

How is PCB used?spa

What is a Context Switch?

進程切換花銷很大
direct cost: number of cycles for loading instructions
indirect cost: cold cache/ hot cache線程

Process Lifecycle

  • running:
  • idle:
    creation: fork (copy the parent PCB into new child PCB) and exec(replace child image with new one)

Threads and Concurrency

Process vs. Thread

the address space
code, data, files and its own thread
進程是不會有共同的address mapping的
不一樣的線程會有本身私有的程序計數器, 棧, 棧指針指針

thread would share all of the virtual to physical address mappings
能夠訪問地址空間的不一樣部分code

  • Benefits of Multithreading
    併發執行: 將任務分解來加速
    specialization: hot cache
    高效: lower mm requirement & cheaper IPC

single CPU
multiple CPU
簡單的比較:blog

  • if (t_idle) > 2 * (t_ctx_switch)
  • t_ctx_switch threads < t_ctx_switch processes

Basic Thread Mechanisms

thread data structure:
mechanisms to create and manage threads
mechanisms to safely coordinate among threads running concurrently

能夠讀取一樣的地址, 會致使inconsistency

面試題整理

  • 進程與線程的區別?

  • 進程和線程都是一個時間段的描述, 是CPU工做時間段的描述

CPU太快,
獲得CPU的時候,相關的資源必須已經就位, 除CPU以外的構成了程序的執行環境, 也就是咱們所說的程序上下文。

輪流執行CPU的方法: 先加載程序A的上下文,而後開始執行A,保存程序A的上下文,調入下一個要執行的程序B的程序上下文,而後開始執行B,保存程序B的上下文 進程就是包括了上下文切換的程序執行時間總和 = CPU 加載上下文 + CPU執行 + CPU保存上下文 線程就是貢獻了進程的上下文環境的更細小的CPU時間段

相關文章
相關標籤/搜索