OS Learning (II) (B Video Station)

2019.5.25

Page replacement algorithm

When a memory page fault is generated, if you already have free space in memory, you can select directly after the call, change the page tables.
If there is no space, it is necessary to call certain page, the page is then transferred to them, so, recall specifically which pages related to the associated scheduling algorithm.
1. paging algorithm, which has several?

process

2019.5.30
2. Each process corresponds to a single PCB, Process Control Block, what's the use? What uniquely identifies the presence of processes are?

2019.5.31
3. PCB What's in?

4. five life cycle stage of the process?

5. You can create a process under which three cases?

6. Under Which three cases, the process enters the blocking state? Who decides to enter the process blocked from running the state?

7. In both cases the process of waking up, after which the process will enter wake up?

8. The three basic status of the process? In each case the operating state is converted to a ready state or blocked state?

2019.6.1
9. What is the suspended process? Suspend the process which is divided into several?

10. How OS management process?

11. the history of the conventional process, only the thread, there is no thought, why should a thread?

12. What is the process, what is the thread, the thread has the characteristics of what the process can not have?

13. Generally browser is to use the process to achieve, used pages share a process, if one page collapse, which is a thread collapse, its shared code full collapse, all pages are collapsing, but Google's Chorome each browser is a browser arrange a process, so no interference between them.

14. The switching processes and threads which fast, and why?

15. The three kinds of thread main way to achieve?

16. The thread, the parent thread can generate child threads, Linux system, have created a function thread fork and execute () two functions, for replication fork threads, exec for rewriting the child, then the parent process child thread will wait for the end, but do wait operation, this is why?

17. The ranking concept explained

  • CPU usage
  • Throughput
  • Turnaround time
  • Response time
  • waiting time

18. Several scheduling algorithms process?

19. What is the operating system on the process is preempted, and non-preemptive?

20. For the CPU burst process, CPU is often not easy to know exactly how long that process about running end, by the previous two cycles, when the entire process with estimates.

21. What HRRN process scheduling algorithm?

22. The Round Robin algorithm?

23. As indicated above, a single process scheduling algorithms often fail to take into account the process average turnaround time, average response time, the operating system how to balance these algorithms do?

24. In the process of scheduling algorithm, what is multilevel feedback queue?

25. What is the real-time system, real-time systems What are the characteristics, which scheduling algorithm?

26. The inter-process and switching threads within a process of switching is controlled by the kernel of it?

27. There must be a deadlock between the resources of the ring, but the ring is not necessarily a deadlock, the cycle will not ring owned deadlock it?
Here Insert Picture Description

27.
As shown, each resource class if only one instance of each, i.e. a resource, a deadlock occurs inevitably
Here Insert Picture Description

28. The deadlock four necessary conditions?

28.

  • Exclusive
  • Hold and continue to wait
  • Inalienable
  • Circular wait

29. The operating system for the deadlock attitude and approach:
Here Insert Picture Description
Because the operating system processing overhead deadlock too, need to make a lot of constraints to deal with this problem, it is generally issue written procedures should be noted, not by the operating system is complete.

30. The deadlock prevention, deadlock avoidance, deadlock and resolve the deadlock strength is decreasing, in what ways are?

30.

Deadlock prevention
strength of deadlock prevention is the largest, its purpose is absolutely not a deadlock, the core is to solve the four necessary conditions for deadlock

  • ------ Let mutually exclusive mutually exclusive resource becomes not mutually exclusive, this is relatively small.
  • -------- resource requests and to keep the process can make a one-time access to all of its resources, but is inefficient, prone to the process of starvation.
  • ------ deprived of the inalienable becomes available (to kill the process).
  • ------ waiting for the order cycle set of resources, in accordance with specific sequencing process, commonly found in embedded systems, because such systems are generally not a lot of resources.

Deadlock avoidance
deadlock avoidance of the core : ensure that the system will never enter an unsafe state:
well-known algorithms: banker's algorithm
Here Insert Picture Description
can not completely eliminate the deadlock, mainly resource information system for process applications, perform the check , to determine whether it would be deadlock, if generated, corresponding resource is not administered.
Mainly due to:

  • 预先声明进程所需要的资源最大数,进行限定分配
  • 动态检查资源分配情况,确保没有环形等待。
    PS:环形等待状态并不意味着死锁,但这是一种不安全的状态。

