Safety Algorithm
Safety Algorithm
A safe state is said to be a state from which the system can execute some sequence of processes
without deadlock. A system is said to be safe if all its processes can be executed safely in some
sequence.
It is a safety algorithm used to check whether or not a system is in a safe state or follows the safe
sequence in a banker's algorithm:
1. There are two vectors, Wok and Finish, of length m and n in a safety algorithm.
2.
3. Initialization:
4. Work: Initialize work = Available, where Available is the array that stores the number of
available instances for each resource type.
5. Finish: Initialize the Finish array for each process such that Finish[i] = false; for I = 0, 1, 2, 3,
4… n - 1., indicating that no processes have finished at the start.
6.
7. 2. Check the availability status for each type of resource [i], such as:
8.
9. Need[i] <= Work
10. Finish[i] == false
11. If the i does not exist, go to step 4.
12.
13. 3. If a process i satisfies the conditions in step 2, simulate the allocation by updating the
Work vector:
14.
15. WorkWork = Work +Allocation(i) // to get new resource allocation
16. This adds the resources currently allocated to process I back to the Work vector, stimulating
the release of resources after the process has finished.
17.
18. Finish[i] = true
19. Go to step 2 to check the status of resource availability for the next process.
20.
21. 4. If Finish[i] == true, it means that the system is safe for all processes.
22.