Professional Documents
Culture Documents
Os File
Os File
Of
“OPERATING SYSTEMS
LAB”
PC-CS-212AL
Submitted to: Submitted by:
Implementation of shortest
4. 17-03-23 job first serve (SJFS)
Implementation of priority
5. 31-03-23 scheduling
Implementation of Round
6. 31-03-23 Robin scheduling
Windows Vista Home Premium. Windows Vista Business. Windows Vista Enterprise..and
Windows Vista Ultimate
1-gigahertz (GHz) 32-bit (x86) processor or 1-GHz 64-bit (x64) processor
1 GB of system memory
Windows Aero-capable graphics card
Note This includes a DirectX 9-class graphics card.
128 MB of graphics memory (minimum)
40-GB hard disk that has 15 GB of free hard disk space (the 15GB of free space provides
room for temporary file storage during the install or upgrade.)
Internal or external DVD drive
Internet access capability
Audio output capability
Sourcecode:
#include<conio.h>
#include<stdio.h>
main()
{
int i,n,a[20];
float t=0.0,w=0.0;
clrscr();
printf("FCFS");
printf("\nEnter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
t=t+a[i];
if(i!=n)
w=w+t;
}
t=t/n;
w=w/n;
printf("\nAverage turn around time %f ",t);
printf("\nAverage waiting time : %f",w);
getch();
}
Output:
Program No. : 4
Aim : Write a program to implement Shortest-Job-First-Serverd (SJFS) Scheduling.
Sourcecode:
#include<conio.h>
#include<stdio.h>
main()
{
int i,n,j,k,temp,a[20];
float t=0.0,w=0.0;
clrscr();
printf("SJFS");
printf("\nEnter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(j=1;j<=n;j++)
{
for(k=j+1;k<=n;k++)
{
if(a[j]>a[k])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}
t=t+a[j];
if(j!=n)
w=w+t;
}
t=t/n;
w=w/n;
printf("\nAverage turn around time : %f ",t);
printf("\nAverage waiting time : %f",w);
getch();
}
Output:
Program No. : 5
Aim : Write a program to implement Priority scheduling.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int p[20],b[20],temp1,temp2,i,j,n;
float d=0.0,w=0.0,t=0.0;
clrscr();
printf("\nEnter the total no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\nEnter the priority of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&p[i]);
printf("\nAccording to priority arrangement of processes are ");
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i]>p[j])
{
temp1=p[i];
p[i]=p[j];
p[j]=temp1;
temp2=b[i];
b[i]=b[j];
b[j]=temp2;
}
}
printf("\n %d",b[i]);
}
for(i=1;i<=n;i++)
d=b[i]+d;
d=d/n;
printf("\nTurn around time is %f ",d);
for(i=1;i<n;i++)
{
w=w+b[i];
t=t+w;
}
t=t/n;
printf("\nAverage waiting time is %f ",t);
getch();
Output:
Program No. : 6
Aim : Write a program to implement Round-Robin Scheduling.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int bt[50],st[50],wt[50],tat[50],i,j,n,tq,temp,count=0,swt=0,stat=0,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of processes : ");
for(i=1;i<=n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("\nEnter the time quantum process : ");
scanf("%d",&tq);
while(1)
{
for(i=1,count=0;i<=n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>=tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=1;i<=n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+bt[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("\nTurn around time is = %f ",atat);
printf("\nWaiting time is = %f ",awt);
getch();
}
Output:
Program No. : 7
Aim : Write a program to implement Memory allocation.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,ps,a[20],b[20],small,large,index;
clrscr();
printf("\nEnter the no. of memory blocks : ");
scanf("%d",&n);
printf("\nEnter the size of memory blocks : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter the size of new process : ");
scanf("%d",&ps);
for(i=0;i<n;i++)
{
if(a[i]>=ps)
{
index=i;
break;
}
}
printf("\nFirst fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
for(i=0;i<n;i++)
{
b[i]=a[i]-ps;
}
small=b[0];
for(i=0;i<n;i++)
{
if(b[i]<small&&b[i]>=0)
{
small=b[i];
index=i;
}
}
printf("\n\nBest fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
large=b[0];
for(i=0;i<n;i++)
{
if(b[i]>large&&b[i]>=0)
{
large=b[i];
index=i;
}
}
printf("\n\nWorst fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
getch();
}
Output:
Program No. : 8
Aim : Write a program to implement Resource Allocation Graph.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int pr,re,i,j,pn,rn,ch,p[10][10],r[10][10],flag;
clrscr();
printf("Enter the no. of process : ");
scanf("%d",&pr);
printf("\nEnter the no. of resources : ");
scanf("%d",&re);
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
p[i][j]=0;
}
for(i=1;i<=re;i++)
{
for(j=1;j<=pr;j++)
r[i][j]=0;
}
do
{
printf("\nEnter the process number : ");
scanf("%d",&pn);
if(pn>pr)
printf("\nProcess not present");
printf("\nEnter the resource no. : ");
scanf("%d",&rn);
if(rn>re)
printf("\nResource not present.");
for(i=1;i<=pr;i++)
{
if(r[rn][i]==0)
{
flag=1;
r[rn][i]=2;
}
}
if(flag==1)
p[pn][rn]=1;
else
r[rn][pn]=1;
printf("\n\nAny more process then press 1 or press 2 : ");
scanf("%d",&ch);
flag=0;
}while(ch==1);
printf("\n\nResource allocation graph is : ");
for(i=1;i<=pr;i++)
for(j=1;j<=re;j++)
if(p[i][j]==1)
printf("\nR%d------>P%d",j,i);
for(i=1;i<=re;i++)
for(j=1;j<=pr;j++)
if(r[i][j]==1)
printf("\nP%d......>R%d",j,i);
getch();
}
Output:
Program No. : 9
Aim : Write a program to implement wait for graph.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int pr,re,i,j,k,pn,rn,ch,p[10][10],w[10][10],r[10][10],flag;
clrscr();
printf("Enter the no. of process : ");
scanf("%d",&pr);
printf("\nEnter the no. of resources : ");
scanf("%d",&re);
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
p[i][j]=0;
}
for(i=1;i<=re;i++)
{
for(j=1;j<=pr;j++)
r[i][j]=0;
}
do
{
printf("\nEnter the process number : ");
scanf("%d",&pn);
if(pn>pr)
printf("\nProcess not present");
printf("\nEnter the resource no. : ");
scanf("%d",&rn);
if(rn>re)
printf("\nResource not present.");
for(i=1;i<=pr;i++)
{
if(r[rn][i]==0)
{
flag=1;
r[rn][i]=2;
}
}
if(flag==1)
p[pn][rn]=1;
else
r[rn][pn]=1;
printf("\n\nAny more process then press 1 or press 2 : ");
scanf("%d",&ch);
flag=0;
}while(ch==1);
printf("\n\nResource allocation graph is : ");
for(i=1;i<=pr;i++)
for(j=1;j<=re;j++)
if(p[i][j]==1)
printf("\nR%d------>P%d",j,i);
for(i=1;i<=re;i++)
for(j=1;j<=pr;j++)
if(r[i][j]==1)
printf("\nP%d......>R%d",j,i);
for(i=1;i<=pr;i++)
{
for(j=1;j<=pr;j++)
{
w[i][j]=0;
}
}
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
{
for(k=1;k<=pr;k++)
{
if((p[i][j]==1)&&(r[j][k]==1)&&(i!=k))
{
w[k][i]=1;
}
}
}
}
printf("\n\nWait for graph is ");
for(i=1;i<=pr;i++)
{
for(j=1;j<=pr;j++)
{
if(w[i][j]==1)
{
printf("\nP%d---->P%d",i,j);
}
}
}
getch();
}
Output:
Program No. : 10
Aim : Write a program to implement internal and external fragmentation.
Sourcecode:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[20],temp[20],i,n,p,t,loc,sz,flag[20],x=0;
clrscr();
printf("Enter the memory space : ");
scanf("%d",&p);
printf("\nEnter the total no. blocks : ");
scanf("%d",&n);
printf("\nEnter the size of blocks : ");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
x=x+a[i];
}
if(x>p)
{
printf("\nWrong partition!!!!");
getch();
exit(0);
}
for(i=1;i<=n;i++)
{
flag[i]=0;
}
printf("\nEnter the size of process : ");
scanf("%d",&sz);
printf("\nBest fit");
for(i=1;i<=n;i++)
{
temp[i]=a[i]-sz;
}
t=p;
for(i=1;i<=n;i++)
{
if((t>temp[i])&&(temp[i]>=0)&&(flag[i]==0))
{
t=temp[i];
loc=i;
}
}
if(t!=p)
{
printf("\nInternal fragmentation at the location : %d",loc);
a[loc]=t;
flag[loc]=1;
}
else
{
printf("\nExternal fragmentation ");
for(i=1;i<=n;i++)
{
if(flag[i]==0)
{
printf("\n\nTotal free space %d at the location %d",a[i],i);
}
}
for(i=1;i<=n;i++)
{
if(flag[i]==1)
{
printf("\n\nTotal free space %d at the location %d",a[i],i);
}
}
}
getch();
}
Output: