System Software Lab
System Software Lab
#include <stdio.h>
#include <stdlib.h>
struct process
} p[10];
void input()
int i, j, chk = 0;
scanf("%d", &np);
scanf("%d", &nr);
scanf("%d", &avail[i]);
scanf("%d", &p[i].alloc[j]);
scanf("%d", &p[i].max[j]);
chk = 1;
if (chk)
int safe()
int flag, sp = 0, i, j;
work[i] = avail[i];
p[i].finished = 0;
flag = 0;
if (p[i].finished)
continue;
int less = 1;
less = 0;
if (less)
p[i].finished = 1;
flag = 1;
sseq[sp++] = i;
if (!flag)
return 0;
printf("\n");
return 1;
void newReq()
scanf("%d", &pid);
scanf("%d", &req[j]);
chk1 = 1;
chk2 = 1;
if (chk1)
{
printf("Process Exceeds Max Need\n");
return;
if (chk2)
printf("Lack Of Resources\n");
return;
avail[j] -= req[j];
p[pid].alloc[j] += req[j];
p[pid].need[j] -= req[j];
if (!safe())
avail[j] += req[j];
p[pid].alloc[j] -= req[j];
p[pid].need[j] += req[j];
else
printf("Request Committed\n");
void display()
int i, j;
printf("P%d\t", i);
printf("\t");
printf("\t");
printf("\n");
printf("Available\n");
printf("\n");
void main1()
int ch;
for (;;)
scanf("%d", &ch);
switch (ch)
case 1:
input();
break;
case 2:
newReq();
break;
case 3:
safe();
break;
case 4:
display();
break;
case 5:
exit(0);
/*OUTPUT
Enter Choice : 1
332
010
200
302
211
002
753
322
902
222
433
Enter Choice : 4
Number of Process : 5
Number of Resources : 3
P0 7 5 3 0 1 0 7 4 3
P1 3 2 2 2 0 0 1 2 2
P2 9 0 2 3 0 2 6 0 0
P3 2 2 2 2 1 1 0 1 1
P4 4 3 3 0 0 2 4 3 1
Available
332
Enter Choice : 3
Safe Sequence
P1 P3 P4 P0 P2
Enter Choice : 2
Enter Process ID : 1
102
Safe Sequence
P1 P3 P4 P0 P2
Request Committed
Enter Choice : 4
Number of Process : 5
Number of Resources : 3
PID Max Allocated Need
P0 7 5 3 0 1 0 7 4 3
P1 3 2 2 3 0 2 0 2 0
P2 9 0 2 3 0 2 6 0 0
P3 2 2 2 2 1 1 0 1 1
P4 4 3 3 0 0 2 4 3 1
Available
230
Enter Choice : 2
Enter Process ID : 4
330
Lack Of Resources
Enter Choice : 5
*/