没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
Operating System Review Problems
1. What is a process? Please draw a process state transition diagram with
nine states in Unix SVR4?
•
A program in execution
(一个正在执行的程序)
2. Illustrated some scenarios where process switch occur?
①
Clock interrupt
(时钟中断)
Process has executed for the maximum allowable time slice
②
I/O interrupt
(
I/O
中断)
③
Memory fault
(内存失效)
Memory address is in virtual memory so it must be brought into main memory
④
Trap
(陷阱)
Error or exception occurred
May cause process to be moved to edit state
⑤
Supervisor call
(系统调用)
Such as file open
3. Illustrated some scenarios where process should blocked?
①
The system fails to apply for resources.
(向系统申请资源时失败)
For example, if A process (A) requests A printer but the printer is in use by another process
(B), process A is blocked.
②
Waiting for an operation.
(等待某种操作)
Process A starts an I/O device. If process A can start an I/O device only after the specified
I/O task is complete, process A automatically blocks after starting the I/O device.
③
New data has not arrived.
(新数据尚未到达)
For cooperative processes, if a process needs to obtain data from another process before it
can process the data, it will enter the blocking state as long as the data has not arrived.
④
Waiting for a new task to arrive.
(等待新任务的到达)
Each time the process completes its task
4. Suppose there are three processes running in an operating system with
multithreading as following:
Process ID
Threads
A
T11, T12
B
T21, T22
C
T31, T32
If the multithreading is supported by user-level implementation(用户级)
and thread T11 is blocked, which thread may be scheduled to run next?
One of T21,T22,T31,T32
If the multithreading is supported by kernel-level implementation(内核级),
which thread may be scheduled to run next?
One of T12,T21,T22,T31,T32
原因:内核级的实现,
OS
才知道
A
中有
T12
5. What is race condition? Give a program implementation to demonstrate the
mutual exclusion enforced by Test and Set (or exchange) instruction or by
semaphore?
A race condition occurs when multiple processes or threads access shared resource so that the
final result depends on the order of execution of instructions in the multiple processes.
竞争条件是在多个进程或线程访问共享资源时,其最终结果依赖于多个进程的指令执行顺
序。
用信号量实现互斥:
semaphore mutex = 1;
void P(int i = 0)
{
while (true) {
semWait(mutex);
/*临界区critical section*/
semsignal(mutex);
/*其余部分remainder*/
}
}
void main()
{
parbegin(P(1), P(2)...P(n));
}
用 TS 实现互斥:
Lock DB 0
...
entercritical:
TS REG, Lock
CMP REG, 0
JNZ entercritical
...
enxitcritical:
MOV Lock, 0
用 exchange 实现互斥:
Lock DB 0
...
entercritical:
MOV reg, !=0
Xchg Lock,reg
CMP REG, 0
JNZ entercritical
...
enxitcritical:
MOV Lock, 0
Wait 用法:
wait(num),num 是⽬标参数,wait 的作⽤是使其(信
息量)减⼀。
如果信息量>=0,则该进程继续执⾏;否则该进程置为
等待状态,排⼊等待队列。
signal⽤法:
signal(num),num 是⽬标参数,signal 的作⽤是使其
(信息量)加⼀。
如果信息量>0,则该进程继续执⾏;否则释放队列中
第⼀个等待信号量的进程。
CMP 指令:进行比较两个操作数的大小
JNZ:依据 ZF 标志位(我经常叫做 零标志位,判断
是不是 0) 不为 0/不等于时跳转执行
MOV 指令:是数据传送指令,用于将一个数据从源地
址传送到目标地址(移动/赋值)
XCHG 指令:交换两个操作数内容
6. Consider the following program:
boolean blocked[2];
int turn;
void P(int id)
{
while (true) {
blocked[id] = true;
while (turn != id){
while (blocked[1-id]) /* do nothing */;
turn = id; //循环结束,则某一进程进入临界区
}
/* critical section */
blocked[id] = false;
/* remainder */
}
}
void main()
{
blocked[0] = false;
blocked[1] = false;
turn = 0;
parbegin(P(0), P(1));
}
This software segment is the solution to the mutual exclusion problem for two processes.
Find a counterexample(反例) that demonstrates that this solution is incorrect.
考虑进程 0 执行到 blocked[id] = true 这个语句是发生了进程切换,操作系统调度进程 1
运行。这种情况下会导致进程 0 和进程 1 同时进入临界区。
Consider that P(0) executed to blocked[id] = true, a process switch occurred. OS scheduled P(1)
to run. In this case, P(0) and P(1) enter the critical section at the same time.
Consider the case in which turn equals 0 and P(1) sets blocked[1] to true and then finds blocked[0]
set to false. P(0) will then set blocked[0] to true, find turn = 0, and enter its critical section. P(1)
will then assign 1 to turn and will also enter its critical section. The error was pointed out in
[RAYN86]
7. Give a solution to bounded producer-consumer problem with semaphore.
A Solution to the Bounded-Buffer Producer/Consumer Problem Using Semaphores
剩余15页未读,继续阅读
唐钰小宝lucky
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5