BSC OS Programs Manual
BSC OS Programs Manual
#include<stdio.h>
Int main() {
Scanf(“%d”, &limit);
X = limit;
Printf(“Arrival Time:t”);
Scanf(“%d”, &arrival_time*i+);
Printf(“Burst Time:t”);
Scanf(“%d”, &burst_time*i+);
Temp[i] = burst_time[i];
Scanf(“%d”, &time_quantum);
For(total = 0, i = 0; x != 0;)
Temp[i] = 0;
Counter = 1;
{
Temp[i] = temp[i] – time_quantum;
{ x--;
Counter = 0;
If(i == limit – 1)
I = 0; }
I++;
} else
{ i = 0;
} }
Return 0;
}
Output:
Process No[1] 2 1 -1
Process No[2] 2 3 1
Process No[3] 4 5 1
#include<stdio.h>
Int main() {
Int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
Float avg_wt,avg_tat;
Scanf(“%d”,&n);
For(i=0;i<n;i++)
Printf(“p%d:”,i+1);
Scanf(“%d”,&bt*i+); p*i+=i+1;
For(i=0;i<n;i++)
{ pos=i;
For(j=i+1;j<n;j++)
If(bt[j]<bt[pos]) pos=j;
Temp=bt[i];
Bt[i]=bt[pos];
Bt[pos]=temp;
Temp=p[i];
P[i]=p[pos];
P[pos]=temp;
} wt[0]=0;
For(i=1;i<n;i++)
{ wt[i]=0;
For(j=0;j<i;j++)
Wt[i]+=bt[j];
Total+=wt[i]; }
Avg_wt=(float)total/n;
Total=0;
For(i=0;i<n;i++)
{ tat[i]=bt[i]+wt[i];
Total+=tat[i];
Avg_tat=(float)total/n;
}
Output:
p1:32
p2:43
p1 32 0 32
p2 43 32 75
#include<stdio.h>
int main()
{ int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
Scanf(“%d”,&n);
for(i=0;i<n;i++)
{ Printf(“P*%d+:”,i+1);
Scanf(“%d”,&bt*i+);
Wt[0]=0;
for(i=1;i<n;i++)
Wt[i]=0;
for(j=0;j<i;j++)
Wt[i]+=bt[j];
for(i=0;i<n;i++)
Tat[i]=bt[i]+wt[i];
Avwt+=wt[i];
Avtat+=tat[i];
Printf(“nP*%d+tt%dtt%dtt%d”,i+1,bt*i+,wt*i+,tat*i+);
Avwt/=i; Avtat/=i;
return 0; }
Output:
p[2]:7
p[3]:2
p[1] 5 0 5
p[2] 7 5 12
p[3] 2 12 14
#include<stdio.h>
#include<conio.h>
void main()
{ int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;
Scanf(“%d”,&n);
for(i=0;i<n;i++)
Printf(“\nProcess no %d : “,i+1);
Scanf(“%d %d”,&pt*i+,&pp*i+);
P[i]=i+1; }
for(i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(pp[i]<pp[j])
X=pp[i];
Pp[i]=pp[j];
Pp[j]=x;
X=pt[i];
Pt[i]=pt[j];
Pt[j]=x;
X=p[i];
P[i]=p[j];
P[j]=x; } } }
W[0]=0;
Awt=0;
T[0]=pt[0];
atat=t[0];
for(i=1;i<n;i++)
{ w[i]=t[i-1];
awt+=w[i];
T[i]=w[i]+pt[i];
atat+=t[i];
- printf(“\n\n Job \t Burst Time \t Wait Time \t Turn Around Time Priority \n”);
for(i=0;i<n;i++)
Awt/=n;
Atat/=n;
getch();
}
Output:
1 68 0 68 3
0 0 68 68 0
0 0 68 68 -720880432
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
for(i=0;i<50;i++)
{f[i]=0;}
X: count=0;
scanf(“%d%d”, &st,&len);
for(k=st;k<(st+len);k++)
{ if(f[k]==0)
count++;}
if(len==count)
for(j=st;j<(st+len);j++)
if(f[j]==0)
F[j]=1;
printf(“%d\t%d\n”,j,f*j+);
if(j!=(st+len-1))
else
printf(“ The file is not allocated \n”);
scanf(“%d”, &c);
if(c==1){
goto x;}
getch();
}
Output:
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
void main()
clrscr();
for(i=0;i<50;i++)
F[i]=0;
scanf(“%d”,&ind);
if(f[ind]!=1)
Printf(“Enter no of blocks needed and no of files for the index %d on the disk : \n”, ind);
Scanf(“%d”,&n);
else
goto x;
y: count=0;
for(i=0;i<n;i++)
scanf(“%d”, &index*i+);
if(f[index[i]]==0)
count++;
if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
Printf(“Allocated\n”);
Printf(“File Indexed\n”);
for(k=0;k<n;k++)
Printf(“%d------%d : %d\n”,ind,index*k+,f*index*k++);
else
goto y;
Scanf(“%d”, &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Output :
Enter no. of blocks needed and no. of files for the index 3 on the disk: 2
Trri
Allocated
File indexed
3-----0:1
3-----0:1
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
clrscr();
for(i=0;i<50;i++)
F[i]=0;
Scanf(“%d”,&p);
for(i=0;i<p;i++)
scanf(“%d”,&a);
F[a]=1;
}
X: printf(“Enter index starting block and length: “);
scanf(“%d%d”, &st,&len);
K=len;
if(f[st]==0)
for(j=st;j<(st+k);j++)
if(f[j]==0)
F[j]=1;
printf(“%d------%d\n”,j,f*j+);
else
k++;
}
else
scanf(“%d”, &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Output:
4 7 9
4------1
6------1
7------1
8------1
9------1
10------1
11------1
8. Simulate MVT and MFT Memory Management Techniques:
#include<stdio.h>
#include<conio.h>
Void main()
{ int i,os_m,nPage,total,pg[25];
clrscr();
scanf("%d",&total);
scanf("%d",&os_m);
scanf("%d",&nPage);
for(i=0;i<nPage;i++)
scanf("%d",&pg[i]);
total=total-os_m;
for(i=0;i<nPage;i++)
{ if(total>=pg[i])
total=total-pg[i]; }
else{
getch();
}
Output:
Allocate page 1
Allocate page 2
Allocate page 3
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int nf=0,i=0,j=0,ch;
char mdname[10],fname[10][10],name[10];
clrscr();
scanf("%s",mdname);
scanf("%d",&nf);
do
for(i=0;i<nf;i++)
if(!strcmp(name,fname[i]))
break;
if(i==nf)
strcpy(fname[j++],name);
nf++;
else
scanf("%d",&ch);
}
while(ch==1);
for(i=0;i<j;i++)
printf("\n%s",fname[i]);
getch();
}
Output:
System
Operating
10. Simulate Two Level File Organization Techniques:
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
struct
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
int i,ch,dcnt,k;
dcnt=0;
while(1)
scanf("%d",&ch);
switch(ch)
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",dir[i].fname[dir[i].fcnt]);
printf("File created");
break;
if(i==dcnt)
break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
goto jmp;
}
}
jmp : break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
goto jmp1;
goto jmp1;
jmp1: break;
case 5: if(dcnt==0)
else
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
break;
default:exit(0);
}
Output :
Directory created
File created
Directory Files
computers
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int nf=0,i=0,j=0,ch;
char mdname[10],fname[10][10],name[10];
clrscr();
scanf("%s",mdname);
scanf("%d",&nf);
do
{
printf("Enter file name to be created:");
scanf("%s",name);
for(i=0;i<nf;i++)
if(!strcmp(name,fname[i]))
break;
if(i==nf)
strcpy(fname[j++],name);
nf++;
else
while(ch==1);
for(i=0;i<j;i++)
printf("\n%s",fname[i]);
getch();
}
Output:
operating
system
12. Write a Program for Bankers Algorithm for Dead lock Avoidance:
#include <stdio.h>
int main()
scanf("%d", &processes);
running[i] = 1;
counter++;
scanf("%d", &resources);
scanf("%d", &maxres[i]);
scanf("%d", ¤t[i][j]);
scanf("%d", &maximum_claim[i][j]);
printf("\t%d", maxres[i]);
printf("\t%d", current[i][j]);
printf("\n");
}
printf("\nThe Maximum Claim Table:\n");
printf("\t%d", maximum_claim[i][j]);
printf("\n");
allocation[j] += current[i][j];
printf("\nAllocated resources:");
printf("\t%d", allocation[i]);
printf("\nAvailable resources:");
for (i = 0; i < resources; i++)
printf("\t%d", available[i]);
printf("\n");
while (counter != 0)
safe = 0;
if (running[i])
exec = 1;
exec = 0;
break;
if (exec)
running[i] = 0;
counter--;
safe = 1;
available[j] += current[i][j];
break;
if (!safe)
break;
else
printf("\nAvailable vector:");
printf("\t%d", available[i]);
printf("\n");
return 0;
}
Output:
3 4
6 4
3 2
4 5
Allocated resources: 9 8
Available resources: -6 -6
#include <stdio.h>
int main()
int n, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
{ 2, 0, 0 }, // P1
{ 3, 0, 2 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4
{ 9, 0, 2 }, // P2
{ 2, 2, 2 }, // P3
{ 4, 3, 3 } }; // P4
f[k] = 0;
int need[n][m];
int y = 0;
if (f[i] == 0) {
int flag = 0;
flag = 1;
break;
if (flag == 0) {
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
int flag = 1;
for(int i=0;i<n;i++)
if(f[i]==0)
flag=0;
if(flag==1)
return (0);
}
Output:
a)FIFO
#include<stdio.h>
Int main()
int pagefaults = 0;
int frames = 3;
Int m, n, s, pages;
Pages = sizeof(incomingstream)/sizeof(incomingstream[0]);
Int temp[frames];
{ temp[m] = -1; }
{ s = 0;
{ if(incomingstream[m] == temp[n])
{ s++; pagefaults--; } }
pagefaults++;
{ temp[m] = incomingstream[m];
Else if(s == 0)
}
Printf(“\n”);
Printf(“%d\t\t\t”,incomingstream[m]);
if(temp[n] != -1)
return 0;
}
Output:
4 4 - -
1 4 1 -
2 4 1 2
4 4 1 2
5 5 1 2
#include<stdio.h>
minimum = time[i];
pos = i;
return pos;
}
//main function
int main()
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos,
faults = 0;
scanf(“%d”, &no_of_frames);
scanf(“%d”, &no_of_pages);
scanf(“%d”, &pages*i+);
frames[i] = -1;
flag1 = flag2 = 0;
{
if (frames[j] == pages[i])
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
if (flag1 == 0)
if (frames[j] == -1)
counter++;
faults++;
frames[j] = pages[i];
time[j] = counter;
flag2 = 1;
break;
if (flag2 == 0)
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
printf(“\n”);
printf(“%d\t”, frames*j+);
return 0;
}
Output:
0 -1
0 -1
0 -1
#include<stdio.h>
int main() {
int f,p;
int pages[50],frame[10],hit=0,count[50],time[50];
int i,j,page,flag,least,mintime,temp;
scanf(“%d”,&f);
scanf(“%d”,&p);
for(i=0;i<f;i++)
{ frame[i]=-1; }
for(i=0;i<50;i++)
{ count[i]=0; }
for(i=0;i<p;i++)
, scanf(“%d”,&pages*i+); -
printf(“\n”);
for(i=0;i<p;i++)
{ count[pages[i]]++;
time[pages[i]]=i;
flag=1;
least=frame[0];
for(j=0;j<f;j++)
{ if(frame[j]==-1 || frame[j]==pages[i])
{ if(frame[j]!=-1) { hit++; }
flag=0;
frame[j]=pages[i];
break; }
if(count[least]>count[frame[j]]) { least=frame[j]; } }
if(flag) { mintime=50;
for(j=0;j<f;j++)
{ temp=j;
mintime=time[frame[j]]; } }
count[frame[temp]]=0;
frame[temp]=pages[i]; }
for(j=0;j<f;j++)
, printf(“%d “,frame*j+); -
printf(“\n”); -
return 0;
}
Output:
Enter no of frames: 4
Enter no of pages: 3
2 -1 -1 -1
2 1 -1 -1
2 1 0 -1
Page hit = 0
15. Simulate Paging Techniques of Memory Management:
#include<stdio.h>
#include<conio.h>
main()
clrscr();
scanf(“%d”,&ms);
scanf(“%d”,&ps);
nop = ms/ps;
scanf(“%d”,&np);
rempages = nop;
for(i=1;i<=np;i++)
scanf(“%d”,&s*i+);
if(s[i] >rempages)
printf(“\nMemory is Full”);
break;
for(j=0;j<s[i];j++)
scanf(“%d”,&fno*i+*j+);
else
pa=fno[x][y]*ps+offset;
getch();
}
Output:
Memory is Full