操作系统重要考点+ 英文版

233 阅读6分钟

操作系统重要考点(上)+ 英文版

Chapter1

Master CPU mode

  • modern processors usually divide CPU modes into two ,three or four
  • A special bit is set in PSW. Set different CPU mode according to the running program's privileges to use resources and instructions(在PSW 中设置了一个特殊位,根据正在运行的程序使用不同的CPU 模式,来使用资源和指令)

Master privileged and non-privileged instructions

there are two CPU modes in OS

  1. privileged mode.(特权模式),it run operating system programs. It can only used by OS and cannot be used by the user program.

    such as :

    1.I/O instructions

    2.turn off interupts

    3.set the timer

    4.context switching

    5.clear the memory or remove a process from the memory

  2. non-privileged mode,it run user program.

    such as:

    1.read the status of processor

    2.read the system time

    3.generate any trap instructions

    4.send the final printout of printer

    Kernel mode:privilege instruction and non-privilege instruction

    User mode: non-privilege instruction

Master the concept of Interrupt/Exception

  • It is an input signal to the processors indicating an event that needs to immediate attention.(它是处理器的输入信号,指示需要立即注意的事件)
  • CPU suspend the program that is being executed,save the context,and switch to the corresponding event handler.After dealing with it,it returns to the breakpoint and resumes the interrupted program.

Understand how the interrupt/exception works

Take the I/O device interrput as an example:

  1. The printer send an interrupt signal to CPU(Hardware)
  2. The CPU detects the signal after finishing the current instruction,determine the surce of the interrut and sends a confirmation signal to the relebant device.(Hardware)
  3. CPU starts for software processing interrupts:the processor mode is switched to kernel mode(cpu模式切换到核心态)。save the context of the interrupt program in the system stack.(Hardware)
  4. CPU check the interupt vertor table according to the interrupt code to obtain relevant entriy address of the handler(CPU检查中断向量表根据中断码获取处理器相关的入口地址),PC set the address.When the new instruction cycle starts,CPU contril is transferred to the interrupt handler.(当新的指令周期开始,CPU 控制权转移到中断处理程序)(Hardware)
  5. Interrupt handler starts working.It save context information in the system stack.It check the status information if I/O devices ...(Software)
  6. When the interrupt processing ends,CPU detects the interrupt return instruction.(中断返回指令),and the context of interrupted program iis restored in the stack.(中断程序的上下文会在栈堆中恢复).Then CPU resumes a instrction cycle.(然后CPU 恢复指令周期)(Hardware)

Master the system call design priciples

  1. Raise an exception and switch from user mode to kernel mode(产生一个中断,切换CPU 状态)(Select a special instruction:trap instruction)
  2. System call number and parameter:Each system call is given a number made in advance.(每次系统调用前会提供一个数)(System call number and paramter)
  3. Store the entry address of the system call service routine(System call table)

Master the system call execution process

When a system call is made in user mode.The CPU will execute a trap instruction ,switch the CPU from user to kernel (cpu发出陷入指令,将cpu状态从用户态转换到核心态)

System call routine:

  1. save the context;save the parameters in kernel stack;transfer the control to the corresponding system call routine(把控制权给要执行的系统调用)(by checking system call table)
  2. execute system call routine(执行系统调用)’
  3. restore the context and return to the user program

Chapter2

Mutiprogramming and concurrency

Mutiprogramming : only one program will be able to get the CPU for executing.The main idea of mutiprogramming is to maximum the use of CPU

Concurrency:there are two or more programs begin to run at the same time period with same CPU.The order is not predetermined(顺序没有被提前决定)

Program Vs Process

PROGRAMPROCESS
BasicProgram is a set of instructionsWhen a program is executed,it is kown as process
Nature(性质)Passive(被动)Actice
LifespanLongerLimited
Required resoucesProgram is stored on disks,don't need other resoucesProgress holds CPU,memory address,disk,I/O, etc

Process states and state trantes and switching

  1. Three states

    ready, running, waiting/blocked

    image-20230212205521587

  2. Five states

    new, ready, running, waiting/blocked, terminated

    image-20230212205542023

  3. Seven states

    new, ready, running, waiting/blocked, blocked suspend, ready suspend, terminated

    image-20230212205554834

