Skip to content

Latest commit

 

History

History
311 lines (242 loc) · 9.27 KB

操作系统期末复习.md

File metadata and controls

311 lines (242 loc) · 9.27 KB

操作系统期末复习

第一章

什么是OS

  • Consists primarily of:
    • Kernel
    • Systems programs

Version 1

  • A program that

    • manages computer hardware
    • provides basis for application programs
    • acts as an bridge between computer user and computer hardware
  • A resources allocator

    • manage all resources
    • deal with conflict resources request
  • A control program

    • control executions of programs to prevent errors and improper use

Version 2

  • An extended machine

    • using abstraction to hide complexity
    • provides high level operation using low level operation
  • An virtual machine

    • using virtualization to support sharing
    • provides virtual CPU, memory, devices
  • A resources manager

    • balance overall performance with individual needs

Version 3

  • make computer system easier to use

    • provides interface to run apps
    • protect data
    • provides read/write interface
    • implements TCP/IP stack
  • manage the resources of the computer

    • process management
    • memory management
    • storage management
    • protection and security

Kernel & User Model

What is Kernel

  • another program
  • run automatically when you power up your computer
  • terminates when you shut down your computer
  • Provides lower management of CPU, memory...

kernel Mode

  • full access to all hardware devices
  • only OS Kernel runs here

User Mode

  • limited access to hardware
  • all process run in this mode

Kernel 类型

Monolithic

  • a single large program
  • all kernel function can be invoked directly
  • very difficult to maintain/extend
  • difficult to isolate and debug

Layered

  • each layer provides services to the next higher layers
  • layers an change without impacting other layers by not changing the interface
  • I/O requires memory management
  • Memory management needs I/O

Microkernel

  • a bug in OS kernel can kill the system
  • kernel contain minimum function
  • remaining functionality is moved to "servers"
  • easier to port between hardware platforms
  • perform is often poor

Hypervisor/Virtualization OS

  • OS itself is tiny
  • services used by user are provided by "normal" OS running in virtual hardware
  • can combine many physical servers into one large server
  • computing power can be scheduled to where it is needed dynamically

Kernel如何运行 & 初始化

  • Hardware powers up and completes POST(Power On Self Test)
  • Microcode in ROM/BIOS performs “bootstrap”
  • First-stage boot loader searches devices for second-stage boot loader(PC checks floppy, optical disk, hard disk in some order)
  • Second stage boot loader loads and “runs” the OS kernel
  • Operating system undertakes initialization then starts one or more standard services to allow the user to interact with the system

第二章 Process & Threads

定义

Process & program

he difference is subtle, but absolutely crucial.

a computer scientist wants to bake a birthday cake for his daughter He has a birthday cake recipe and all the input: flour, eggs, sugar, extract of vanilla, and so on.

  • The recipe is the program
  • the computer scientist is the processor (CPU),and the cake ingredients are the input data.
  • The process is the activity consisting of our baker reading the recipe, fetching the ingredients, and baking the cake.

What is process

  • processes are logical resources
  • the concept of process is supported by hardware

Process Structure

  • programs
  • Datas
  • PCB

context switch & how often to switch

what is context & context switch

  • all the memory that can be accessed by program code
  • switching from one process to another means changing what memory can be accessed

How often to switch

More regular

  • OS becomes more responsive
  • Waste more time

Less regular

  • OS becomes less responsive
  • waste less time

抢占调度 & 非抢占调度

Preemptive Multitasking

  • Preempts the currently executing process and save its state
  • Change the hardware context to match the next process
  • Restore the state of next process and resume its execution

Non-Preemptive

  • Once a process is in the running state, it will continue until it terminates or blocks itself for I/O

Preemptive

  • Currently running process may be interrupted and moved to the Ready state by the operating system

各种状态

ready 到 block 是不可能的

  • Running
  • Ready
  • Ready suspend
  • Blocked
  • blocked supend
  • New
  • Exit

进程创建和终止

When to Create a process

  • Submission of a batch job
  • User logs on
  • Created to provide a service such as printing
  • Process creates another process

