Professional Documents
Culture Documents
A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause (including itself). Waiting for an event could be: waiting for access to a critical section waiting for a resource Note that it is usually a non-preemptable (resource). pre-emptable resources can be yanked away and given to another.
Deadlock Prevention
Difference from avoidance is that here, the system itself is build in such a way that there are no deadlocks. Make sure atleast one of the 4 deadlock conditions is never satisfied. This may however be even more conservative than deadlock avoidance strategy. Attacking Mutex condition o never grant exclusive access. but this may not be possible for several resources. Attacking preemption o not something you want to do. Attacking hold and wait condition o make a process hold at the most 1 resource at a time. o make all the requests at the beginning. All or nothing policy. If you feel, retry. eg. 2-phase locking Attacking circular wait o Order all the resources. o Make sure that the requests are issued in the correct order so that there are no cycles present in the resource graph. Resources numbered 1 ... n. Resources can be requested only in increasing order. ie. you cannot request a resource whose no is less than any you may be holding.
Deadlock Avoidance
Avoid actions that may lead to a deadlock. Think of it as a state machine moving from 1 state to another as each instruction is executed. Safe State Safe state is one where o o It is not a deadlocked state There is some sequence by which all requests can be satisfied.
To avoid deadlocks, we try to make only those transitions that will take you from one safe state to another. We avoid transitions to unsafe state (a state that is not deadlocked, and is not safe) eg. Total # of instances of resource = 12 (Max, Allocated, Still Needs) P0 (10, 5, 5) P1 (4, 2, 2) P2 (9, 2, 7) The sequence is a reducible sequence the first state is safe.
Free = 3
- Safe
What if P2 requests 1 more and is allocated 1 more instance? - results in Unsafe state So do not allow P2's request to be satisfied.
Done[i] = TRUE} } else if Done[i] = TRUE for all i then state is safe else state is unsafe }
Multiple resources of each type o o o o o o o o m resources, n processes Max resources in existence = [E1, E2, E3, .... Em] Current Allocation = C1-n,1-m Resources currently Available = [A1, A2, ... Am] Request matrix = R1-n,1-m Invariant = Sum(Cij) + Aj = Ej Define A <= B for 2 vectors, A and B, if Ai <= Bi for all i Overview of deadlock detection algorithm, Check R matrix, and find a row i such at Ri < A. If such a process is found, add Ci to A and remove process i from the system. Keep doing this till either you have removed all processes, or you cannot remove any other process. Whatever is remaining is deadlocked.
Basic idea, is that there is atleast 1 execution which will undeadlock the system
Recovery
o o through preemption rollback keep checkpointing periodically when a deadlock is detected, see which resource is needed. Take away the resource from the process currently having it. Later on, you can restart this process from a check pointed state where it may need to reacquire the resource. killing processes where possible, kill a process that can be rerun from the beginning without illeffects
System calls provide an interface between the process an the operating system. System calls allow user-level processes to request some services from the operating system which process itself is not allowed to do. In handling the trap, the operating system will enter in the kernel mode, where it has access to privileged instructions, and can perform the desired service on the behalf of user-level process. It is because of the critical nature of operations that the operating system itself does them every time they are needed. For example, for I/O a process involves a system call telling the operating system to read or write particular area and this request is satisfied by the operating system. System programs provide basic functioning to users so that they do not need to write their own environment for program development (editors, compilers) and program execution (shells). In some sense, they are bundles of useful system calls.