Operating System Important Questions
Operating System Important Questions
Operating System Important Questions
#include <stdio.h>
{ wait_time[0] = 0;
return 0;
int turnaroundtime( int proc[], int n, int burst_time[], int wait_time[], int tat[])
int i;
return 0;
int i;
return 0;
int main()
avgtime(proc, n, burst_me);
return 0;
2.Round robin
#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;
x--;
counter = 0;
if(i == limit - 1) {
i = 0;
}
else if(arrival_time[i + 1] <= total) {
i++;
else {
i = 0;
return 0;
#include<stdio.h>
int main()
{ int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10], i ;
b[i]= 0 ;
w[i]= 0 ;
scanf("%d",&n);
scanf("%d", &b[i]);
p[i]=i;
if(b[i]>b[j])
{ temp=b[i];
temp1=p[i];
b[i]=b[j];
p[i]=p[j];
b[j]=temp;
p[j]=temp1;
w[0]=0;
w[i+1] = w[i]+b[i];
t[i] = w[i]+b[i];
awt = awt+w[i];
att = att+t[i];
awt=awt/n;
att=att/n;
return 1;
#include <stdio.h>
int main()
scanf("%d", &referenceString[m]);
scanf("%d", &frames);
int temp[frames];
temp[m] = -1;
s = 0;
if(referenceString[m] == temp[n]) {
s++ ;
pageFaults-- ;
pageFaults++;
temp[m] = referenceString[m];
else if(s == 0)
printf("\n");
printf("%d\t", temp[n]);
return 0;
}
5.LRU
#include<stdio.h>
main()
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++ ;
k++;
c1=0;
for(j=0;j<f;j++)
if(p[i]!=q[j])
c1++;
if(c1==f) {
c++;
if(k<f) {
q[k]=p[i];
k++;
for(j=0 ; j<k ; j++)
printf("\t%d",q[j]);
printf("\n");
else
c2[r] = 0 ;
if(q[r]!=p[j])
c2[r]++;
else
break;
b[r]=c2[r];
if(b[r]<b[j]) {
t=b[r];
b[r]=b[j];
b[j]=t;
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
printf("\n");
6.Bankers algorithm
#include<stdio.h>
#include<conio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n,r;
void input();
void show();
void cal();
int main()
int i,j;
input();
show();
cal();
getch();
return 0;
void input()
int i,j;
scanf("%d",&n);
scanf("%d",&r);
scanf("%d",&max[i][j]);
scanf("%d",&alloc[i][j]);
scanf("%d",&avail[j]);
void show()
int i,j;
printf("\nP%d\t ",i+1);
printf("%d ",alloc[i][j]);
printf("\t");
printf("%d ",max[i][j]);
printf("\t");
if(i==0)
for(j=0;j<r;j++)
printf("%d ",avail[j]);
void cal()
int finish[100],temp,need[100][100],flag=1,k,c1=0;
int safe[100];
int i,j;
finish[i]=0;
need[i][j]=max[i][j]-alloc[i][j];
printf("\n");
while(flag)
flag=0;
int c=0;
if((finish[i]==0)&&(need[i][j]<=avail[j])) {
c++;
if(c==r)
avail[k]+=alloc[i][j];
finish[i]=1;
flag=1;
printf("P%d->",i);
if(finish[i]==1)
i=n;
if(finish[i]==1)
c1++;
else
printf("P%d->",i);
if(c1==n)
else
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
printf("Enter the starting block and the length of the files: ");
if (files[j] == 0)
flag++;
if(len == flag) {
if (files[k] == 0) {
files[k] = 1;
printf("%d\t%d\n", k, files[k]);
if (k != (startBlock+len-1))
else
printf("The file is not allocated to the disk\n");
scanf("%d", &ch);
if (ch == 1)
recurse(files);
else
exit(0);
return;
int main()
{ int files[50];
files[i]=0;
recurse(files);
getch();
return 0;
}
8.Index File allocation
#include<stdlib.h>
main()
for(i=0;i<50;i++)
f[i]=0;
scanf("%d",&ind);
if(f[ind]!=1) {
scanf("%d",&n);
else
goto x;
y: count=0;
scanf("%d", &index[i]);
if(f[index[i]]==0)
count++;
if(count==n)
{
f[index[j]]=1;
printf("Allocated\n");
printf("File Indexed\n");
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();
}
9.Linked File Allocation
#include<stdlib.h>
main()
f[i]=0;
scanf("%d",&p);
scanf("%d",&a);
f[a]=1;
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)
gotx;
else
exit(0);
getch();
#include<stdio.h>
main()
scanf("%d",&ms);
scanf("%d",&ps);
nop = ms/ps;
rempages = nop;
printf("\nMemory is Full");
break;
scanf("%d",&fno[i][j]);
else
pa=fno[x][y]*ps+offset;
getch();