操作系统练习题(全)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

答案仅供参考

1.How does the distinction between kernel mode and user mode function as a rudimentary form of protection (security) system? (内核态和用户态作为保护系统有什么区别)

答:内核态和用户态的区别有以下方式,某些指令只有当CPU处于内核态时才可以执行。同样地,某些硬件设备只有当程序在内核态下执行才能够被访问。只有在CPU处于内核态时,才能够控制中断。因此,CPU处于用户态时的能力有限,从而强制保护关键的资源。

2. Which of the following instructions should be privileged? (下列哪个指令是受保护的)

a. Set value of timer.设置计时器的值

b. Read the clock.读时钟

c. Clear memory.清除内存

d. Issue a trap instruction.解决一个陷阱指令

e. Turn off interrupts.关中断

f. Modify entries in device-status table.修改设备状态表中的条目

g. Switch from user to kernel mode.从用户态转到内核态

h. Access I/O device.访问I/O设备

答:受保护的:a、c、e、f、h,剩下的可以在用户态执行。

3.Why should an application programmer prefer programming according to an API rather than invoking actual system call? (为什么应用程序设计者更喜欢根据API编程)

答:使用API编程的一个好处是程序的可移植性:程序员用API设计的程序可以在任何支持相同API的系统上编译和运行,并且,对于一个应用程序来说,实际系统调用比API更加复杂和困难,总之,API调用和与其相关的内核中的系统调用有着很强的相关性。

4. What resources are used when a thread is created? How do they differ from those used when a process is created? (当线程创建时需要哪些资源,当进程创建时又需要哪些)

答:因为一个线程小于一个进程,因此,创建线程所用的资源一般比创建进程所用的资源少。创建一个进程需要分配进程控制块(PCB),一个相当大的数据结构,PCB包括了一个内存映射,打开文件的目录和外界变量。分配和管理内存映射通常是最费时的活动。创建一个用户或内核线程包括分配一个小的数据结构来控制寄存器的设置,堆栈和优先级。

5. Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. In answering the questions, use preemptive scheduling and base all decisions on the information you have at the time the decision must be made?(考点:调度算法)

Process Arrival Time Burst Time

P1 0 8

P2 1 4

P3 2 9

P4 3 5

What is the average turnaround time for these processes with the preemptive SJF scheduling algorithm(抢占、最短作业优先调度算法)?

答:甘特图:

0 1 5 10 17 26

平均等待时间=((10-1)+ 0 +(17-2)+(5-3))/4=6.5ms

6. Consider the following snapshot(快照)of a system:(考察银行家算法)

a. What OS the content of the matrix need?(求need矩阵的内容Need=Max-Allocation)答:

b. Is the system in a safe state?(系统是否处于安全状态)

答:

因此,系统存在安全序列,所以,系统安全

7. The necessary conditions for arising deadlock in a system are发生死锁的必要条件是(互斥)、(循环等待)、(请求与保持)、(非剥夺分配)。

8. The synchronization(同步)Problems:

a. readers and writers problems(读者写者问题)

一个缓冲区,读与读不互斥,读与写互斥,写与写互斥,写与读互斥,读优先

信号量mutex=1(readcount)

信号量wrt=1(写和读)

信号量readcount=0(记录读个数)

读:写:

wait(mutex); wait(wrt);

readcount++; //writing

if(readcount= =1) signal(wrt);

wait(wrt);

signal(mutex);

//reading

wait(mutex);

readcount--;

if(readcount= =0)

signal(wrt);

signal(mutex);

相关文档
最新文档