Here Insert Picture Description
Here Insert Picture Description

31. 什么是管程,管程有哪些特点?

31.
管程是操作系统为进程并发管理所定义的一个数据结构,这个数据结构包含了对进程的操作。
管程的一些特性:

  • 模块化:管程作为一个数据结构,可以作为程序单独编译。
  • 封装性:具体内部的函数可以不可见,但提供接口外部供调用
  • 抽象的数据结构:里面不仅有数据,还有对数据的操作。
  • 互斥:每次只允许一个进程在管程中进行。

答案

1.

  • 最优页面调度算法
  • 最近最少使用页面调度算法(LRU)
  • 时钟页面调度算法(Clock)
  • 二次算法(改进时钟算法)
  • 还有个奇怪的算法

2.
PCB控制块,是操作系统控制进程运行所用的信息集合。
当进程被创建时,一个PCB块页随之产生,da那个进程终止时,回收其PCB块。
一个进程对应一个单独的PCB控制块,所以PCB块是进城的唯一识别标识。

3.
PCB是一个进程存在的标识,所以其包括的内容有三类:

  • 进程的标识信息,相当于身份证号,包括进程的标识,其父进程的标识,用户标识等。
  • 进程的状态信息保存区,用来保存进程的运行现场。比如各种寄存器和栈指针等。
  • 进程的控制信息。比如状态信息,进程间通信信息,所用资源等。

4.
分别是:创建、运行、等待(堵塞)、唤起、结束。

5.
进程创建的三种情况:

  • 系统初始化创建
  • 用户请求创建新进程
  • 通过父进程创建,即正在执行的进程执行了创建新进程的系统调用。

6.
进程阻塞的三种情况:

  • 请求并等待CPU的服务
  • 等待数据资源
  • 启动某种操作,无法马上完成

一般理解是进程自己阻塞了自己,因为只有进程自身才知道自己何时要等待某种事件的发生,即进入等待状态。

7.

  • 等待的事件已下达,比如请求的CPU指令已下达
  • 需要的资源已经满足

当进程被唤醒时,将该进程的PCB插入到就绪队列中。

8.
就绪、等待和运行状态。
状态与生命期不一样,线程的五个状态是,创建,就绪,等待,运行和死亡。
Here Insert Picture Description
时间片用完时,运行态转为就绪态,等待事件时,转入堵塞态。
五种基本状态如图:
Here Insert Picture Description

9.
挂起,顾名思义,就是挂出去,这里是指从内存挂到外存中去,基于需存的概念,当程序暂时不用时,可将进程挂起,放到磁盘上。
进程挂起分为就绪到就绪挂起、阻塞到阻塞挂起和运行到就绪挂起。

Here Insert Picture Description
Here Insert Picture Description
其中优先级的关系是,阻塞转为阻塞挂起>就绪专为就绪挂起>运行转为就绪挂起,但最优先考虑的还是进程本身的优先级,优先级高的自然先处理他的状态,不管是就绪、等待还是运行,都先考虑它。
如果要把阻塞挂起重新变为运行状态,需要把它变为就绪挂起,再变为就绪,再变为运行。

注意:阻塞挂起状态可以变为就绪挂起状态,如果其优先级高,也可以从外存写入内存,变为阻塞状态。

10.
OS通过PCB来控制和管理进程,进程有不同的状态,不同的状态下,各有一个队列。Here Insert Picture Description
严格意义上讲,不只是一个队列,如下图:
Here Insert Picture Description

11.
对于以下问题:
Here Insert Picture Description
如果是这样的程序,在解压的时候,就没有读取和播放,设备利用率很低。

Here Insert Picture Description
如何实现并发和充分利用流水线操作,需要引入线程的概念,每一个线程单独执行任务。

12.
进程可以从两个方面来理解

  • 资源平台
  • 可执行的代码——也就是线程

线程是进程中的一条执行流程,线程可以并发,而且线程具有相同的存储空间。
线程也有对应的线程控制块TCB(Tread Control Block)Here Insert Picture Description

