OS Lab Manual
OS Lab Manual
S Nagar(Irumbedu), Arni,
T.V.Malai Dt.-632 317.
Department
Of
Information Technology
CS3461-Operating System Laboratory
1.INSTALLATION OF WINDOWS OPERATING SYSTEM
Step 3: Go to https://www.microsoft.com/en-us/software-
download/windows10%20.
This is official download website for Windows 10
Login
part of time Cal Calendar of the current month cal year Displays calendar
for all months of
The commands can be combined using the pipeline (|) operator. For
example, number of users logged in can be obtained as. who | wc -l
Finally to terminate the unix session execute the command exit or logout.
Output
$ date +%H 13
$ uname Linux
$ uname -r 2.4.20-8smp
$ uname -n localhost.localdomain
$ bc 3+5 8
$ pwd /home/vijai/shellscripts/loops
$ cd shellscripts/loops/ $
$ cd $
$ cd / [vijai@localhost /]$
$ cat >> greet bye $ cat greet hi cse wishing u the best bye
$ rm -i *.sh rm: remove regular file 'fact.sh'? y rm: remove regular file
'prime.sh'? y $ ls list.sh regexpr shellscripts
PROGRAM:
echo "enter the number"
read num
echo "enter the number”
read num
if [ `expr $num % 2` -eq 0 ]
then
echo "number is even"
else
echo "number is odd"
fi
OUTPUT:
PROGRAM:
echo "enter the number"
read a b
if [ $a -gt $b ]
then
echo "A is big"
else
echo "B is big"
fi
OUTPUT:
PROGRAM:
echo "enter three numbers"
read a b c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "A is big"
else if [ $b -gt $c ]
then
echo "B is big"
else
echo "C is big"
fi
OUTPUT:
OUTPUT:
Enter the number :
4
The factorial of 4 is 24.
2.E. FIBONACCI SERIES
PROGRAM:
echo " ENTER THE LIMIT FOR FIBONNACI SERIES"
read lim
n1=0
n2=1
var=0
echo "FIBONACCI SERIES IS "
echo "$n1"
echo "$n2"
while [ $var -lt `expr $lim - 2` ]
do
n3=`expr $n1 + $n2 `
n1=`expr $n2 `
n2=`expr $n3 `
var=`expr $var + 1 `
echo "$n2"
done
OUTPUT :
OUTPUT:
cse6@localhost Pgm]$ cc prog4a.c [cse6@localhost Pgm]$ ./a.out
4.A. CPU SCHEDULING: ROUND ROBIN SCHEDULING
PROGRAM:
#include<studio.h>
void main()
int i,tbt=0,nop,ts=0,flag[20],
rem[20];
int from,wt[20],tt[20],b[20],
twt=0,ttt=0;
int dur;
float awt,att;
printf("Enter no. of
Processes: ");
scanf("%d",&nop);
flag[i]=0;
}
from=0;
i=0;
printf("\n\t Gantt Chart");
{
if(!flag[i])
{
if(rem[i]<=ts)
{
dur=rem[i];
flag[i]=1;
tt[i]=dur+from; wt[i]=tt[i]-b[i];
}
else dur=ts;
from += dur;
}
i=(i+1)%nop;
}
for(i=0;i<nop;i++)
{
twt+=wt[i];
ttt+=tt[i];
}
{
printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);
}
awt=(float)twt/(float)nop;
att=(float)ttt/(float)nop;
}
OUTPUT:
Enter no. of Processes: 3
Enter the time
slice: 3
Enter the Burst times.. P1 : 24
P2 : 5
P3 : 3
Gantt Chart
ProcessID From Time To Time
1 0 3
2 3 6
3 6 9
1 9 12
2 12 14
1 14 17
1 17 20
1 20 23
1 23 26
1 26 29
1 29 32
Turn Around
Process ID Waiting Time Time
1 8 32
2 9 14
3 6 9
Total Waiting Time:23
Total Turn Around
Time:55
Average Waiting
Time:7.67
PROGRAM :
#include<stdio.h>
int main()
struct
int p,bt;
}sjf[10],temp;
scanf("%d",&n); for(i=1;i<=n;i++)
scanf("%d",&sjf[i].bt);
sjf[i].p=i;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(sjf[j].bt>sjf[i].bt)
temp=sjf[i];
sjf[i]=sjf[j];
sjf[j]=temp;
w[1]=0;
tot[1]=sjf[1].bt;
atot=0;
for(i=1;i<=n;i++)
w[i]=tot[i]-sjf[i].bt; awt+=w[i];
atot+=tot[i];
avwt=(float)awt/n;
avtot=(float)atot/n;
for(i=1;i<=n;i++)
printf("\n\t%d\t\t%d\t\t%d",sjf[i].p,w[i],tot[i]);
}
OUTPUT:
3 0 3
2 3 8
1 8 32
PROGRAM
#include<stdio.h>
int main()
{
int n,b[10],t=0,i,w=0,r=0,a=0; float avg,avg1;
printf("\nEnter number of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : \n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\n Gantt chart ");
for(i=1;i<=n;i++)
printf("P%d\t",i);
printf("\n\nProcess BurstTime WaitingTime TurnaroundTime\n");
for(i=1;i<=n;i++)
{
t=t+w;
r=r+b[i];
printf("P%d\t\t%d\t\t%d\t\t%d\t\t\n",i,b[i],w,r);
w=w+b[i];
a=a+r;
}
avg=(float)t/n;
avg1=(float)a/n;
printf("\n Average WaitingTime is %f",avg);
printf("\n Average TurnaroundTime is %f\n",avg1);
return(0);
}
OUTPUT:
Gantt chart P1 P2 P3
Process BurstTime WaitingTime TurnaroundTime
P1 24 0 24
P2 5 24 29
P3 3 29 32
PROGRAM :
#include<stdio.h>
int main()
{
int n,temp=0,w[20],b[20], p[20], t2[20],j,t1,d[20],i, te=0,b1[20],t3=0;
float t,r; w[1]=0;
printf("\nEnter no. of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : ");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&b[i]);
d[i]=i;
}
printf("Enter the priorities:");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&p[i]);
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(p[i]<p[j])
{
temp=p[i];
t1=d[i];
te=b[i];
p[i]=p[j];
d[i]=d[j];
b[i]=b[j];
p[j]=temp;
d[j]=t1;
b[j]=te;
}
printf("\nGantt Chart : "); for(i=1;i<=n;i++) printf("P%d\t",d[i]);
printf("\nProcess \t Priority\tBurst Time\t Waiting Time\t Turnaround
Time");
for(i=1;i<=n;i++)
{
t=d[i];
w[i+1]=w[i]+b[i];
t2[i]=b[i]+w[i];
t3+=t2[i];
printf("\nP%d\t\t%d\t\t%d\t\t%d\t\t%d",d[i],p[i],b[i],w[i],t2[i]);
}
temp=0;
for(i=1;i<=n;i++)
temp+=w[i];
t=(float)temp/n;
r=(float)t3/n;
printf("\nAverage Waiting time : %.2f",t); printf("\nAverage Turnaround
time : %.2f",r);
}
OUTPUT:
P1 : 2
P2 : 1
P3 : 3
Gantt Chart : P2 P1P3
ProcessID Priority BurstTime WaitingTime TurnaroundTime
P2 1 5 0 5
P1 2 24 5 29
P3 3 3 29 32
[cse6@localhost Pgm]$
5.IMPLEMENTATION OF INTER PROCESS COMMUNICATION
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
main()
{
int p1[2],p2[2],p3[2],p4[2];
int i,j=0,k=0,l=0;
char r[10],s[10],t[10],u[10];
printf("\t PROCESS 1.ENTER THE STRING");
scanf("%s",r);
pipe(p1);
pipe(p2);
write(p1[1],r,sizeof(r));
write(p2[1],r,sizeof(r));
int a=fork();
if(a==0)
{
printf("\n\t PROCESS 2:it splits the given string\n");
read(p1[0],r,sizeof(r));
int n=strlen(r);
for(i=0;i<n/2;i++)
{
s[i]=r[i];
}
for(i=n/2;i<=n;i++)
{
t[j++]=r[i];
}
pipe(p3);
pipe(p4);
write(p3[1],s,sizeof(s));
write(p4[1],t,sizeof(t));
int b=fork();
if(b==0)
{
printf("p4 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p3[0],s,sizeof(s));
printf("\t PROCESS 4:sub string \t %s \t",s);
printf("no of char=%d \n",strlen(s));
}
else
{
int c=fork();
if(c==0) {
printf("p5 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p4[0],t,sizeof(t));
printf("\t PROCESS 5:sub string \t %s \t",t);
printf("no of char=%d \n",strlen(t));
}
else
{
wait();
printf("p2 %d\t",getpid());
printf("p1 %d\n",getppid());
}
}
}
else
{
wait();
int d=fork();
if(d==0)
{
printf("p3 %d\t",getpid());
printf("p1 %d\n",getppid());
read(p2[0],r,sizeof(r));
for(i=strlen(r)-1;i>=0;i--)
{
u[l++]=r[i];
}
for(i=0;i<strlen(r);i++)
{
if(u[i]==r[i])
k++;
else
continue;
}
if(k==strlen(r))
printf("\t PROCESS 3: the given string is palindrome\n");
else
printf("\t PROCESS 3: the given string is not palindrome\n");
}
else
{
printf("p1 %d\t",getpid());
printf("kernal %d\t\n",getppid());
}
}
}
OUTPUT:
Process 1: enter the string ARUN
Process 2: it splits the string
P4 8137 p2 8136
Process 3: sub string a r no of char=2
P5 8138 p2 8136
Process 4; substring u n no of char=2
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is not palindrome
Process 1: enter the string MADAM
Process 2: it splits the string
P4 8137 p2 8136
Process 4: sub string m a no of char=2
P5 8138 p2 8136
Process 5: sub string dam no of char=3
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is palindrome
6. IMPLEMENT MUTUAL EXCLUSION BY SEMAPHORE
PROGRAM:
#include<stdio.h>
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n 1.producer\n2.consumer\n3.exit\n");
while(1)
scanf("%d",&n);
switch(n)
case 1:if((mutex==1)&&(empty!=0))
producer();
else
case 2:if((mutex==1)&&(full!=0))
consumer();
else
printf("buffer is empty");
break;
case 3:exit(0);
break;
int wait(int s)
return(--s);
int signal(int s)
return (++s);
void producer()
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
mutex=signal(mutex);
}
void consumer()
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
x--;
mutex=signal(mutex);
}
OUTPUT:
Produced element a
Consumed element a
Produced element b
Consumed element b
Produced element c
Consumed element c
Produced element d
Consumed element d
Produced element e
Consumed element e
Produced element f
Consumed element f
Produced element g
Consumed element g
Produced element h
Consumed element h
7.IMPLEMENTATION BANKERS ALGORITHM FOR DEAD
LOCK AVOIDANCE
PROGRAM:
#include<stdio.h>
Void main()
int n,i,j,c,p[20],av[20],max[20][20],all[20][20],all1[20][20],
int need[20][20];
scanf(“%d”,&n);
for(i=0;i<n;i++)
scanf(“%d”,&p[i]);
for(i=0;i<3;i++)
scanf(“%d”,&av[i]);
for(i=0;<n;i++)
for(j=0;j<3;j++)
{
scanf(“%d”,&max[i][j]);
printf(“\n”);
for(i=0;<n;i++)
for(j=0;j<3;j++)
scanf(“%d”,&alli][j]);
printf(“\n”);
for(i=0;<n;i++)
for(j=0;j<3;j++)
all1[i][j]=all[i][j];
for(i=0;<n;i++)
for(j=0;j<3;j++)
{
need[i][j]=max[i][j]-all[i][j];
for(i=0;<3;i++)
c=0;
for(j=0;j<n;j++)
c=c+all[j][i];
av[i]=av[i]-c;
printf(“\n A \t B \t C \n”);
for(i=0;<n;i++)
for(j=0;j<3;j++)
printf(“%d \t”need[i][j]);
printf(“\n”);
Printf(“\n AVAILABLE”);
for(i=0;<3;i++)
{
printf(“%d\t”av[j]);
for(i=0;<n;i++)
for(j=0;j<3;j++)
if(need[i][j]<=av[j])
all[i][j]=all1[i][j]+need[i][j];
av[j]=all1[i][j]+av[j];
else
exit(0);
printf(“\n***SUCCESS***);
printf(“\n***ALLOCATED MATRIX***);
printf(“\n A \t B \t C \n);
for(i=0;<n;i++)
{
for(j=0;j<3;j++)
Printf(“%d \t”,all[i][j]);
printf(“\n”);
for(i=0;i<3;i++)
Printf(“\n %d”,av[j]);
Output:
Safe Sequence :
p2 p4 p5 p1 p3
Need matrix :
743
122
600
011
431
8. IMPLEMENTATION OF DEADLOCK DETECTION ALGORITHM
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();
scanf("%d",&tp);
scanf("%d",&tr);
for(i=1;i<=tp;i++)
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
for(i=1;i<=tp;i++)
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
for(i=1;i<=tr;i++)
scanf("%d",&r[i]);
for(i=1;i<=tr;i++)
scanf("%d",&a[i]);
temp[i]=a[i];
for(i=1;i<=tp;i++)
sum=0;
for(j=1;j<=tr;j++)
sum+=p[i][j];
if(sum==0)
m[k]=i;
k++;
}
for(i=1;i<=tp;i++)
for(l=1;l<k;l++)
if(i!=m[l])
flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
flag=0;
break;
if(flag==1)
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
found=0;
for(i=1;i<k;i++)
if(j==m[i])
found=1;
if(found==0)
printf("%d\t",j);
getch();
OUTPUT:
OUT PUT:
Job 1 started
Job 2 started
Job 2 finished
Job 2 finished
10. PAGING TECHNIQUE OF MEMORY MANAGEMENT
PROGRAM:
#include <stdio.h>
#include <conio.h>
struct pstruct
int fno;
int pbit;
}ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],frameno;
void info()
scanf("%d",&pmsize);
scanf("%d",&lmsize);
scanf("%d",&psize);
}
void assign()
int i;
for (i=0;i<page;i++)
ptable[i].fno = -1;
ptable[i].pbit= -1;
for(i=0; i<frame;i++)
ftable[i] = 32555;
for (i=0;i<page;i++)
scanf("%d",&frameno);
ftable[frameno] = i;
if(ptable[i].pbit == -1)
ptable[i].fno = frameno;
ptable[i].pbit = 1;
getch();
printf("\n\nPAGE TABLE\n\n");
printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);
printf("\n\n\n\tFRAME TABLE\n\n");
printf("FrameAddress PageNo\n\n");
for(i=0;i<frame;i++)
printf("%d\t\t%d\n",i,ftable[i]);
void cphyaddr()
int laddr,paddr,disp,phyaddr,baddr;
getch();
scanf("%d",&baddr);
scanf("%d",&laddr);
if(ptable[paddr].pbit == 1 )
void main()
{
clrscr();
info();
assign();
cphyaddr();
getch();
OUTPUT:
PAGE TABLE
page address frame no .presentBit
0 5 1
1 6 1
2 7 1
3 2 1
FRAME TABLE
0 32555
1 32555
2 3
3 32555
4 32555
5 0
6 1
7 2
PROGRAM:
#include<stdio.h>
struct process
int ps;
int flag;
} p[50];
struct sizes
int size;
int alloc;
s[5];
int main()
int i=0,np=0,n=0,j=0;
printf("\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&s[i].size);
scanf("%d",&np);
printf("/n");
for(i=0;i<np;i++)
scanf("\n%d",&p[i].ps);
for(i=0;i<np;i++)
for(j=0;j<n;j++)
if(p[i].flag!=1)
if(p[i].flag!=1)
if(p[i].ps<=s[j].size)
{
if(!s[j].alloc)
p[i].flag=1;
s[j].alloc=1;
printf("\n\t\t %d\t\t\t%d\t%d\t",i,p[i].ps,s[j].size);
for(i=0;i<np;i++)
if(p[i].flag!=1)
}
OUTPUT:
first fit
023
1 6 10
(B) BESTFIT:
PROGRAM:
#include<stdio.h>
#define MAX 20
int main()
int bsize[MAX],fsize[MAX],nb,nf;
int temp,low=10000;
int i,j;
scanf("%d",&nb);
for(i=1;i<=nb;i++)
scanf("%d", &bsize[i]);
scanf("%d",&nf);
for(i=1;i<=nf;i++)
{
printf("\n enetr the size of file %d",i);
scanf("%d",&fsize[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
if(bflag[j]!=1)
temp=bsize[j]-fsize[i];
if(temp>=0)
if(low>temp)
fflag[i]=j;
low=temp;
bflag[fflag[i]]=1;
low=10000;
printf("\n \n %d \t\t%d\t\t%d\t\t%d",i,fsize[i],fflag[i],bsize[fflag[i]]);
OUTPUT:
1545
2657
3 7 1 10
4 10 3 10
5 12 2 12
(C) . WORST FIT
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
ff[i]=j;
highest=temp;
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
OUTPUT:
Block 1:5
Block 2:2
Block 3:7
File 1:1
File 2:4
1 1 3 7 6
2 4 1 5 1
12.A. PAGE REPLACEMENT ALGORITHMS – FIFO
PROGRAM
#include<stdio.h>
#include<conio.h>
int ssize,fsize,frame[10],rstring[30];
int main()
int i,cs=0,pf=0,y,k,z=0;
void display();
clrscr();
printf("\t\t -------------------------------");
scanf("%d",&fsize);
scanf("%d",&ssize);
for(i=0;i<ssize;i++)
scanf("%d",&rstring[i]);
for(k=0;k<=fsize;k++)
frame[k]=-3;
for(i=0;i<ssize;i++)
y=found(rstring[i]);
if(y==0)
pf++;
if(cs>=fsize)
frame[z%fsize]=rstring[i];
z++;
else if(cs<fsize)
frame[z++]=rstring[i];
cs++;
display();
getch();
int found(int x)
int i,val=0;
for(i=0;i<fsize;i++)
{
if(x==frame[i])
val=1;
break;
return(val);
void display()
int i;
printf("\n");
for(i=0;i<fsize;i++)
if(frame[i]>=0)
printf("%d\t",frame[i]);
else
printf("\t");
}
OUTPUT:
5 5 5 3
8 8 8
4 4
Page fault:4
12. B. PAGE REPLACEMENT ALGORITHMS - LRU
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int fsize,ssize,f,frame[10],arrive[30],rstring[30];
int main()
int i,lfi,idx,cs=0,f,ls=0,pf=0,j=0,y,k,z=0,time=0;
void display();
int leastused();
clrscr();
printf("\n\t\t --------------------");
scanf("%d",&fsize);
scanf("%d",&ssize);
for(i=0;i<ssize;i++)
scanf("%d",&rstring[i]);
for(k=0;k<fsize;k++)
frame[k]=-3;
arrive[k]=0;
for(i=0;i<ssize;i++)
y=pagefound(rstring[i]);
if(y==0)
pf++;
if(cs>=fsize)
lfi=leastused();
frame [lfi]=rstring[i];
arrive [lfi]=++time;
else if (cs<fsize)
frame[cs]=rstring[i];
arrive [cs]=++time;
}
else
idx=pagelocation(rstring[i]);
arrive [idx]=++time;
cs++;
display();
int pagefound(int x)
int i,val=0;
for(i=0;i<fsize;i++)
if(x==frame[i])
val=1;
break;
return(val);
void display()
{
int i;
printf("\n");
for(i=0;i<fsize;i++)
if(frame[i]>=0)
printf("%d",frame[i]);
else
printf("\t");
int leastused()
int i,min=0,n=0;
for(i=1;i<fsize;i++)
if(arrive[i]<arrive[min])
min=i;
n++;
}
if(n==0)
return(0);
else
return(min);
int i,flag=0;
for(i=0;i<fsize;i++)
if(frame[i]==pageno)
flag=1;
break;
return(i);
getch();
}
OUTPUT:
1 1 1 1 1 5
2 2 4 4 4
3 3 3 3
Page fault:5
12.C. PAGE REPLACEMENT ALGORITHMS – LFU(optimal):
PROGRAM
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
clrscr();
printf("\n.........................");
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
clrscr();
printf("\n........................")
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
frm[i]=-1;
optcal[i]=0;
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
printf("\n\tref no %d->\t",ref[i]);
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
flag=1;
break;
if(flag==0)
{
count++;
if(count<=nof)
victim++;
else
victim=optvictim(i);
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
int i,j,temp,notfound;
for(i=0;i<nof;i++)
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
notfound=0;
optcal[i]=j;
break;
if(notfound==1)
return i;
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0;
OUTPUT:
...................................
...................................
................
654214
ref no 6-> 6 -1 -1
ref no 5-> 6 5 -1
ref no 2-> 6 5 4
ref no 1-> 2 5 4
ref no 4-> 1 5 4
PROGRAM:
#include<stdio.h>
main()
int master,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
scanf(“%d”,&master);
for(i=0;i<master;i++)
scanf(“%s”,&d[i]);
for(i=0;i<master;i++)
scanf(“%d”,&s[i]);
for(i=0;i<master;i++)
for(j=0;j<s[i];j++)
scanf(“%s”,&f[I][j]);
printf(“\n”);
printf(“directory\tsize\tfilenames\n”);
printf(“******************************************\n”);
for(i=0;i<master;i++)
printf(“%s\t\t%2d\t”,d[i],s[i]);
for(j=0;j<s[i];j++)
printf(“%s\n\t\t\t”,f[i][j]);
printf(“\n”);
printf(“\t\n”);
OUTPUT:
bbb
ccc
ddd
eee
fff
ggg
cse 3 aaa
bbb
Ccc
it 4 ddd
eee
fff
ggg
13.B. FILE ORGANIZATION TECHNIQUES : TWO LEVEL
DIRECTORY
PROGRAM:
#include<stdio.h>
struct st
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
void main()
int i,j,k,n;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",&dir[i].dname);
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
scanf("%s",&dir[i].fname[j][k]);
printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles");
printf("\n***************************************************
*************\n");
for(i=0;i<n;i++)
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t");
printf("\n\t\t");
}
OUTPUT:
***********************************************************
***
dc 2 afs ged
14.A. FILE ALLOCATION TECHNIQUE-SEQUENTIAL
ALLOCATION
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int st[20],b[20],b1[20],ch,i,j,n,blocks[20][20],sz[20];
char F[20][20],S[20];
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",&F[i]);
scanf("%d",&sz[i]);
scanf("%d",&st[i]);
scanf("%d",&b[i]);
for(i=0;i<n;i++)
b1[i]=(sz[i]*1024)/b[i];
for(i=0;i<n;i++)
for(j=0;j<b1[i];j++)
blocks[i][j]=st[i]+j;
do
scanf("%s",S);
for(i=0;i<n;i++)
if(strcmp(S,F[i])==0)
printf("\nFname\tStart\tNblocks\tBlocks\n");
printf("\n---------------------------------------------\n");
printf("\n%s\t%d\t%d\t",F[i],st[i],b1[i]);
for(j=0;j<b1[i];j++)
printf("%d->",blocks[i][j]);
printf("\n---------------------------------------------\n");
scanf("%d",&ch);
if(ch!=1)
break;
}while(1);
OUTPUT:
---------------------------------------------
---------------------------------------------
PROGRAM:
#include<stdio.h>
void main()
char a[10];
int i,ib,cib[10];
scanf("%s",a);
scanf("%d",&ib);
for(i=1;i<=5;i++)
scanf("%d",&cib[i]);
printf("%s\t\t %d",a,ib);
printf("\n");
for(i=1;i<=5;i++)
printf("%d\t\t",cib[i]);
}
printf("\n");
OUTPUT:
Index block:19
Testing 19
9 16 1 10 25
14.C. FILE ALLOCATION TECHNIQUE-LINKED ALLOCATION
PROGRAM :
#include<stdio.h>
void main()
char a[10];
int i,sb,eb,fb1[10];
scanf("%s",a);
scanf("%d",&sb);
scanf("%d",&eb);
for(i=0;i<5;i++)
scanf("%d",&fb1[i]);
printf("\n %d->",sb);
for(i=0;i<5;i++)
{
printf("%d->",fb1[i]);
printf("%d\n",eb);
}
OUTPUT:
ending
Binary 19 25
PROGRAM:
#include<stdio.h>
main()
clrscr();
scanf(“%d”,&n);
for(i=2;i<n+2;i++)
scanf(“%d”,&t*i+);
for(i=1;i<n+1;i++)
tohm[i]=t[i+1]-t[i];
if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
for(i=1;i<n+1;i++)
tot+=tohm[i];
avhm=(float)tot/n;
for(i=1;i<n+1;i++)
printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);
getch();
}
INPUT
OUTPUT
55 45
58 3
60 2
70 10
18 52
90 72
150 60
160 10
184 24
INPUT
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184
OUTPUT
TRACKS TRAVERSED DIFFERENCE BETWEEN TRACKS
150 50
160 10
184 24
90 94
70 20
60 10
58 2
55 3
18 37
INPUT
Enter the track position : 55 58 60 70 18 90 150 160 184
Enter starting position : 100
OUTPUT
Tracks traversed Difference Between tracks
150 50
160 10
184 24
18 240
55 37
58 3
60 2
70 10
90 20
STEP 1: Install The Oracle VM VirtualBox and Config the Setting As per
User Requierments