Deadlock prevention means that what things (steps) we need to do to avoid deadlock condition. There are four conditions which causes a deadlock. If we handle these situations or if we get solution to resolve all these conditions (Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait) then we can prevent the occurrence of a deadlock.
* Mutual Exclusion: This condition occurs when multiple processes tries to access a non sharable resource.
For example only one user can use a printer at a time and if more than one user will try access it then deadlock may occur. But on the other hand if many users are accessing a read-only file at a time, then they can access it without generating deadlock condition because read-only file is a sharable resource.
* Hold and Wait: We can avoid this condition by using a suitable method. As if we make it possible that a process cannot access two resources at a time then we can avoid this condition.
* No Preemption: A resource will not be immediately available to a process if that process already hold a resource.
Similarly we can check whether a resource is available and if it is available then we can allocate it to that process.
* Circular Wait: We can use a method to avoid this condition. In this method, we assign a number to resources as well as processes. For example, if there are ten processes in waiting queue which want to hold resource number 7 then the process with the integer number 1 can use that because it was the first process that wanted to access resource number 7 and was entered in queue.
* Mutual Exclusion: This condition occurs when multiple processes tries to access a non sharable resource.
For example only one user can use a printer at a time and if more than one user will try access it then deadlock may occur. But on the other hand if many users are accessing a read-only file at a time, then they can access it without generating deadlock condition because read-only file is a sharable resource.
* Hold and Wait: We can avoid this condition by using a suitable method. As if we make it possible that a process cannot access two resources at a time then we can avoid this condition.
* No Preemption: A resource will not be immediately available to a process if that process already hold a resource.
Similarly we can check whether a resource is available and if it is available then we can allocate it to that process.
* Circular Wait: We can use a method to avoid this condition. In this method, we assign a number to resources as well as processes. For example, if there are ten processes in waiting queue which want to hold resource number 7 then the process with the integer number 1 can use that because it was the first process that wanted to access resource number 7 and was entered in queue.