目录
2. 考虑一个由m个相同类型的资源组成的系统,由n个进程共享。一个进程一次只能请求或释放一个资源。当满足以下两个条件时,表明系统无死锁:
5. 考虑以下系统快照:(12分)最大可用分配使用银行家算法回答以下问题:
c.如果进程P1的请求到达(0,4,2,0),该请求是否可以立即被批准?
1 What’ s deadlock? What's the prerequisite of deadlock?
1. 死锁是什么?死锁的前提是什么?
ln an operating system. a deadlock occurs when a process or thread enters awaiting state because a requested system resource is held by another waiting process. which in turn is waiting for another resource held by another waiting process. If a process is unable to change its state indefinitely because the resources requested by it are being used by another waiting process, then the system is said lo be in a deadlock.
在操作系统中。死锁发生在进程或线程进入等待状态时,因为请求的系统资源由另一个等待进程持有。而它又在等待另一个等待进程所持有的另一个资源。如果一个进程无法无限期地改变其状态,因为它请求的资源正在被另一个等待的进程使用,那么系统就处于死锁状态。
2 Consider a system consisting of m resources of the same type being shared by n processes. A process can request or release only one resource at a time. Show that the system is deadlock free if the following two conditions hold:
a. The maximum need of each process is between one resource and m resources.
b. The sum of all maximum needs is less than m + n.
2. 考虑一个由m个相同类型的资源组成的系统,由n个进程共享。一个进程一次只能请求或释放一个资源。当满足以下两个条件时,表明系统无死锁:
a.每个进程的最大资源需求在1到m个资源之间。
b.所有最大需求之和小于m + n。
Answer :
If the system exit dcadlock.it must satisfy that
Because every processes need at least one resources, our assumption is wrong.
答:如果系统退出deadlock。
因为每个进程至少需要一个资源,所以我们的假设是错误的。
当系统满足这两个条件时,就可以保证系统不会出现死锁。条件a保证了每个进程对资源的需求量在可控范围内,不会出现某个进程对资源需求过多而导致系统无法满足需求的情况。条件b保证了总的资源需求量不会超过系统中可用的资源数量,也就不会出现系统无法满足所有进程的资源需求的情况。如果一个系统满足这两个条件,就可以保证在正常运行的情况下不会出现死锁。
3. Describe the actions taken by a kernel to context switch between processes.
3. 描述在进程之间从内核到上下文切换所采取的操作。
Answer: In general, the operating system must save the state of the currently running process and restore the state of the process scheduled to be run next. Saving the state of a process typically includes the values of all the CPU registers in addition to memory allocation. Context switches must also perform many architecture-specific operations, including flushing data and instruction caches.
答:一般情况下,操作系统必须保存当前运行进程的状态,并恢复计划下次运行的进程的状态。
保存进程的状态通常包括所有CPU寄存器的值以及内存分配。
上下文交换机还必须执行许多特定于体系结构的操作,包括刷新数据和指令缓存。
当进程从内核切换到用户模式时,系统会采取一些操作来完成进程间的上下文切换。这些操作包括:
- 保存当前进程的上下文信息,包括它的状态、寄存器和内存信息等。这些信息用于在后续的上下文切换中恢复进程的状态。
- 将当前进程的状态设置为“等待中”,表示进程正在等待系统资源或其他操作完成。
- 将处理器的控制权交给下一个准备运行的进程。这个进程可能是新建的进程,也可能是之前被暂停的
4. Consider the following segment table: What are the physical addresses for the following logical addresses?
4. 考虑下面的段表: 以下逻辑地址的物理地址是什么?
5. consider the following snapshot of a system: (12pts)Allocation Max Available Answer the following questions using the banker 's algorithm:
5. 考虑以下系统快照:(12分)最大可用分配使用银行家算法回答以下问题:
a. What is the content of the matrix Need?
a.需要矩阵的内容是什么?
The values of need for processes P0 through P4 respectively are (0.0.0.0).(0.7.5.0). ( 1.0.0.2).(0.0.2.0).and (0.6.-4.2).
过程P0到P4的需求值分别为(0.0.0.0).(0.7.5.0),(1.0.0.2)。(0.0.2.0)和(0.6.-4.2)。
b. ls the system in a safe state?
B.系统是否处于安全状态?
Yes. With Available being equal to ( 1.5.2. 0).either process PO) or P3 could run. Once process P3 runs, it releases its resources which allow all other existing processes to run.
是的。Available等于(1.5.2.0).任一进程PO)或P3都可以运行。一旦进程P3运行,它将释放其资源,从而允许所有其他现有进程运行。
c. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately?
c.如果进程P1的请求到达(0,4,2,0),该请求是否可以立即被批准?
Yes it can. This results in the value of Available being ( 1. 1.0.0). One ordering of processes that can finish is P0,P2,P3,P1,P4
是的,它可以。这将导致Available的值为(1.1.0.0)。可以完成的进程的顺序是P0,P2,P3,P1,P4
如果可以找到一种方案,使得每个进程都能按照其需求获得所需的资源,那么系统就处于安全状态。否则,如果存在进程无法获得所需的资源,那么系统就处于不安全状态。