第一题
Q: 什么原因推动了操作系统从批处理发展到多道程序,进而发展到分时系统?
A: 当处理程序数量变多时,批处理系统的局限性愈加明显。采用多道程序九二一同时容纳多个作业,形成一个自动转接的连续的作业流。
多道程序不能进行任务间的切换,也不能提供交互作用力。而分时系统可以解决这些问题问题以便于多用户对一个终端同时进行操作。分时系统的作用原理是将CPU的处理时间分割为多个时间片,将时间片分给多个程序,使得在用户看来达到了多个程序同时运行的效果。分时系统解决了这样一些问题:
- 批处理系统一次执行一个程序,I/O过程CPU空转;
- 为进一步提高CPU利用率,支持多用户、多进程。
第二题
Q: 什么是陷阱?与中断的区别是什么?什么是系统调用?
A: PPT中给的参考文档有这样一段话:
Although the terms trap and exception are often used synonymously, we will use the
term trap to denote a programmer initiated and expected transfer of control to a special
handler routine. In many respects, a trap is nothing more than a specialized subroutine
call. Many texts refer to traps as software interrupts. The 80x86 int instruction is the main
vehicle for executing a trap. Note that traps are usually unconditional; that is, when you
execute an int instruction, control always transfers to the procedure associated with the
trap. Since traps execute via an explicit instruction, it is easy to determine exactly which
instructions in a program will invoke a trap handling routine.
从这段话我们可以知道,陷阱是编程者预先指定好的、向一段特殊处理程序跳转的代码片段。
陷阱可以被称为“软件中断”。陷阱和中断的区别在于中断来自于I/O设备,是异步步异常;而陷阱是程序内部有意设置的,是同步异常。
系统调用也可视作同步异常,或者trap. 系统调用在内核态进行,是操作系统的功能。
第三题
Q: 你能否从这些复杂的启动过程中总结出一个最简单的启动需要哪些功能?
A: 其核心就是要实现逐步释放内存可用空间的功能。大致包括以下功能:
- 寄存器复位到固定值
- 硬件初始化,为下一阶段初始化RAM,并且装入下一阶段到RAM;设置堆栈到并跳转到下一个阶段入口
- 初始化本阶段所需硬件设备,载入内核和根文件系统,为内核设置启动参数,跳转到内核入口。
- 完成启动。