操作系统学习笔记

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 memory

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: 记录位置信息
heap

Process Control Block

process state
process number
registers

1066857-20190115134251024-2050761843.png

How is PCB used?

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)

1066857-20190115210230133-148259435.png

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
可以访问地址空间的不同部分

  • Benefits of Multithreading
    并发执行: 将任务分解来加速
    specialization: hot cache
    高效: lower mm requirement & cheaper IPC

single CPU
multiple CPU
简单的比较:

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

1066857-20190116085753325-127292335.png

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时间段

转载于:https://www.cnblogs.com/kong-xy/p/10271523.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值