从零开始的操作系统:处理机的调度和死锁

关于这个理论的问题,其实重点有三。

第一在于死锁,死锁的原因,死锁的数值计算比如所有M份资源N个进程,每个进程最多申请m份资源然后计算这三个数值的关系。

第二以及还有处理机调度的各种算法的核心优先级,就是每种算法安装哪个指标来调度的,比如说先来先服务(FCFS算法)就是安装进程等待时间调度的,等待时间越长则优先级越高。以及这种算法它在什么情况下用时最好的,比如说在实时系统中用哪个算法最好。

第三 银行家算法和消费者模式是怎么运转的。

最后会结合实际,会拿MINIX 3的来说明一下。MINIX 3就是当年LINUS大神受其启发写出LINUX的启蒙版操作系统。

会从三个问题来结合MINIX 3说

第一 MINIX 3的内部结构是怎么样的。

 MINIX 3有四层结构。只有底层的进程才有权力使用(内核模式)指令。

第一层:

 (kernel):在底层的内核就是调度各种各种进程并且管理它们的状态转换。比如让一个进程从准备,到运行。内核同时也控制进程间的信息流动。进程间的信息流动需要检查合法边界,锁定发送源和接收源的物理地址。然后从发送端复制字节到接收端。内核的一部分还可以访问I/O 端口和中断,这部分功能用到内核模式的调用。而不是用户进程的一般调用。

(Clock task):时钟任务,是一个I/O驱动程序。它和硬件交互发送给硬件时间信号。但是用户是不可访问它的。

(system task):系统任务,则是负责在不同地址空间复制字节,读写I/O端口。

虽然 时钟任务和系统任务都是在内核的地址空间实现的,但是它们却和内核不是同一部分。它们是不同于内核的独立的一部分!

第二,三,四层的共性:

The three layers above the kernel could be considered to be a single layer because the kernel fundamentally treats them all of them the same way. Each one is limited to user mode instructions, and each is scheduled to run by the kernel. None of them can access I/O ports directly. Furthermore, none of them can access memory outside the segments allotted to it.

 这三个层都在内核之上,然后它们可被视作一个层。因为内核对待它们的方法都一样。每一个都被限制在用户模式中。而且只能被内核调度。

However, processes potentially have special privileges (such as the ability to make kernel calls). This is the real difference between processes in layers 2, 3, and 4. The processes in layer 2 have the most privileges, those in layer 3 have some privileges, and those in layer 4 have no special privileges. For example, processes in layer 2, called device drivers, are allowed to request that the system task read data from or write data to I/O ports on their behalf. A driver is needed for each device type, including disks, printers, terminals, and network interfaces. If other I/O devices are present, a driver is needed for each one of those, as well. Device drivers may also make other kernel calls, such as requesting that newly-read data be copied to the address space of a different process.

第三层:

The third layer contains servers, processes that provide useful services to the user processes. Two servers are essential. The process manager (PM) carries out all the MINIX 3 system calls that involve starting or stopping process execution, such as fork, exec, and exit, as well as system calls related to signals, such as alarm and kill, which can alter the execution state of a process. The process manager also is responsible for managing memory, for instance, with the brk system call. The file system (FS) carries out all the file system calls, such as read, mount, and chdir.

In addition to the PM and FS, other servers exist in layer 3. They perform
functions that are specific to MINIX 3. It is safe to say that the functionality
of the process manager and the file system will be found in any operating
system. The information server (IS) handles jobs such as providing debugging and
status information about other drivers and servers, something that is more
necessary in a system like MINIX 3, designed for experimentation, than would be
the case for a commercial operating system which users cannot alter. The reincarnation server (RS) starts, and if necessary restarts, device drivers
that are not loaded into memory at the same time as the kernel. In particular,
if a driver fails during operation, the reincarnation server detects this
failure, kills the driver if it is not already dead, and starts a fresh copy of
the driver, making the system highly fault tolerant. This functionality is
absent from most operating systems. On a networked system the optional network server (inet) is also in level 3. Servers cannot do I/O
directly, but they can communicate with drivers to request I/O. Servers can also
communicate with the kernel via the system task.

第二 MINXI3 的进程树是如何初始化的。

第三 MINIX3 的进程是如何调度的。

原文地址:https://www.cnblogs.com/zzzPark/p/6813824.html