- 103
- 0
- 约6.02千字
- 约 8页
- 2017-03-28 发布于重庆
- 举报
OperatingSystemReviewProblems(答案)
Operating System Review ProblemsWhat is a process? Please draw a process state transition diagram with nine states in Unix SVR4?进程是一个正在执行的程序(a program in execution);九状态转换图如下所示: fork 返回用户模式 存储器空间足够 存储器空间不足 抢占 换出 返回 重新调度进程 换入 系统调用,中断 唤醒 唤醒 退出 睡眠中断,中断返回 换出Illustrated some scenarios(场景) where process switch(进程切换) occur?时钟中断②i/0中断③内存失效④陷阱⑤系统调用Suppose there are three processes running in an operating system with multithreading as following:Process IDThreadsAT11, T12BT21, T22CT31, T32If 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中有T124. What is race condition? 答:竞争条件是在当多个进程或线程访问共享资源时,其最终结果依赖于多个进程的指令执行顺序。 Give a program implementation to demonstrate(演示,展示) the mutual exclusion enforced by Test and Set (or exchange) instruction or by semaphore?用信号量实现互斥:semaphore mutex;mutex=1;…semwait(mutex);…Semsignal(mutex);…TS实现互斥:Lock DB 0…entercritical:TS reg,lock CMP reg,o JNZ entercritical …exitcritical:MOV lock,0exchange实现互斥:Lock DB 0…entercritical:MOV reg,!0Xchg lock,reg CMP reg,0 JNZ entercritical …exitcritical:MOV lock,05.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(){假设2个进程访问资源,我们对其行为纠错 blocked[0] = false; blocked[1] = false; turn = 0; parbegin(P(0), P(1));创建2个进程}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同时进入临界区。6.Give
原创力文档

文档评论(0)