14.
切换线程快,因为线程都在同一个存储空间里,不需要切换页表,而不同进程的存储空间不同,需要切换页表,花费更多时间。

15.

  • 用户线程:操作系统看不见(操作不了)的线程。
  • 内核线程:操作系统看得见的线程。(TCB块放在内核中)
  • 轻量级进程:目前Solaris和Linux操作系统采取的方式,是内核支持的用户线程,一个进程可以有一个或多个轻量级进程组成,每个轻量级进程由一个单独的内核线程来支持。

现在的Windows系统主要采取内核线程的实现方式,来实现线程的创建、终止、管理和调度等,缺点是切换线程、终止线程的开销要稍微大一点。

用户线程的优缺点
优点:快,因为无需在内核中进行
缺点:

  • 当线程阻塞时,用户线程对应的进程也会堵塞,因为操作系统无法中断该线程,让其他线程继续运行。
  • 操作系统无法控制线程,只能等线程主动交出CPU使用权后,该进程里的其他线程才可以使用对应的资源。
  • 操作系统的时间片是按照进程分的,所以具体到线程的时间片会比较少,速度可能会比较慢。(而内核线程的时间片是按照线程分的,时间更多)

内核线程的优缺点
优点:时间片多,由操作系统直接操作,可停止线程,帮助协调使用CPU的资源。
缺点:开销大,每一次线程的切换都对应了从内核态到用户态的切换。(而用户线程则一直在用户态实现)

16.
因为操作系统只能处理父进程的资源回收,而子进程的资源回收需要父进程完成。所以需要用wait函数等到子进程的exit函数返回对应的值后,执行其资源回收。

17.

Here Insert Picture Description
一个良好的操作系统进程调度算法希望实现:
Here Insert Picture Description

Here Insert Picture Description

18.
Here Insert Picture Description

19.
当一个进程进行到一半,能够被其他进程打断抢占资源的时候,是抢占的。比如一个进程共用时9,已经用了2,但是来了一个新的进程,用时是5,那么可抢占的情况下,该进程会从运行态转为就绪态,换新的进程进行。
这种进程调度算法叫SRT:Shortest Remain-Time. 最短剩余时间算法,是SPN的变种
最短作业优先算法的平均周转时间是最小的:
Here Insert Picture Description

算法的缺点:
Here Insert Picture Description

20.
具体如下:
Here Insert Picture Description

21.
不仅考虑进程执行的时间,还考虑了响应的时间
Here Insert Picture Description

22.
轮训算法,也是时间片算法,就是给每个进程同样的时间片,比较公平,但是平均进程等待时间较久,而且切换上下文需要开销。
所以时间片的设置要合理,一般经验来说,早期Linux时间片为0.01秒,后来随着性能提升,变为了0.001秒。
Here Insert Picture Description

23.
Very simple, the operating system uses a different algorithm scheduling of the different characteristics of the process have learned FCFS, RR, SPN, HRRN algorithm
can process the ready state is divided into different queues:
high priority for, because very important, you can use the RR algorithm
low priority, not very important, you can take a batch of similar algorithm, first come, first serve, FCFS, simple and practical.

Here Insert Picture Description

24. A
multi-level feedback queue scheduling algorithm is a process scheduling algorithm is an algorithm for both short operating priority and high priority process priority obtained in response, characterized in that the different priorities of the processes corresponding to different time quantum , did not complete the process within the time quantum, its priority will be reduced,
Here Insert Picture Description

Process scheduling algorithm summarized:
Here Insert Picture Description

25. The
Realtime real-time systems, generally refers to a system of machine tools and other equipment, which is characterized by an important requirement of time, that is the importance of time is likely to be higher than the performance.

  • Hard real-time systems: for example, the machine must be turned off point, otherwise it will cause casualties
  • Soft real-time systems: such as watching video analysis, can be snapped, but the best

26. The
process of switching in two steps:
1. Change directory to use the new page address space
2. Switch hardware and kernel stack context
for linux, the biggest difference is that thread and process address space for a thread switch, step 1 It is not required to do, and the second is the process thread switching are done.

Guess you like

Origin blog.csdn.net/alexhu2010q/article/details/90545663