Os Record
Os Record
DEPARTMENT OF COMPUTER
APPLICATION
2024-2025
OPERATING SYSTEM LAB
SUBMITTED BY
REG.NO :
NAME :
SUB.CODE :
BONAFIDE CERTIFICATE
B.C.A
2 SHELL PROGRAMMING
5 SEMAPHORES
8 DEADLOCK DETECTIONS
THREADING A
SYNCHORNIZATION
12
APPLICATIONS
Ex. No: 1
BASICUNIX COMMANDS
Date:
AIM:
To write a basic commands in Linux
CODING:
1) date
2) cal
Su Mo Tu We Th Fr Sa
1
2 34 5 6 7 8
9 101112 13 1415
16 1718 19 20 21 22
23 2425 26 27 28 29
30 31
3) Echo
Echo “text”
Output: text
4) Hostname
Output: ubuntu
5)rm
Syn:rm filename
Output: remove file
6)touch
7) cp(copies)
Syn: cp source file to destination file
Output: cp filename
8) mv(rename)
Syn: mv old file to new file
9) more
Syn: more file name
10) clear
Syn:clear
Output: clear the current screen
RESULT:
AIM:
To write a shell program for factorial
ALGORITHM:
Step-4:From the value of the integer upto1, multiply each digit and update the final value
Step-5:The final value at the end of all the multiplication till 1 is the factorial
Read num
Fact=1
While[$num-gt1] Do
Fact=$((fact*num))
Fact=$((num-1))
Done
Echo $fact
OUTPUT:
Enter the number:5
120
RESULT:
AIM:
To write a program for Round Robin scheduling
ALGORITHM:
Step-1:Start the program
Step-2:Declarethevariable
oid main()
{
inti,n,pid[15],bst[15],wait=0,tarnd,ts;
printf("\n Enter the no of process:");
scanf("%d",&n);
printf("\nEnter the values:");
for(i=1;i<=n;i++)
{
printf("\nEnter the process id:");
scanf("%d",&pid[i]);
printf("\n Enter the burst time:");
scanf("%d", &bst[i]);
}
printf("\n Enter the value for time slice:");
scanf("%d",&ts);
printf("\npid\tburst\twait\ttarnd");
for(i=1;i<=n;i++)
{
if(bst[i]>ts)
{
n=n+1;
bst[n]=bst[i]-ts;
bst[i]=bst[i]-bst[n];
pid[n]=pid[i];
}
tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d\t",pid[i],bst[i],wait,tarnd);
wait=tarnd;
}
}
OUTPUT:
Enterthenoofprocess:3
3 4 8 12
1 2 12 14
RESULT:
AIM:
To write a program for shortest job first algorithm
ALGORITHM:
Step-1:Start the program
Step-2:Declarethevariable
oid main()
{
int i,n,j,pid[20],bst[20],wait=0,tarnd,t;
printf("\n enter the number of process:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
printf("enter the process id:");
scanf("%d",&pid[i]);
printf("\n enter the burst time:");
scanf("%d",&bst[i]);
}
printf("\npid\tburst\twait\ttarnd"); for
(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(bst[i]>bst[j])
{
t=bst[i];
bst[i]=bst[j];
bst[j]=t;
t=pid[i];
pid[i]=pid[j];
pid[j]=t;
}
}
}
for(i=1;i<=n;i++)
{
tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d",pid[i],bst[i],wait,tarnd); wait=tarnd;
}
}
OUTPUT:
Enter the number of
process:5
Date:
AIM:
To write the program for First Come First serves scheduling
ALGORITHM:
Step-1:Start the program
Step-2:Declarethevariable
Step-4:Printtheturnaroundtimeusingaaddition
#include<stdio.h>v
oid main()
{
inti,n,pid[5],bst[5],wait=0,tarnd;
scanf("%d",&bst[i]);
}
printf("\npid\tburst\twait\ttarnd");
for(i=1;i<=n;i++)
{
tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d",pid[i],bst[i],wait,tarnd); wait=tarnd;
}
}
OUTPUT:
Enterthenumberofprocessid:5
Enterthebursttime:5
Entertheprocessid:2
Enterthebursttime:5
Entertheprocessid:3
Enterthebursttime:5
Entertheprocessid:4
Enterthebursttime:5
Entertheprocessid:5
Entertheburst time:5
4 5 15 20
5 5 20 25
RESULT:
AIM:
To write a program for Priority scheduling
ALGORITHM:
Step-1:Start the program
oid main()
{
intbt[20],p[20],wt[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat,tat[20];
printf("enter the number of process:");
scanf("%d",&n);
scanf("%d",&pr[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
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=total/n;
total=0;
printf("\nprocess\tbursttime\twaitingtime\tturnaroundtime");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\np[%d]\t%d\t%d\t%d\t",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n;
printf("\n Average Waiting time=%d",avg_wt);
burst time:7
priority:5
p[4]
burst time:6
priority:4
process burst time waiting time turnaround time
p[1] 2 0 2
p[4] 6 2 8
p[3] 7 8 15
p[2] 4 15 19
RESULT:
Date:
AIM:
ALGORITHM:
b) check whether the required location are from the selected location c)
#include<stdlib.h>
void main()
intf[50],i,st,j,len,c,k;
for(i= 0;i<50;i++)
f[i]=0;
x:
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
f[j]=1;
printf("\n%d->%d",j,f[j]);
else
break;
if(j==(st+len))
scanf("%d",&c);
if(c==1)
goto x;
elseexit;
}
OUTPUT:
3->1
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
RESULT:
Date:
AIM:
To write a program for file allocation concept using Indexed allocation techniques
ALGORITHM:
Step-1:Start the program
randomly
oid main()
{
intf[50],i,k,j,inde[50],n,c,count=0,p;
for(i=0;i<50;i++)
f[i]=0;
x:
goto x;
}
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
{
printf("Block already allocated");
goto x;
}
for(j=0;j<n;j++)
f[inde[j]]=1;
printf("\n allocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
printf("enter 1 to enter more file and to exit\t");
scanf("%d",&c);
if(c==1)
goto x;
}
OUTPUT:
Enter index block:5
Enter no of files on index:4
6
7
8
9
allocated
file indexed
5->6:1
5->7:1
5->8:1
5->9:1
Date:
AIM:
To write a program for file allocate concept using linked list technique
ALGORITHM:
Step-1:Start the program
void main()
{
intf[50],p,i,j,k,a,st,len,n,c;
for(i=0;i<50;i++)
f[i]=0;
f[a]=1;
}
x:
printf("\n Enter the starting index block & length");
scanf("%d%d",&st,&len);
k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n%d->file is already allocated" ,j);
k++;
}
}
printf("\n If you want to enter one more file?(yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto x;
}
OUTPUT:
Enterhowmanyblocksthatarealreadyallocated:3
Enter the blocks no.s print are already allocated:68
10
Enterthestartingindexblock&length:310 3-
>1
4->1
5->1
6->file is already allocated
7->1
8->file is already allocated
9->1
10->file is already allocated
11->1
12->1
13->1
14->1
15->1
If you want to enter on file?(yes-1/no-0):0
RESULT:
Date:
AIM:
ALGORITHM:
Step-1:Start the program
oid main()
{
intn,a[5],in,out,pr,cr,ch;
in=out=pr=cr=0;
printf("\n Enter the no of element:");
scanf("%d",&n);
do
{
printf("\n1.proceducer\n2.customer\n3.exit:");
printf("\n Enter the choice:");scanf("%d",&ch);
switch(ch)
{
case 1:
if(in>=n)
printf("\n The Buffer is overflowing");
else
{
pr=1;
in++;
printf("\n Enter the element:");
scanf("%d",&a[in]);
if(in==n)
pr=0;
}
break;
case2:
if(in==out)
printf("\n The buffer is under flowing:"); else if(pr==1)
printf("\nThe Producer process is going on:");
else
{
cr=1;
printf("\nThe element %d is consumer:",a[in]);
in--;
if(in==0)
cr=0;
}
break;
}
}
while(ch!=3);
OUTPUT:
Enterthenoofelement:3
1.proceducer
2.customer
3.exit:
1.proceducer
2.customer
3.exit:
1.proceducer
2.customer
3.exit:
Enterthechoice:1
The Buffer is overflowing
1.proceducer
2.customer
3.exit:
Enterthechoice:2
The element 56 is consumer:
1.proceducer
2.customer
3.exit:
Enterthechoice:2
3.exit:
Enterthechoice:2
2.customer
3.exit:
Enter the choice:2
The buffer is under flowing
1.proceducer
2.customer
3.exit:
Enterthechoice:3
RESULT:
AIM:
ALGORITHM:
#include<stdio.h>
struct
chardname[10],fname[10][10];
int fcnt;
}dir;
void main()
int i,ch;
char f[30];
clrscr();
dir.fcnt=0;
scanf("%s", dir.dname);
while(1)
printf("\n\n1.Create File\t2.DeleteFile\t3.SearchFile\n4.DisplayFiles\t5.Exit\nEnteryourchoice--");
scanf("%d",&ch);
switch(ch)
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f,dir.fname[i])==0)
{
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
if(i==dir.fcnt)
printf("File%snotfound",f);
else
dir.fcnt--;
break;
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f,dir.fname[i])==0)
printf("File%sisfound",f);
break;
if(i==dir.fcnt)
printf("File%snotfound",f);
break;
case 4: if(dir.fcnt==0)
printf("\nDirectory Empty");
else
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
break;
default: exit(0);
getch();
OUTPUT:
File B is deleted
RESULT:
Date:
AIM:
To write a program file organization techniques using Two–level directory
ALGORITHM:
Step-4:Setvariablesgd=DETECT, gm;
struct
chardname[10],fname[10][10];
int fcnt;
}dir[10];
voidmain()
int i,ch,dcnt,k;
charf[30],d[30];
clrscr();
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]);
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)
printf("File %s Is deleted",f);
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)
printf("File %s is found",f);
goto jmp1;
goto jmp1;
jmp1: break;
case 5: if(dcnt==0)
printf("\nNo Directory's");
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);
getch();
OUTPUT:
1.CreateDirectory 2.CreateFile 3.DeleteFile
Directory created
Directory created
1.CreateDirectory 2.CreateFile 3.DeleteFile
File created
File created
File created
Directory Files
DIR1A1A2
DIR2 B1
FileA2is deleted
RESULT:
Date:
AIM:
To write a C program File Organization concept using the technique hierarchical level directory.
ALGORITHM:
#include<stdio.h>
#include<graphics.h>str
uct tree_element
charname[20];
int x,y,ftype,lx,rx,nc,level;
structtree_element*link[5];
};
Typedef structtree_element
intgd=DETECT,gm;
node *root;
root=NULL;clrscr();
create(&root,0,"root",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\\tc\\BGI");
display(root);
getch();
closegraph();
create(node**root,intlev,char*dname,intlx,intrx,intx)
int i,gap;
if(*root==NULL)
(*root)=(node *)malloc(sizeof(node));
gets((*root)->name);
printf("enter1forDir/2forfile:");
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
printf("Noofsubdirectories/files(for%s):",(*root)->name);scanf("%d",&(*root)->nc);
if((*root)->nc==0)
gap=rx-lx;
elsegap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i]),lev+1,(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
else(*root)->nc=0;
display(node*root)
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);if(root!=NULL)
{
for(i=0;i<root->nc;i++)
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
if(root->ftype==1)bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);for(i=0;i<root->nc;i++)
display(root->link[i]);
}
OUTPUT:
No of subdirectories/files(forUSER1):1
No of subdirectories/files(for SUBDIR):2
No of subdirectories/files(forUSER2):2
No of subdirectories/files(forSUBDIR2):2
No of subdirectories/files(for PPL):2
No of subdirectories/files(for AI):2
RESULT:
AIM:
To write a C program File Organization concept using the technique DAG
ALGORITHM:
#include<conio.h>
#include<graphics.h>
#include<string.h>stru
ct tree_element
charname[20];
int x,y,ftype,lx,rx,nc,level;
structtree_element*link[5];
};
Typedef structtree_element
charfrom[20];
char to[20];
}link;link
L[10]; int
nofl;
node*root;
void main()
intgd=DETECT,gm;
root=NULL;clrscr();
create(&root,0,"root",0,639,320);
read_links();
clrscr();
initgraph(&gd,&gm,"c:\\tc\\BGI");
draw_link_lines();
display(root);
getch();
closegraph();
read_links()
inti;
scanf("%d",&nofl);
for(i=0;i<nofl;i++)
printf("File/dir:");
fflush(stdin);
gets(L[i].from);
printf("username:");
fflush(stdin);
gets(L[i].to);
draw_link_lines()
int i,x1,y1,x2,y2;
for(i=0;i<nofl;i++)
search(root,L[i].from,&x1,&y1);
search(root,L[i].to,&x2,&y2);
setcolor(LIGHTGREEN);
setlinestyle(3,0,1);
line(x1,y1,x2,y2);
setcolor(YELLOW);
setline style(0,0,1);
search(node*root,char*s,int*x,int*y)
int i;
if(root!=NULL)
if(strcmpi(root->name,s)==0)
*x=root->x;
*y=root->y;
return;
else
for(i=0;i<root->nc;i++)
search(root->link[i],s,x,y);
create(node**root,intlev,char*dname,intlx,intrx,intx)
int i,gap;
if(*root==NULL)
(*root)=(node*)malloc(sizeof(node));
%s):",dname);fflush(stdin);
gets((*root)->name);
printf("enter 1 for dir/ 2 for
file:");scanf("%d",&(*root)-
>ftype);(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
printf("noofsubdirectories/files(for%s):",(*root)-
>name);scanf("%d",&(*root)->nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i]),lev+1,
(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
else
(*root)->nc=0;
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14); if(root
!=NULL)
for(i=0;i<root->nc;i++)
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
if(root->ftype==1)bar3d(root->x-20,root->y-10,root-
>x+20,root->y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root-
>name);for(i=0;i<root->nc;i++)
display(root->link[i]);
}}}
OUTPUT:
Enter Name of dir/file(under root):ROOT
No of subdirectories/files(for VB):2
No of subdirectories/files(for JAVA):2
File/Dir: B
UserName:USER2
File/Dir: HTML
UserName:USER1
RESULT:
AIM:
ALGORITHM:
Void input()
{
int i,j;
printf("Enter no of processes:");
scanf("%d",&n);
printf("Enter no of resource instances:");
scanf("%d", &r);
printf("Enter the max matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
scanf("%d", &max[i][j]);
}
void show()
{
int i,j;
printf("Process Allocation Maximum Available\n");
for(i=0;i<n;i++)
{
printf("\nP%d:",i);
for(j=0;j<r;j++)
{
printf("%d",all[i][j]);
}
printf("\t");
for(j=0;j<r;j++)
{
printf("%d",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++)
printf("%d",avail[j]);
}
}
}
voidcall()
{
Int finish[20],temp,
need[20][20],flag=1,k,c1=0; int safe[20];
int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
need[i][j]=max[i][j]-all[i][j];
}
printf("\n");
while(flag)
{
flag=0;
for(i=0;i<n;i++)
{
int c=0;
for(j=0;j<r;j++)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{
c++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=all[i][j];
finish[i]=1;flag=1;
}
printf("P%d->",i);
if(finish[i]==1)
{
i=n;
}
} //if
}//if
} //for
} //for
} //while
for(i=0;i<n;i++)
{
if(finish[i]==1)
{
c1++;
}
}
if(c1==n)
{
printf("\n The system is in Safe State");
}
else
{
printf("\n Process are in dead lock");
printf("\nThe System is in unsafe state");
}
}
OUTPUT:
DEADLOCKAVOIDANCE
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 02
2 21
Enter the allocation matrix:
101
111
111
P0 : 101 102 1 11
RESULT:
AIM:
ALGORITHM:
#include<stdio.h>
intmax[20][20],all[20][20],need[20][20],avail[20];
int n,r;
voidinput();
voidshow();
void call();
void main()
{
int i,j;
printf("Deadlock Detection");
input();
show();
call();
getch();
}
voidinput()
{
int i,j;
printf("\nEnter no of processes:");
scanf("%d",&n);
printf("Enter no of resource instances:");
scanf("%d",&r);
void show()
{
int i,j;
printf("Process Allocation Maximum Available\n");
for(i=0;i<n;i++)
{
printf("\nP%d:",i);
for(j=0;j<r;j++)
{
printf("%d ",all[i][j]);
}
printf("\t");
for(j=0;j<r;j++)
{
printf("%d ",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++)
printf("%d ",avail[j]);
}
}
}
voidcall()
{
intfinish[20],temp,need[20][20],flag=1,k;
int dead[20],safe[20];
int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
need[i][j]=max[i][j]-all[i][j];
}
while(flag)
{
flag=0;
for(i=0;i<n;i++)
{
int c=0;
for(j=0;j<r;j++)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{
c++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=all[i][j];
finish[i]=1;flag=1;
}
if(finish[i]==1)
{
i=n;
}//if
} //if
} //if
} //for
} //for
}//while
j=0;
flag=0;
for(i=0;i<n;i++)
{
if(finish[i]==0)
{
dead[j]=i;
j++;
flag=1;
}
}
if(flag==1)
{
printf("\nsystem is in deadlock and the deadlock process are \n");
for(i=0;i<n;i++)
{
printf("P%d :",dead[i]);
}
}
else
printf("\n no deadlock occur");
}
OUTPUT:
DEADLOCKDETECTION
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 11
2 12
Enter the allocation matrix:
100
201
000
P0 : 100 111 0 00
P0 :P1:
RESULT:
Date: FIFO
AIM:
ALGORITHM:
#include<stdio.h>v
oid main()
inta[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
if(p==0)
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
q1=q;
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
p=0;
for(k=0;k<q1;k++)
if(b[i+1]==a[k])
p=1;
printf("\nNo of faults:%d",m);
OUTPUT:
Enterthe10 pagenumbers:1 23 45 12 34 5
1 1-->F
2 12-->F
3 123-->F
4 423-->F
5 453-->F
1 451-->F
2 251-->F
3 231-->F
4 234-->F
5 534-->F
No offaults:10
RESULT:
Date: LRU
AIM:
ALGORITHM:
#include<stdio.h>
void main()
intg=0,a[5],b[20],p=0,q=0,m=0,n,k,i,q1=1,j,u,h;
char f='F';
scanf("%d",&n);
scanf("%d",&b[i]);for(i=0;i<n;i++)
if(p==0)
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
q1=q;
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
p=0;
g=0;
if(q1==3)
for(k=0;k<q1;k++)
if(b[i+1]==a[k])
p=1;
for(j=0;j<q1;j++)
u=0;
k=i;
while(k>=(i-1)&&(k>=0))
if(b[k]==a[j])
u++;
k--;
if(u==0)
q=j;
else
for(k=0;k<q;k++)
{
if(b[i+1]==a[k])
p=1;
printf("\nno.fault:%d",m);
OUTPUT:
Enter12 pagenumber:2 32 1 52 45 32 3 2
2 2-->F
3 23-->F
2 23
1 231-->F
5 251-->F
2 251
4 254-->F
5 254
3 354-->F
2 352-->F
3 352
2 352
no.fault:7
RESULTS:
Date: LFU
AIM:
ALGORITHM:
Step-6:If No Frames Is Free Replace The Page With The Page That Is Least Used
Step-8:Stoptheprogram
CODING:
#include<stdio.h>v
oid main()
intrs[50],i,j,k,m,f,cntr[20],a[20],min,pf=0;
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&rs[i]);
scanf("%d",&f);
for(i=0;i<f;i++)
cntr[i]=0;
a[i]=-1;
for(i=0;i<m;i++)
for(j=0;j<f;j++)
if(rs[i]==a[j])
cntr[j]++;
break;
if(j==f)
min=0;
for(k=1;k<f;k++)
if(cntr[k]<cntr[min])
min=k;
a[min]=rs[i];
cntr[min]=1;
pf++;
printf("\n");
for(j=0;j<f;j++)
printf("\t%d",a[j]);
if(j==f)
printf("\tPFno%d",pf);
OUTPUT:
1 -1 -1 PFno1
1 2 -1 PFno2
1 2 3 PFno3
4 2 3 PFno4
5 2 3 PFno5
5 2 3 PFno5
5 2 3 PFno5
5 2 3 PFno5
5 2 3 PFno5
5 2 1 PFno6
5 2 4 PFno7
5 2 3 PFno8
RESULT:
Date:
AIM:
ALGORITHM:
variables
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/shm.h>
#include<string.h>vo
id main()
int i;
void*shared_memory;
char buff[100];
int shmid;
shmid=shmget((key_t)2345,1024,0666|IPC_CREAT);
shared_memory=shmat(shmid,NULL,0);
read(0,buff,100);
strcpy(shared_memory,buff);
printf("you wrote:%s\n",(char*)shared_memory);
OUTPUT:
Process attached at
0x7f1bf34b3000
Hello World
Date:
AIM:
ALGORITHM:
Step-5:Calculate the physical address using the following physical address=(frame number *Frame
size)+offset.
#include<stdio.h>
#include<conio.h>
Void main()
Intnp,ns,i;
Int *sa;
Clrscr();
Scanf(“%d”,&np);
Scanf(“%d”,&ps);
Sa=(int*)malloc(2*np);
For(i=0;i<np;i++)
Sa[i]=(int)malloc(ps);
Getch();
}
OUTPUT:
Page1 Address:1894
Page2 Address:1902
Page3 Address:1910
Page4 Address:1918
Page5 Address:1926
RESULT:
Date:
AIM:
ALGORITHM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>pt
hread_t tid[2];
int counter;
void*do something(void*arg)
Unsigned longi=0;
counter+=1;
printf("\njob%dstarted\n",counter);
for(i=0;i<(0xFFFFFFFF);i++);
printf("\njob%dfinished\n",counter);
return NULL;
intmain(void)
inti=0;
int err;
while(i<2)
err=pthread_create(&(tid[i]),NULL,&dosomething,NULL);
if(err!=0)
i++;
pthread_join(tid[0],NULL);
pthread_join(tid[1],NULL);
return0;
OUTPUT:
job1 started
job2 started
job2 finished
job2finished
RESULT: