-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.c
81 lines (74 loc) · 1.86 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Function which prints the main menu.
void menu()
{
system("clear");
printf("--------------------------Banker's Alogrithm--------------------------\n");
printf("1. Check Status\n");
printf("2. Allocate Resources\n");
printf("3. Terminate a process\n");
printf("4. See Safe Sequence\n");
printf("5. Exit\n");
printf("Enter one of the option = ");
}
//Shows the current state of the simulation.
void status_module()
{
printf("\n\n\n\tAvailable system resources:\n\t");
for(int i=0;i<maxr;i++)
printf("R%d ",i);
printf("\nFree\t");
for(int i=0;i<maxr;i++)
printf("%d ",available[i]);
//Currently allocated resources
printf("\n\n\n\tProcesses (currently allocated resources):\n\t");
for(int i=0;i<maxr;i++)
printf("R%d ",i);
for(int i=0;i<maxn;i++)
{
printf("\nP%d\t",i);
for(int j=0;j<maxr;j++)
printf("%d ",allocated[i][j]);
if(state[i]==-1)
printf("--Terminated");
}
//Currently allocated resources
printf("\n\n\n\tProcesses (maximum resources):\n\t");
for(int i=0;i<maxr;i++)
printf("R%d ",i);
for(int i=0;i<maxn;i++)
{
printf("\nP%d\t",i);
for(int j=0;j<maxr;j++)
printf("%d ",max[i][j]);
if(state[i]==-1)
printf("--Terminated");
}
//Resources needed to complete execution by each process
printf("\n\n\n\tNeed (maximum resources - currently allocated resources):\n\t");
for(int i=0;i<maxr;i++)
printf("R%d ",i);
for(int i=0;i<maxn;i++)
{
printf("\nP%d\t",i);
for(int j=0;j<maxr;j++)
printf("%d ",need[i][j]);
if(state[i]==-1)
printf("--Terminated");
}
}
//For Showing status.
void show_status()
{
system("clear");
//Total system resources
printf("\tTotal system resources:\n\t");
for(int i=0;i<maxr;i++)
printf("R%d ",i);
printf("\nFree\t");
for(int i=0;i<maxr;i++)
printf("%d ",total_resources[i]);
status_module();
//Available system resources
printf("\nPress enter to go back......");
return;
}