The procedure of creation

  • Allocate and initialize a PCB structure
  • Allocate at least three memory regions:
    • Text
    • Data/heap
    • Stack region
  • Connect standard input/output streams to the process
  • Initialize hardware context to match new process
  • Switch to user mode
  • set program counter to pre-defined code entry point

When to terminate process

  • Batch job issues Halt instruction
  • User logs off
  • Quit an application
  • Error and fault conditions

The procedure of termination

  • Program invokes a system call to the OS
  • OS stores the result in the PCB and frees all memory used by the process
  • PCB remains in a ‘terminated’ state until the parent process retrieves the result

线程概念 & 优缺点 & 创建和终结

第三章 Process Schedule

长 中 短程调度

Long_Term Scheduling

  • Determines which programs are admitted to the system for processing
  • When will the Scheduling be invoked
    • Each time a job terminates
    • Processor is idle exceeds a certain threshold

Medium-term Scheduling

  • It schedules the process swapped out to disk in memory, ready to execute

Short-term scheduling

  • schedule process to run
  • execute most frequently
  • involved when an event occurs

计算密集型 & I/O密集型

  • A compute bound process spends most of its time performing computations

  • An I/O bound process spends most of its time waiting for input or output

进程调度的概念 & 目标

  • Fairness(公平)
  • Policy enforcement
    • Some jobs may have unusual requirements
  • Balance
    • Keep as much of the system busy as possible
  • Throughput(吞吐量)
    • The number of jobs completed per unit of time, e.g., per hour
  • Turnaround time(周转时间)
    • The time from when a job is first submitted until it is completes/exits
  • CPU utilization
    • Keep the CPU busy/working at all times, an idle CPU is wasted time
    • Remember a context switch is wasted time!
  • Response time
    • The time it takes for a program to respond to input, e.g., typing in a command to the shell in Linux
  • Proportionality(均衡性)
    • System matches user expectations, e.g., simple jobs are quick, complex jobs take time
  • Meeting deadlines
  • Predictability(可预测性)

调度算法

FCFS

SJF(Non-preemptive)

SRTN(Preemptive)

RR

第四章 存储管理

进程如何共享存储

交换概念是什么(swap)

  • Save out memory contents to disk
  • Load next program’s memory contents from disk

Memory Abstraction

  • Processes have an abstract view of memory (logical address space)
  • Every logical memory address is then mapped to a physical address (physical address space)
  • processes do not work directly with physical memory Uses hardware support to improve efficiency

储存分配算法

first、worst,,,,

Fixed Partition

  • any process whose size is less than or equal to the partition size can be loaded into an available partition.
  • if all partitions are full, the operating system can swap a process out of a partition

Dynamic Partition

  • Partitions are of variable length and number. Process is allocated exactly as much memory as required.
  • Eventually get holes in the memory. This is called external fragmentation(外零头).
  • Must use compaction(紧凑) to shift processes so they are contiguous and all free memory is in one block.

Buddy System

Dynamic Partitioning

各种算法的特点

first号next易混淆

Virtual Memory 概念

  • Processes access virtual address space
  • Virtual address space is mapped to the physical address space by:
    • Hardware: The MMU(Memory Management Unit) translates virtual memory addresses to physical addresses
    • Software: The operating system configures and manages the MMU
  • The virtual address space is broken up into small, fixed size chunks known as pages

了解TLB

  • Contains page table entries that have been most recently used.
  • Functions same way as a memory cache.
  • Given a virtual address, processor examines the TLB.
  • If page table entry is present (a hit), the frame number is retrieved and the real address is formed.
  • If page table entry is not found in the TLB (a miss), the page number is used to index the process page table.
  • First checks if page is already in main memory .
    • if not in main memory a page fault is issued.
  • The TLB is updated to include the new page entry.

第五章

页面置换算法(重点掌握)

第六章

竞争条件(了解)

临界区

互斥

单CPU同步

多CPU同步

消息传递(了解)

死锁

银行家算法(强调) 四个条件:mutual exclusion, 没听到1, 没听到2,没听到3

第九章

磁盘调度(重点)

SSF elevator upward & downward