lab Exp OS 6
lab Exp OS 6
Performed Date
Deadlock is a situation where in two or more competing actions are waiting f or the other to finish,
and thus neither ever does. When a new process enters a system, it must declare the Maximum
number of instances of each resource type it needed. This number may exceed the total number of
resources in the system. When the user request a set of resources, the system must determine
whether the allocation of each resources will leave the system in safe state. If it will the resources
are allocation; otherwise the process must wait until some other process release the resources.
Data structures:
n-Number of process,
m-number of resource types.
Available: Available[j]=k, k – instance of resource type Rj is available.
Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj Need: If Need[I, j]=k,
Pi may need k more instances of resource type Rj, Need[I, j]=Max[I, j]- Allocation[I, j];
Safety Algorithm
ALGORITHM:
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. or not if we allow the request.
10. stop the program.
11. end
Conclusion:
Program:
#include <stdio.h>
#include <string.h>
void main() {
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], total[10];
int i, j, k, n, m, count = 0, c = 0;
char finish[10]; // process executed or not
if(canExecute) {
printf("All resources can be allocated to process %d\n", i+1);
printf("Available resources before allocation: ");
for(k = 0; k < m; k++) {
printf("%d ", avail[k]);
}
printf("\n");
for(k = 0; k < m; k++) {
avail[k] += alloc[i][k];
}