-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rohit Kumar
committed
Jul 13, 2021
1 parent
936ebfb
commit 6fff36d
Showing
20 changed files
with
322 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Program to Implement Shortest Job First (SJF) | ||
// Rohit Kumar | 1900320100131 | ||
#include<stdio.h> | ||
|
||
void main() | ||
{ | ||
// STDIN | ||
int n; | ||
printf("No of Process : "); | ||
scanf("%d",&n); | ||
int AT[n],BT[n],CT[n],WT[n],TAT[n]; | ||
printf("Enter the AT & BT of Process\n"); | ||
for(int i=0;i<n;i++) | ||
{ | ||
printf("P[%d]\t",i); | ||
scanf("%d%d",&AT[i],&BT[i]); | ||
} | ||
// PROCESSING | ||
float AvgWT = 0.0; | ||
float AvgTAT = 0.0; | ||
int flag[n]; | ||
//Initialize Flag of Every process to Zero | ||
for(int i=0;i<n;i++) | ||
flag[i]=0; | ||
|
||
int time=AT[0],min,k; | ||
for(int j=0;j<n;j++) | ||
{ | ||
min=100; | ||
k=0; | ||
//Loop to Find Less Burst Time Process by Checking Flag | ||
for(int i=0;i<n;i++) | ||
{ | ||
if(flag[i]==0) | ||
{ | ||
if(AT[i]<=time) | ||
{ | ||
if(BT[i]<min) | ||
{ | ||
min=BT[i]; | ||
k=i; | ||
} | ||
} | ||
} | ||
} | ||
CT[k]=min+time; | ||
time=time+min; | ||
flag[k]=1; | ||
WT[k]=CT[k]-(BT[k]+AT[k]); | ||
TAT[k]=CT[k]-AT[k]; | ||
AvgTAT += TAT[k]; | ||
AvgWT += WT[k]; | ||
} | ||
|
||
AvgWT = AvgWT/n; | ||
AvgTAT = AvgTAT/n; | ||
// STDOUT | ||
printf("\n\tAT\tBT\tWT\tTAT\n"); | ||
for(int i=0;i<n;i++) | ||
{ | ||
printf("P[%d]\t%d\t%d\t%d\t%d\n",i,AT[i],BT[i],WT[i],TAT[i]); | ||
|
||
} | ||
printf("\nAverage WT : %f Units\n",AvgWT); | ||
printf("Average TAT : %f Units",AvgTAT); | ||
} |
This file was deleted.
Oops, something went wrong.
92 changes: 46 additions & 46 deletions
92
...Allocation Scheme/Best Fit (Incomplete).c → 7.Memory Allocation/Best Fit (Incomplete).c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void BestFit(int size2[6],int process2[6]) | ||
{ | ||
int i,j,k,temp[6],min,temp1; | ||
printf("----Best Fit Memory Allocation Scheme---- \n\n"); | ||
for (i=0;i<5;i++) | ||
{ | ||
for(j=0;j<6;j++) | ||
{ | ||
temp[j] =size2[j]-process2[i]; | ||
} | ||
min= temp[0]; | ||
for (j=0;j<6;j++) | ||
{ | ||
if ((min>temp[j]) && (temp[j]>=0)) | ||
{ | ||
min=temp[j]; | ||
k= j; | ||
} | ||
} | ||
if ((process2[i]<=size2[k])&&(process2[i]!=0)) | ||
{ | ||
temp1 = size2[k]- process2[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process2[i],size2[k],temp1); | ||
size2[k]-=process2[i]; | ||
process2[i]=0; | ||
|
||
} | ||
} | ||
for(i=0;i<5;i++) | ||
{ | ||
if (process2[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process2[i]); | ||
} | ||
} | ||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
BestFit(size,process); | ||
return 0; | ||
} | ||
|
||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void BestFit(int size2[6],int process2[6]) | ||
{ | ||
int i,j,k,temp[6],min,temp1; | ||
printf("----Best Fit Memory Allocation Scheme---- \n\n"); | ||
for (i=0;i<5;i++) | ||
{ | ||
for(j=0;j<6;j++) | ||
{ | ||
temp[j] =size2[j]-process2[i]; | ||
} | ||
min= temp[0]; | ||
for (j=0;j<6;j++) | ||
{ | ||
if ((min>temp[j]) && (temp[j]>=0)) | ||
{ | ||
min=temp[j]; | ||
k= j; | ||
} | ||
} | ||
if ((process2[i]<=size2[k])&&(process2[i]!=0)) | ||
{ | ||
temp1 = size2[k]- process2[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process2[i],size2[k],temp1); | ||
size2[k]-=process2[i]; | ||
process2[i]=0; | ||
|
||
} | ||
} | ||
for(i=0;i<5;i++) | ||
{ | ||
if (process2[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process2[i]); | ||
} | ||
} | ||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
BestFit(size,process); | ||
return 0; | ||
} | ||
|
||
|
72 changes: 36 additions & 36 deletions
72
7.Memory Allocation Scheme/First Fit.C → 7.Memory Allocation/First Fit.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void FirstFit(int size1[6],int process1[6]) | ||
{ | ||
int i,j,temp; | ||
printf("----First Fit Memory Allocation Scheme---- \n\n"); | ||
for(i=0;i<5;i++) | ||
{ | ||
for(j=0;j<6;j++) | ||
{ | ||
if ((process1[i]<=size1[j])&&(process1[i]!=0)) | ||
{ | ||
temp = size1[j]- process1[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process1[i],size1[j],temp); | ||
size1[j]-=process1[i]; | ||
process1[i]=0; | ||
|
||
} | ||
} | ||
} | ||
for(i=0;i<6;i++) | ||
{ | ||
if (process1[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process1[i]); | ||
} | ||
|
||
} | ||
|
||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
FirstFit(size,process); | ||
return 0; | ||
} | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void FirstFit(int size1[6],int process1[6]) | ||
{ | ||
int i,j,temp; | ||
printf("----First Fit Memory Allocation Scheme---- \n\n"); | ||
for(i=0;i<5;i++) | ||
{ | ||
for(j=0;j<6;j++) | ||
{ | ||
if ((process1[i]<=size1[j])&&(process1[i]!=0)) | ||
{ | ||
temp = size1[j]- process1[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process1[i],size1[j],temp); | ||
size1[j]-=process1[i]; | ||
process1[i]=0; | ||
|
||
} | ||
} | ||
} | ||
for(i=0;i<6;i++) | ||
{ | ||
if (process1[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process1[i]); | ||
} | ||
|
||
} | ||
|
||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
FirstFit(size,process); | ||
return 0; | ||
} |
88 changes: 44 additions & 44 deletions
88
7.Memory Allocation Scheme/Worst Fit.c → 7.Memory Allocation/Worst Fit.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void WorstFit(int size3[6],int process3[6]) | ||
{ | ||
int i,j,k,temp,max; | ||
printf("----Worst Fit Memory Allocation Scheme---- \n\n"); | ||
for(i=0;i<5;i++) | ||
{ | ||
max=0; | ||
for (j=0;j<6;j++) | ||
{ | ||
if (max<size3[j]) | ||
{ | ||
max=size3[j]; | ||
k= j; | ||
} | ||
|
||
} | ||
if ((process3[i]<=size3[k])&&(process3[i]!=0)) | ||
{ | ||
temp = size3[k]- process3[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process3[i],size3[k],temp); | ||
size3[k]-=process3[i]; | ||
process3[i]=0; | ||
|
||
} | ||
} | ||
for(i=0;i<5;i++) | ||
{ | ||
if (process3[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process3[i]); | ||
} | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
WorstFit(size,process); | ||
return 0; | ||
} | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
|
||
void WorstFit(int size3[6],int process3[6]) | ||
{ | ||
int i,j,k,temp,max; | ||
printf("----Worst Fit Memory Allocation Scheme---- \n\n"); | ||
for(i=0;i<5;i++) | ||
{ | ||
max=0; | ||
for (j=0;j<6;j++) | ||
{ | ||
if (max<size3[j]) | ||
{ | ||
max=size3[j]; | ||
k= j; | ||
} | ||
|
||
} | ||
if ((process3[i]<=size3[k])&&(process3[i]!=0)) | ||
{ | ||
temp = size3[k]- process3[i]; | ||
printf("Process of size %d KB is allocated in the memory block of %d .And new hole is created of size %d KB\n",process3[i],size3[k],temp); | ||
size3[k]-=process3[i]; | ||
process3[i]=0; | ||
|
||
} | ||
} | ||
for(i=0;i<5;i++) | ||
{ | ||
if (process3[i]!=0) | ||
printf("Process of size %d KB is not allocated because sufficient contiguous memory hole is not available to load the process\n",process3[i]); | ||
} | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
int size[6]={300,600,350,200,750,125}; | ||
int process[5] = {115,500,358,200,375}; | ||
WorstFit(size,process); | ||
return 0; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.