Deadlock in Operating System | GeeksforGeeks GeeksforGeeks https://www.youtube.com/watch?v=onkWXaXAgbY Transkript (automatisch erstellt) 0:06 Hello and welcome to Geeks for Geeks. In this video, we are going to understand a very important concept of deadlock in operating systems in a simple manner 0:15 with the help of some real-life examples. So, let us understand deadlock by a real-life example. You can't get a job without experience and experience 0:23 can only come when you do some job. So, here we end up in a deadlock. Let's see a formal definition of deadlock. So, deadlock is a situation 0:32 where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. 0:41 Let us understand it with the help of an example. So, in this example, process one is waiting for resource Y but it is assigned to process two. 0:52 Process two is not getting completed because it requires resource X which is assigned to process one ending up in a deadlock situation. Let's understand 1:02 deadlock with one more real-life example of a wrongly managed school. The school never performs good in board exams. Almost all the students get failed. When 1:12 the principal is asked why, his straightforward answer is that teachers doesn't teach well. When the teachers were asked about why the 1:20 students were getting failed, they said that they were not given their wages. Then again, when the principal was asked why they are not giving the wages, he 1:28 replies that parents don't want to pay the fees and he does not have the funds to give them. Pay to the teachers. 1:35 The parents give the reason that school does not provide enough facilities but obviously principal cannot provide facilities unless the fees is paid 1:44 which is depicted in this diagram and parents are not ready to pay the fees until facilities are enhanced in the school. 1:51 So, here we end up in a deadlock situation and there's not much we can do for the school. In the previous example, we saw a 1:58 deadlock between only two processes, namely school and parents. But a real operating system deadlock can be complex, and it usually involves 2:07 multiple processes and resources. So, now we are going to study four necessary conditions for a deadlock to 2:15 happen. So, they are mutual exclusion, hold and wait, no preemption, and circular wait. Let's see them all one by 2:25 one. So, let's understand mutual exclusion. If some resources are non-shareable, which means that only a single process 2:32 can use it. For example, here process one can use resource one, and no other process can use resource one. If this is not the case, then process cannot be 2:41 stopped from using the resource when they require it. For example, full-screen processes in our computer cannot be used by two apps 2:48 simultaneously. So, let's understand hold and wait now. If a process holds some resource and waits for some other resource, then the 2:57 hold and wait is occurred. If this is not the case, then the cycle of deadlock, which we saw in the first diagram, will not get completed, and no 3:05 deadlock will occur. The above school example is a classic example of hold and wait. As the school holds the facilities, 3:14 and parents hold the resources. School needs the resources, and parent need the facilities. Hence, creating a hold and wait 3:23 situation. Now, let's understand the third condition of no preemption. A resource cannot be taken from a 3:30 process unless the process releases the resource. If preemption was allowed, deadlock would never occur because then there 3:40 would have been no process able to hold a resource for long amount of time. For example, if your speaker is running an audio and after some time you click 3:49 on some another audio, it starts playing it. But in case if no preemption was allowed, we would have to wait for the first audio to end. It was on an 3:57 infinite loop. We will end up in a deadlock. So, let's understand the last condition, circular wait. 4:03 A set of processes are waiting for each other in a circular form, then circular wait happens. For example, if you extend the first 4:10 example to multiple processes and resources waiting for each other's held resources in a circular fashion, we will end up in 4:17 a circular wait condition. So, hope you understood the concept of deadlock in operating system. Please don't forget to subscribe to the GeeksforGeeks YouTube 4:24 channel and click on the bell icon.