PCB

  • PCB called process control block.
  • A PCB is a data structure used by OS to store all the information about a process.
  • It is also a process describer.
  • When a process is created ,the operating system will create a corresponding PCB
  • It is a one-to-one relationship between the process and PCB
  • The process table is an array of PCB

Components:

  • Naming the process
  • State of the process
  • Resources allocated to the process
  • Scheduling information
  • Input/Output devices associated with process.

Context Switching

Triggers:

  1. Mutitasking:In a mutitasking environment, a process is switched out of the CPU so annother process can run(多任务)
  2. Interrupt handling(中断处理)
  3. Kernel and User Mode Switching(用户态核心态切换)

Process Control

  • Process management functions are usually placed in OS kernel
  • The OS kernel contains two aspects:Supporting functions and Resouce management functions
  • The process control operation completes the transition between the states of process by primitives:(A primitive is the smallest unit of processing)Process creation Process termination Process blocking Process wake-up Process Suspending Process activating Process Priority

Thread VS Process

  • A thread is a path of execution within a process.
  • A thread is known as a lightweight process.
  • A process can contain mutiple threads
  • The primary difference is that threads within the same process run in a shared meory space,while processes run in sperate memory spaces(线程在公用的内存空间,进程在分散的内存空间)

Advantages over process:

  1. Its output can be immediately returned.
  2. Faster context switch.
  3. Effectively using multiprocessor system(更有效利用多处理器系统)

Components:

Thread Id,program counter (程序计数器), register set(寄存器集合),stack,

Thread impletation

User level thread

Example:UNIX

  • Create a thread libarary in user spcace:provide a set of management
  • completion of thread management(完成线程管理)
  • Process manage the kernel(进程管理核心态),does not know the existence of the threads
  • Thread swiching does not need kernel privilege

Kernel Level Thread

Example:Windows

  • The kernel manage all the threads,and provide API to the application(核心态管理所有的线程,并且提供api给应用)
  • The kernel maintains the context of processes and threads(核心态维持进程和线程的上下文)
  • Thread switching requires kernel support(线程切换需要核心态支持)

Hybrid model(混合模式)

Example:Solaris

  • Thread creation is done in user model
  • Thread scheduling is completed in kernel model(线程调度在核心态完成)

Chapter 3

Illustrate CPU scheduler category(阐述CPU 调度种类)

  • Long-term scheduler.(high-level scheduler,Job scheduler)

    Primary aim of the Job Scheduler is to maintain a good degree of Multiprogramming(作业调度程序主要是保持良好的进程并发水平)

  • Short term scheduler (low-level scheduler, CPU scheduler)

  • Medium term scheduler (Swapping)

Goals of Scheduling

  • Maximum CPU usage(最大化CPU使用)

    CPU utilization = CPU serve time / CPU serve time + idle time

  • Fairnes

  • Short average of turnaround time

Describe components of CPU scheduler

Enqueuer

It adds a pointer or reference to the process of PCB,which is usally a collection of linked lists(将PCB 的引用加入一个列表)

Dispatcher

The part that implements the scheduling algorithem to pick the next process to run

Context Switcher

Loads the selected process onto CPU as the running process.(从CPU 选中的程序中加载运行)

CPU scheduling circumstances(CPU 调度情况)and context switch(上下文切换)

circumstances:

  1. When a process switch from the running state to waiting state
  2. When a process switch from the running state to ready state
  3. When a process switch from the waiting state to ready state
  4. When a process terminates

context switch:

  1. save the context of process A(such as program counter,status,registers)
  2. update A's PCB with new status
  3. move process A to an appropriate queue(ready,blocked)
  4. set the state of process B to running
  5. restore the context of PCB of process B.(such as program counter,status,registers)

Algorithem

FCFS(First come First serve)

image-20230212220122634

image-20230212220141810

SJF(Shorted Job First)&SRTF(shorted remaining time first)

image-20230212220510760

preemptive means "抢占"

HPF(highest priority first)

image-20230212221109272

weighed turn around time = turn around time/service time

image-20230212221216049

HRRN(Highest Response Ratio Next)高响应优先

image-20230212221732213

image-20230212221719345

As it is an non-preemptive alogorithem,every time it finish the task ,it will calculate the response ratio = 1+ w/s

w:wait time

s:service time

Mutilevel feedback scheduling algorithem

image-20230212222241592

多级反馈调度算法