Os Print Word File
Os Print Word File
COMMANDS:
February 2004
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29
Linux
5).[cse053@localhost cse053]$ bc
bc 1.06
3+7
10
[1]+ Stopped bc
6).[cse053@localhost cse053]$ id
uid=552(cse053) gid=552(cse053) groups=552(cse053)
/home/cse053
Hii
NAME
SYNOPSIS
DESCRIPTION
NOTE: your shell may have its own version of echo which will supercede
below
--version
\\ backslash
\a alert BEL
\b backspace
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
AUTHOR
REPORTING BUGS
COPYRIGHT
10).[cse053@localhost cse053]$ ls
hii
hello
welcome
Hii
Hii
hii
hello
welcome
13).[cse053@localhost cse053]$ wc a
3 3 18 a
14).[cse053@localhost cse053]$ cp a b
hii
hello
welcome
15).[cse053@localhost cse053]$ mv a b
hii
hello
welcome
2,3d1
< hello
< welcome
hello
welcome
Hii
welcome
EX NO-2(B) SHELL PROGRAMMING
read no
test=`expr $no % 2`
if [ $test -eq 0 ]
then
echo "This Number Is Even";
else
echo "This Number Is Odd";
fi
OUTPUT:
read count
sum=0
do
read num
count=`expr $count - 1 `
done
echo sum is
echo $sum
OUTPUT:
$ enter count
enter numbers
sum is
8
BIGGEST AMONG 3 NUMBERS
OUTPUT:
321
3 is biggest
ARITHMETIC EXPRESSION EVALUATION
read a
read b
val=`expr $a + $b`
val=`expr $a - $b`
val=`expr $a \* $b`
val=`expr $a / $b`
val=`expr $a % $b`
OUTPUT:
enter a value
enter b value
a+b : 8
a-b : 4
a*b : 12
a/b : 3a%b :
FACTORIAL OF A GIVEN NUMBER
OUTPUT:
[cse053@localhost cse053]$ sh 2e.sh
enter a number
factorial of 5 is 120
EXNO-3
PROGRAM 1: PROGRAM 2:
#include<stdio.h> #include<stdio.h>
#include<unistd.h> #include<unistd.h>
main() main()
{ {
fork(); fork();
printf("Helloworld"); fork();
} fork();
OUTPUT: printf("Helloworld\n");
Helloworld
Helloworld
Helloworld
Helloworld
Helloworld
Helloworld
Helloworld
EXNO-3(B) FORK,EXIT,GETPID,WAIT,CLOSE SYSTEM CALLS
#include<stdio.h> }
#include<stdlib.h> }
main() else
{ {
pid=getpid(); }
pid=fork(); OUTPUT:
for(i=0;i<n;i++) 0
{ 1
b=c;
EXNO-3(C) EXECLP SYSTEM CALL
#include<stdio.h> }
#include<unistd.h> else
#include<sys/wait.h> {
main() wait(NULL);
{ printf("Child complete");
pid=fork(); }
if(pid<0) }
exit(-1);
{ Child complete
execlp("/bin/ls","ls",NULL);
EXNO-3(D) CLOSE SYSTEM CALL
#include<stdio.h> close(fd[1]);
pipe(fd);
OUTPUT:
child=fork();
if(!child)
[cse053@localhost cse053]$ cc ex5a11.c
{
[cse053@localhost cse053]$ ./a.out
close(fd[0]);
write(fd[1],a,5);
Enter the string to enter into the pipe:hii
}
else
The string retrived from the pipi is hii
{
EXNO-4 CPU SCHEDULING ALOGORITHMS
#include<stdio.h> for(i=2;i<=n;i++)
struct process {
{ p[i].wtime=p[i-1].wtime+p[i-1].btime;
} }
p[50]; avg_wait=tot_wait/n;
main() avg_turn=tot_turn/n;
for(i=1;i<=n;i++) printf("%d",p[n].wtime+p[n].btime);
{ printf("\n ................................\n");
printf("\n Enter the burst time of each person:"); printf("process burst time turn around:\n");
scanf("%d",&p[i].btime); for(i=1;i<=n;i++)
} {
i=1; printf("%5d%10d%15d
%15d",i,p[i].btime,p[i].wtime,p[i].ttime);
p[i].wtime=0;
printf("\n");
p[i].ttime=p[i].btime;
}
tot_wait=p[i].wtime;
printf("\n average wait time :%f \n", avg_wait);
tot_turn=p[i].ttime;
printf("\n average turn around time %f \n
",avg_turn);
}
GANTT CHART
1 2 3
OUTPUT:
...............................
0 2 5 9
[cse053@localhost cse053]$ cc ex4a1.c
................................
[cse053@localhost cse053]$ ./a.out
process burst time turn around:
1 2 0 2
Enter no of process3
2 3 2 5
3 4 5 9
Enter the burst time of each person:2
#include<stdio.h> pno[j]=t;
main() t=bs[i];
{ bs[i]=bs[j];
int p; bs[j]=t;
int n; }
int i,j,tot_wt=0,tot_tt=0; }
float avg_wt=0.0,avg_tu=0.0; }
scanf("%d",&p); ft[i]=stt+bs[i];
n=p; wt[i]=stt;
for(i=1;i<=n;i++) tu[i]=wt[i]+bs[i];
{ tot_wt=tot_wt+wt[i];
pno[i]=i; tot_tt=tot_tt+tu[i];
scanf("%d",&bs[i]); }
} avg_wt=tot_wt/n;
for(i=1;i<=n;i++) avg_tu=tot_tt/n;
for(j=i+1;j<=n;j++) printf("\n__________________\n");
{ for(i=1;i<=n;i++)
{ printf("|\t\n");
t=pno[i]; printf("____________________\n");
pno[i]=pno[j]; printf("\n");
for(i=1;i<=n;i++) [cse053@localhost cse053]$ cc ex4b1.c
printf("%d",wt[n]+bs[n]);
printf("\n"); ____________________
printf("\t%f",avg_wt);
printf("\n Avg turn around time in millisec"); pno bursttime(msec),waiting time(msec) turn sround
time(msec)
printf("\t%f",avg_tu);
2 4 0 4
}
1 6 4 10
3 8 10 18
OUTPUT:
avg waiting time in millisec is: 4.000000
PRIORITY SCHEDULING:
#include<stdio.h> at[i]=at[j];
#include<string.h> at[j]=temp;
{ et[i]=et[j];
int et[j]=temp;
et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[1
0]; strcpy(t,pn[i]);
char pn[10][10],t[10]; }
{ if(i==0)
totta+=ta[i]; 4
} 2
ngtime\ttatime"); 7
2 3 7 1 0 7
#include<stdio.h> if(b[i]==0)
main() continue;
{ if(b[i]>t)
int i,n,j=0; {
scanf("%d",&n); b[i]=b[i]-t;
scanf("%d",&t); }
for(i=1;i<=n;i++) else
{ {
scanf("%d",&b[i]); finish=start+b[i];
b1[i]=b[i]; j=j+b[i];
total=total+b[i]; start=finish;
} f[i]=finish;
start=0; w[i]=finish-b1[i];
while(j<total) }
{ }
1 3 0 3
[cse053@localhost cse053]$ cc ex4d11.c
enter no of process3
3 9 8 17
enter the time slice4
AVG WT TIME:5.000000
enter the burst time of process13
AVG TAT:10.6666666
enter the burst time of process25
EXNO-5 INTERPROCESS COMMUNICATION
PROGRAM:
#include<stdio.h> close(fd[1]);
pipe(fd);
OUTPUT:
child=fork();
if(!child)
[cse053@localhost cse053]$ cc ex5a11.c
{
[cse053@localhost cse053]$ ./a.out
close(fd[0]);
write(fd[1],a,5);
Enter the string to enter into the pipe:hello
}
else
The string retrived from the pipi is hello
{
EXNO-5(B) INTERPROCESS COMMUNICATION USING SHARED MEMORY
PROGRAM 1:
#include<stdio.h> #include<unistd.h>
#include<stdlib.h> #include<sys/shm.h>
#include<unistd.h> #include<string.h>
#include<string.h> {
{ void *shared_memory;
PROGRAM:
#define n 3 break;
int }}}
bu[n],a,in=1,out=1,mutex=1,full=0,empty=n,x=0,nc;
int wait(int s)
main()
{
{
return(--s);
int ch;
}
void producer();
int signal(int s)
void consumer();
{
int wait(int);
return(++s);
int signal(int);
}
printf("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
producer()
while(1)
{
{
printf("\nEnterthe item produced by the producer:");
printf("\nENTER YOUR CHOICE");
scanf("%d",&a);
scanf("%d",&ch);
empty=wait(empty);
switch(ch)
mutex=wait(mutex);
{
bu[in]=a;
case 1:if((mutex==1)&&(empty>0))
printf("\nproducer produces the item%d",bu[in]);
producer();
in++;
else
mutex=signal(mutex);
printf("BUFFER IS FULL");
full=signal(full);
break;
}
case 2:if((mutex==1)&&(full>0))
void consumer()
consumer();
{
else
full=wait(full);
printf("BUFFER IS EMPTY");
mutex=wait(mutex);
break;
nc=bu[out];
out++;
OUTPUT:
BUFFER IS FULL
2.CONSUMER
PROGRAM:
#include<stdio.h> {
printf("\n\t");
#include<stdlib.h> for(j=0;j<m;j++)
#include<string.h> {
int available[20]; printf("%d",need[i][j]);
int max[20][20]; }
int allocation[20][20]; }
int need[20][20]; printf("\n\t need calculation completed...");
int main() cntr=0;
{ while(1)
int n,m,i,j,cntr=0,allow=0,no,req1,req2,req3; {
int flag[20]={0},f=0; for(i=0;i<n;i++)
printf("\n\t enter the number of processes:"); {
scanf("%d",&n); allow=0;
printf("enter the number of resources:"); for(j=0;j<m;j++)
scanf("%d",&m); {
printf("\n enter the allocation matrix\n\t"); if(need[i][j]<=available[j]&&flag[i]==0)
for(i=0;i<n;i++) allow=1;
{ else
printf("\n\t"); {
for(j=0;j<m;j++) break;
{ }
scanf("%d",&allocation[i][j]); }
} if(allow==1)
} {
printf("\nEnter MAX matrix : \n\t"); printf("\n\t *****process P%d is safe *****",i);
for(i=0;i<n;i++) available[0]+=allocation[i][0];
{ available[1]+=allocation[i][1];
printf("\n\t"); available[2]+=allocation[i][2];
for(j=0;j<m;j++) flag[i]=1;
{ cntr++;
scanf("%d",&max[i][j]); }
} }
} if(cntr==n)
printf("\n\tEnter Available : "); break;
for(i=0;i<m;i++) }
{ while(1)
printf("\n\tEnter available value of resource %d : ",i); {
scanf("%d",&available[i]); printf("enter requested process:");
} scanf("%d",&no);
printf("\n\t Calculating need...."); printf("\n enter the requested resources:");
for(i=0;i<n;i++) scanf("%d%d%d",&req1,&req2,&req3);
{ if(req1<=need[no][0]&&req2<need[no]
for(j=0;j<m;j++) [1]&&req3<need[no][2])
{ if(req1<available[0]&&req2<available[1]&&req3<ava
need[i][j]=max[i][j]-allocation[i][j]; ilable[2])
} {
} printf("\n\t !!!!!!!GRANTED REQUESTED!!!!!!!!!");
for(i=0;i<n;i++) available[0]=available[0]-req1;
available[1]=available[1]-req2; 211
available[2]=available[2]-req3;
allocation[no][0]=allocation[no][0]+req1; 002
allocation[no][1]=allocation[no][1]+req2;
allocation[no][2]=allocation[no][2]+req3; Enter MAX matrix :
need[no][0]=need[no][0]-req1;
need[no][1]=need[no][1]-req2; 753
need[no][2]=need[no][2]-req3;
} 322
else
printf("\n\t ***Process p%d must be waited!!!",no); 902
else
printf("\n\t ***Error....exceding request allocation 222
***");
printf("\n do you want to continue<yes=1/no=0>:"); 433
scanf("%d",&f);
if(f==0) Enter Available :
break; Enter available value of resource 0 : 3 3 2
}
} Enter available value of resource 1 :
Enter available value of resource 2 :
Calculating need....
743
122
OUTPUT : 600
011
431
need calculation completed...
[cse053@localhost cse053]$ cc ex7.c *****process P1 is safe *****
*****process P3 is safe *****
[cse053@localhost cse053]$ ./a.out *****process P4 is safe *****
*****process P0 is safe *****
*****process P2 is safe *****enter requested
process:1
enter the number of processes:5
enter the number of resources:3 enter the requested resources:5 3 2
PROGRAM:
#include<stdio.h> {
static int mark[20]; int canbeprocessed= 0;
int i, j, np, nr; if(mark[i]!=1)
int main() {
{ for(j=0;j<nr;j++)
int alloc[10][10],request[10] {
[10],avail[10],r[10],w[10]; if(request[i][j]<=w[j])
printf ("\nEnter the no of the process: "); canbeprocessed=1;
scanf("%d",&np); else
printf ("\nEnter the no of resources: "); {
scanf("%d",&nr); canbeprocessed=0;
for(i=0;i<nr; i++) break;
{ }
printf("\nTotal Amount of the Resource R % d: ",i+1); }
scanf("%d", &r[i]); if(canbeprocessed)
} {
printf("\nEnter the request matrix:"); mark[i]=1;
for(i=0;i<np;i++) for(j=0;j<nr;j++)
for(j=0;j<nr;j++) w[j]+=alloc[i][j];
scanf("%d",&request[i][j]); }
printf("\nEnter the allocation matrix:"); }
for(i=0;i<np;i++) }
for(j=0;j<nr;j++) int deadlock=0;
scanf("%d",&alloc[i][j]); for(i=0;i<np;i++)
for(j=0;j<nr;j++) if(mark[i]!=1)
{ deadlock=1;
avail[j]=r[j]; if(deadlock)
for(i=0;i<np;i++) printf("\n Deadlock detected");
{ else
avail[j]-=alloc[i][j]; printf("\n No Deadlock possible");
} }
}
for(i=0;i<np;i++)
{
int count=0; OUTPUT:
for(j=0;j<nr;j++)
{ [cse053@localhost cse053]$ cc ex8.c
if(alloc[i][j]==0)
count++; [cse053@localhost cse053]$ ./a.out
else
break;
}
if(count==nr) Enter the no of the process: 5
mark[i]=1;
} Enter the no of resources: 3
for(j=0;j<nr; j++)
w[j]=avail[j]; Total Amount of the Resource R 1: 7
for(i=0;i<np; i++)
Total Amount of the Resource R 2: 2
Enter the allocation matrix:
Total Amount of the Resource R 3: 6 010
200
Enter the request matrix: 303
000 211
202 002
000
100 Deadlock detected
002
EXNO-9 THREADING
PROGRAM:
#include<stdio.h> {
err=pthread_create(&tid[i],NULL,&createthread,NUL
#include<string.h> L);
#include<pthread.h> if(err!=0)
#include<stdlib.h> printf("\n Cant create thread:[%s]",strerror(err));
#include<unistd.h> else
pthread_t tid[20]; printf("\n Thread created successfully");
void * createthread(void * arg) i++;
{ }
unsigned long i=0; sleep(5);
pthread_t id =pthread_self(); return 0;
if(pthread_equal(id,tid[0])) }
{
printf("\n First thread processing\n");
} OUTPUT:
else
{
printf("\n Second thread processing \n"); [cse053@localhost cse053]$ cc ex9.c
}
for(i=0;i<10000000;i++) [cse053@localhost cse053]$ ./a.out
return NULL;
}
int main(void)
{ Thread created successfully
int i =0; Thread created successfully
int err; First thread processing
while(i<2)
Second thread processing
EXNO-10 PAGING TECHNIQUE
PROGRAM:
int n,size,la,i,pno[10],fno[10],offset,pa,limit,p; }
printf("enter logical address within the limit enter logical address within the limit 15:6
%d:",limit);
enter the pages:0
scanf("%d",&la);
enter the frame no:5
for(i=0;i<n;i++)
enter the pages:1
{
enter the frame no:3
printf("enter the pages:");
enter the pages:2
scanf("%d",&pno[i]);
enter the frame no:8
printf("enter the frame no:");
enter the pages:3
scanf("%d",&fno[i]);
enter the frame no:6
}
pageno frame no
printf("pageno \t frame no");
0 5
for(i=0;i<n;i++)
1 3
{
2 8
printf("\n %d \t\t %d",pno[i],fno[i]);
3 6
}
the page number is 1
p=la/size;
offset is 2
printf("\n the page number is %d",p);
the physical address is 14
offset=la % size;
EXNO-11 MEMORY ALLOCATION METHODS
PROGRAM:
#include<stdio.h> else
printf("Not allocated");
void main() }
{ }
int bsize[10], psize[10], bno, pno, flags[10],
allocation[10], i, j;
for(i = 0; i < 10; i++) OUTPUT:
{
flags[i] = 0;
allocation[i] = -1; [cse053@localhost cse053]$ cc ex11a.c
}
printf("Enter no. of blocks: "); [cse053@localhost cse053]$ ./a.out
scanf("%d", &bno);
printf("\nEnter size of each block: ");
for(i = 0; i < bno; i++)
scanf("%d", &bsize[i]); Enter no. of blocks: 5
printf("\nEnter no. of processes: ");
scanf("%d", &pno); Enter size of each block: 100
printf("\nEnter size of each process: "); 500
for(i = 0; i < pno; i++) 200
scanf("%d", &psize[i]); 300
for(i = 0; i < pno; i++) 600
for(j = 0; j < bno; j++)
if(flags[j] == 0 && bsize[j] >= psize[i]) Enter no. of processes: 4
{
allocation[j] = i; Enter size of each process: 212
flags[j] = 1; 417
break; 112
} 426
printf("\nBlock no.\tsize\t\tprocess no.\t\tsize");
for(i = 0; i < bno; i++) Block no. size process no. size
{ 1 100 Not allocated
printf("\n%d\t\t%d\t\t", i+1, bsize[i]); 2 500 1 212
if(flags[i] == 1) 3 200 3 112
printf("%d\t\t\t%d",allocation[i] 4 300 Not allocated
+1,psize[allocation[i]]); 5 600 2 417
EXNO-11(B) BEST FIT
PROGRAM:
#include<stdio.h> lowest=10000;
int main() }
{ printf("\n Process no\t Process size\t Block no\t
int Block size\t Fragment");
fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=999 for(i=1;i<=np&&parray[i]!=0;i++)
9; printf("\n %d \t\t %d\t\t %d\t\t %d\t\t
static int barray[20],parray[20]; %d",i,p[i],parray[i],b[parray[i]],fragment[i]);
printf("\n\t\t MEMORY MANAGEMENT SCHEME- }
BEST FIT\n");
printf("\n Enter the no of blocks:");
scanf("%d",&nb);
printf("Enter the no.of process:"); OUTPUT:
scanf("%d",&np);
printf("Enter the size of blocks:"); [cse053@localhost cse053]$ cc ex11b.c
for(i=1;i<=nb;i++)
{ [cse053@localhost cse053]$ ./a.out
printf("Block no:%d-",i);
scanf("%d",&b[i]);
} MEMORY MANAGEMENT SCHEME-BEST FIT
printf("\n Enter the size of the processes:");
for(i=1;i<=np;i++) Enter the no of blocks:5
{ Enter the no.of process:4
printf("Process no:%d-",i); Enter the size of blocks:Block no:1-100
scanf("%d",&p[i]); Block no:2-500
} Block no:3-200
for(i=1;i<=np;i++) Block no:4-300
{ Block no:5-600
for(j=1;j<=nb;j++)
{ Enter the size of the processes:Process no:1-212
if(barray[j]!=1) Process no:2-417
{ Process no:3-112
temp=b[j]-p[i]; Process no:4-426
if(temp>=0)
if(lowest>temp) Process no Process size Block no Block size
{ Fragment
parray[i]=j; 1 212 4
300 88
lowest=temp;
2 417 2
}
500 83
} 3 112 3
} 200 88
fragment[i]=lowest; 4 426 5
barray[parray[i]]=1; 600 174
EXNO-11(C) WORST FIT
PROGRAM:
#include<stdio.h> }
int main() }
{ fragment[i]=greatest;
int barray[parray[i]]=1;
fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=999 lowest=10000;
9,greatest; }
static int barray[20],parray[20]; printf("\n Process no\t Process size\t Block no\t
printf("\n\t\t MEMORY MANAGEMENT SCHEME- Block size\t Fragment");
WORST FIT\n"); for(i=1;i<=np&&parray[i]!=0;i++)
printf("\n Enter the no of blocks:"); printf("\n %d \t\t %d\t\t %d\t\t %d\t\t
scanf("%d",&nb); %d",i,p[i],parray[i],b[parray[i]],fragment[i]);
printf("Enter the no.of process:"); }
scanf("%d",&np); OUTPUT:
printf("Enter the size of blocks:");
for(i=1;i<=nb;i++)
{ [cse053@localhost cse053]$ cc ex11c.c
printf("Block no:%d-",i);
scanf("%d",&b[i]); [cse053@localhost cse053]$ ./a.out
}
printf("\n Enter the size of the processes:");
for(i=1;i<=np;i++)
{ MEMORY MANAGEMENT SCHEME-WORST FIT
printf("Process no:%d-",i);
scanf("%d",&p[i]); Enter the no of blocks:5
} Enter the no.of process:4
for(i=1;i<np;i++) Enter the size of blocks:Block no:1-100
{ Block no:2-500
for(j=1;j<=nb;j++) Block no:3-200
{ Block no:4-300
if(barray[j]!=1) Block no:5-600
{
temp=b[j]-p[i]; Enter the size of the processes:Process no:1-212
if(temp>=0) Process no:2-417
if(greatest<temp) Process no:3-112
{ Process no:4-426
parray[i]=j;
greatest=temp; Process no Process size Block no Block size
} Fragment
1 212 5 600 388
EXNO-12 PAGE REPLACEMENT ALGORITHMS
PROGRAM:
#include<stdio.h>
int main()
{ OUTPUT:
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\nEnter the number of pages:\n"); [cse053@localhost cse053]$ cc ex12a.c
scanf("%d",&n);
printf("\n Enter the page number:"); [cse053@localhost cse053]$ ./a.out
for(i=0;i<n;i++)
scanf("%d",&a[i]); Enter the number of pages:
printf("\nEnter the no of frames:"); 12
scanf("%d",&no);
for(i=0;i<n;i++) Enter the page number:
frame[i]=-1; 1
j=0; 2
printf("Ref string \t page frames"); 3
for(i=1;i<n;i++) 4
{ 5
printf("%d\t\t",a[i]); 6
avail=0; 7
for(k=0;k<no;k++) 8
if(frame[k]==a[i]) 9
avail=1; 10
if(avail==0) 11
{ 12
frame[j]=a[i];
j=(j+1)%no; Enter the no of frames:4
count++; Ref string page frames
for(k=0;k<no;k++) 3 3 -1 -1 -1
printf("%d\t",frame[k]); 4 3 4 -1 -1
} 5 3 4 5 -1
printf("\n"); 6 3 4 5 6
} 7 7 4 5 6
printf("Page fault is %d",count); 8 7 8 5 6
return 0; 9 7 8 9 6
} 10 7 8 9 10
11 11 8 9 10
12 11 12 9 10
Page fault is 10
#include<stdio.h> for(r=0;r<f;r++)
int main() {
{ for(j=r;j<f;j++)
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:"); if(b[r]<b[j])
scanf("%d",&n); {
printf("Enter the reference string:"); t=b[r];
for(i=0;i<n;i++) b[r]=b[j];
scanf("%d",&p[i]); b[j]=t;
printf("Enter no of frames:"); }
scanf("%d",&f); }
q[k]=p[k]; }
printf("\n\t%d\n",q[k]); for(r=0;r<f;r++)
c++; {
k++; if(c2[r]==b[0])
for(i=1;i<n;i++) q[r]=p[i];
{ printf("\t%d",q[r]);
c1=0; }
for(j=0;j<f;j++) printf("\n");
{ }
if(p[i]!=q[j]) }
c1++; }
} printf("\nThe no of page faults is %d",c);
if(c1==f) }
{
c++; OUTPUT:
if(k<f)
{ [cse053@localhost cse053]$ cc ex12b.c
q[k]=p[i];
k++; [cse053@localhost cse053]$ ./a.out
for(j=0;j<k;j++)
printf("\t%d",q[j]); Enter no of pages:12
printf("\n"); Enter the reference string:1 2 3 4 5 6 7 8 9 10 11 12
} Enter no of frames:4
else
{ 1
for(r=0;r<f;r++) 1 2
{ 1 2 3
c2[r]=0; 1 2 3 4
for(j=i-1;j<n;j--) 5 2 3 4
{ 5 6 3 4
if(q[r]!=p[j]) 5 6 7 4
c2[r]++; 5 6 7 8
else 9 6 7 8
break; 9 10 7 8
} 9 10 11 8
} 9 10 11 12
for(r=0;r<f;r++)
b[r]=c2[r]; The no of page faults is 4
EXNO-12(C) LFU PAGE REPLACEMENT
PROGRAM:
#include<stdio.h> int j;
struct frame for(j=0;j<3;j++)
{ {
int val; if(f[j].val==page_seq[i])
int freq; return j;
int pos; }
}f[30]; return -1;
int no_frame,no_page,page_seq[100],page_fault=0; }
void input(){ int position()
int i; {
printf("\n\n least frequently used"); int i,j=0,k;
printf("\n Enter no of frames"); for(i=0;i<3;i++)
scanf("%d",&no_frame); {
printf("\nEnter no of pages"); if(f[i].pos==-1)
scanf("%d",&no_page); return i;
printf("Enter page sequence"); }
for(i=0;i<3;i++) for(i=0;i<3;i++)
scanf("%d",&page_seq[i]); {
printf("\n"); if(f[j].freq>f[i].freq)
for(i=0;i<3;i++){ {
f[i].pos=-1; j=i;
f[i].val=-1; } }
f[i].freq=0; k=j;
} for(i=0;i<3;i++)
} {
void display() if(f[j].freq==f[i].freq&&j!=i)
{ {
static int preev_page_fault=0; if(f[j].pos>f[i].pos)
int i; j=i;
for(i=0;i<3;i++) }
{ k=j;
if(f[i].val==-1) return k;
{ }
printf("0"); return 0;
} }
else void LFU()
{ {
printf("%d",f[i].val); int i,k;
} input();
} for(i=0;i<3;i++)
if(preev_page_fault!=page_fault) {
{ k=search(i);
printf("F"); if(k!=-1)
preev_page_fault=page_fault; {
} f[k].freq++;
printf("\n"); f[k].pos=i;
} }
int search(int i) if(k==-1)
{ {
k=position();
f[k].pos=i;
f[k].val=page_seq[i]; [cse053@localhost cse053]$ cc ex12c.c
f[k].freq=1;
page_fault++; [cse053@localhost cse053]$ ./a.out
}
display();
}
Least frequently used
}
Enter no of frames3
int main()
{
Enter no of pages4
LFU();
Enter page sequence7
printf("\n The no. of page faults %d",page_fault);
8
}
9
}
700F
780F
789F
PROGARM:
#include<stdio.h>
int main()
{
int master,s[20]; OUTPUT:
char f[20][20][20];
char d[20][20];
int i,j; [cse053@localhost cse053]$ cc ex13a.c
printf("enter number of directories:");
scanf("%d",&master); [cse053@localhost cse053]$ ./a.out
printf("enter names of directories:");
for(i=0;i<master;i++)
scanf("%s",&d[i]); enter number of directories:2
printf("enter size of directories:"); enter names of directories:abc
for(i=0;i<master;i++) def
scanf("%d",&s[i]); enter size of directories:2
printf("enter the file names:"); 4
for(i=0;i<master;i++) enter the file names:a
for(j=0;j<s[i];j++) b
scanf("%s",&f[i][j]); c
printf("\n"); d
printf("directory\tsize\tfilename\n"); e
printf("************************************* f
*\n");
for(i=0;i<master;i++) directory size filename
{ **************************************
printf("%s\t\t%2d\t",d[i],s[i]); abc 2 a
for(j=0;j<s[i];j++) b
printf("%s\n\t\t\t",f[i][j]);
printf("\n"); def 4 c
} d
printf("\t\n"); e
} f
#include<stdio.h> printf("%s\t",dir[i].fname[j][k]);
struct st printf("\n\t\t");
{ }
char dname[10]; printf("\n");
char sdname[10][10]; }
char fname[10][10][10]; }
int ds,sds[10];
}dir[10];
int main()
{
int i,j,k,n; OUTPUT:
printf("enter number of directories");
scanf("%d",&n);
for(i=0;i<n;i++) [cse053@localhost cse053]$ cc ex13b.c
{
printf("enter directory %d [cse053@localhost cse053]$ ./a.out
names:",i+1);scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds); enter number of directories2
for(j=0;j<dir[i].ds;j++) enter directory 1 names:aaa
{ enter size of directories:2
printf("enter subdirectionary name and size:"); enter subdirectionary name and size:ab
scanf("%s",&dir[i].sdname[j]); 2
scanf("%d",&dir[i].sds[j]); enter file name:aa
for(k=0;k<dir[i].sds[j];k++) enter file name:bb
{ enter subdirectionary name and size:bc
printf("enter file name:"); 1
scanf("%s",&dir[i].fname[j][k]); enter file name:cc
} enter directory 2 names:xyz
} enter size of directories:2
} enter subdirectionary name and size:xx
printf("\nDIRNAME\t\tSIZE\tSUBDIRNAME\tSIZE\ 1
tFILES"); enter file name:ss
printf("\ enter subdirectionary name and size:yz
n****************************************** 1
***********\n"); enter file name:as
for(i=0;i<n;i++)
{ DIRNAME SIZE SUBDIRNAME SIZE FILES
printf("%s\t\t%d",dir[i].dname,dir[i].ds); *******************************************
for(j=0;j<dir[i].ds;j++) **********
{ aaa 2 ab 2 aa bb
printf("\t%s\t\t%d\ bc 1 cc
t",dir[i].sdname[j],dir[i].sds[j]);for(k=0;k<dir[i].sds[j];
k++) xyz 2 xx 1 ss
yz 1 as
PROGRAM:
#include<stdio.h> if(i!=0)
#include<fcntl.h> start++;
#include<string.h> printf("\n %s\t\t %d\t %d\t %d\
int main() n",name[i],temp,start,n[i]);
{ }
char buff[10][10],name[10][10]; }
int fp,n[20],start=0,num,i,temp;
printf("\n Enter the number of file:");
scanf("%d",&num); OUTPUT:
for(i=0;i<num;i++)
{
printf("\n enter the name of the file %d:",i+1); [cse053@localhost cse053]$ cc ex14a.c
scanf("%s",&name[i]);
fp=open(name[i],O_RDONLY); [cse053@localhost cse053]$ ./a.out
read(fp,buff[i],100);
n[i]=strlen(buff[i]);
printf("%d",n[i]); Enter the number of file:2
} enter the name of the file 1:f1
printf("\nFile name\t Start\tEnd\tLength\n"); 0
for(i=0;i<num;i++) enter the name of the file 2:f2
{ 0
if(i==0) File name Start End Length
temp=0;
else f1 0 -1 0
temp=start+1;
start=start+n[i]-1; f2 0 -1 0
#include<stdio.h> }
struct file
{ OUTPUT:
char fname[10];
int start,size,block[10];
}f[10]; [cse053@localhost cse053]$ cc ex14b.c
int main()
{ [cse053@localhost cse053]$ ./a.out
int i,j,n;
printf("\n enter no of files:");
scanf("%d",&n);
for(i=0;i<n;i++) enter no of files:2
{
printf("\n enter file name:"); enter file name:f1
scanf("%s",&f[i].fname);
printf("\n enter starting block:"); enter starting block:20
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start; enter no of blocks:3
printf("\n enter no of blocks:");
scanf("%d",&f[i].size); enter block numbers:5
printf("\n enter block numbers:"); 10
for(j=1;j<=f[i].size;j++) 20
{
scanf("%d",&f[i].block[j]); enter file name:f2
}
} enter starting block:30
printf("\n file \t start \t size \t block \n");
for(i=0;i<n;i++) enter no of blocks:2
{
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size); enter block numbers:10
for(j=1;j<=f[i].size-1;j++) 20
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]); file start size block
printf("\n"); f1 20 3 5--->10--->20
} f2 30 2 10--->20
PROGRAM:
#include<stdio.h> }
#include<stdlib.h>
int main()
{ OUTPUT:
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n"); [cse053@localhost cse053]$ cc ex15a.c
scanf("%d",&n);
printf("Enter the Requests sequence\n"); [cse053@localhost cse053]$ ./a.out
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n"); Enter the number of Requests
scanf("%d",&initial); 7
for(i=0;i<n;i++) Enter the Requests sequence
{ TotalHeadMoment=TotalHeadMoment+abs(RQ[i]- 82
initial); 170
initial=RQ[i]; 43
} 140
24
printf("Total head moment is 16
%d",TotalHeadMoment); 190
return 0; Enter initial head position
50
Total head moment is 642
EXNO-15(B) SSTF:
PROGRAM:
#include<stdio.h> count++;
#include<stdlib.h> }
int main()
{ printf("Total head movement is
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0; %d",TotalHeadMoment);
printf("Enter the number of Requests\n"); return 0;
scanf("%d",&n); }
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n"); OUTPUT:
scanf("%d",&initial);
[cse053@localhost cse053]$ cc ex15b.c
while(count!=n)
{ [cse053@localhost cse053]$ ./a.out
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial); Enter the number of Requests
if(min>d) 7
{ Enter the Requests sequence
min=d; 82
index=i; 170
} 43
140
} 24
TotalHeadMoment=TotalHeadMoment+min; 16
initial=RQ[index]; 190
Enter initial head position
RQ[index]=1000; 50
Total head movement is 208
EXNO-15(C) SCAN
PROGRAM:
#include<stdio.h> initial=RQ[i];
#include<stdlib.h> }
int main()
{ TotalHeadMoment=TotalHeadMoment+abs(size-
int RQ[i-1]-1);
RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move; initial = size-1;
printf("Enter the number of Requests\n"); for(i=index-1;i>=0;i--)
scanf("%d",&n); {
printf("Enter the Requests sequence\n"); TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
for(i=0;i<n;i++) initial);
scanf("%d",&RQ[i]); initial=RQ[i];
printf("Enter initial head position\n");
scanf("%d",&initial); }
printf("Enter total disk size\n"); }
scanf("%d",&size);
printf("Enter the head movement direction for high else
1 and for low 0\n"); {
scanf("%d",&move); for(i=index-1;i>=0;i--)
{
for(i=0;i<n;i++) TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
{ initial);
for(j=0;j<n-i-1;j++) initial=RQ[i];
{ }
if(RQ[j]>RQ[j+1])
{ TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-
int temp; 0);
temp=RQ[j]; initial =0;
RQ[j]=RQ[j+1]; for(i=index;i<n;i++)
RQ[j+1]=temp; {
} TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial);
} initial=RQ[i];
}
}
int index; }
for(i=0;i<n;i++)
{ printf("Total head movement is
if(initial<RQ[i]) %d",TotalHeadMoment);
{ return 0;
index=i; }
break;
}
}
OUTPUT:
if(move==1)
{ [cse053@localhost cse053]$ cc ex15c.c
for(i=index;i<n;i++)
{ [cse053@localhost cse053]$ ./a.out
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial);
190
Enter the number of Requests Enter initial head position
7 50
Enter the Requests sequence Enter total disk size
82 200
170 Enter the head movement direction for high 1 and
43 for low 0
140 0
24 Total head movement is 240
16
EXNO-15(D) C- SCAN
PROGRAM:
#include<stdio.h> {
#include<stdlib.h> TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
int main() initial);
{ initial=RQ[i];
int }
RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n"); TotalHeadMoment=TotalHeadMoment+abs(size-
scanf("%d",&n); RQ[i-1]-1);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++) TotalHeadMoment=TotalHeadMoment+abs(size-1-
scanf("%d",&RQ[i]); 0);
printf("Enter initial head position\n"); initial=0;
scanf("%d",&initial); for( i=0;i<index;i++)
printf("Enter total disk size\n"); {
scanf("%d",&size); TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
printf("Enter the head movement direction for high initial);
1 and for low 0\n"); initial=RQ[i];
scanf("%d",&move);
}
}
for(i=0;i<n;i++)
{ else
for( j=0;j<n-i-1;j++) {
{ for(i=index-1;i>=0;i--)
if(RQ[j]>RQ[j+1]) {
{ TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
int temp; initial);
temp=RQ[j]; initial=RQ[i];
RQ[j]=RQ[j+1]; }
RQ[j+1]=temp;
} TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-
0);
}
} TotalHeadMoment=TotalHeadMoment+abs(size-1-
0);
int index; initial =size-1;
for(i=0;i<n;i++) for(i=n-1;i>=index;i--)
{ {
if(initial<RQ[i]) TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
{ initial);
index=i; initial=RQ[i];
break;
} }
} }
EXNO-15(E) LOOK
PROGRAM:
#include<stdio.h> }
#include<stdlib.h>
int main() for(i=index-1;i>=0;i--)
{ {
int TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move; initial);
printf("Enter the number of Requests\n"); initial=RQ[i];
scanf("%d",&n);
printf("Enter the Requests sequence\n"); }
for(i=0;i<n;i++) }
scanf("%d",&RQ[i]);
printf("Enter initial head position\n"); else
scanf("%d",&initial); {
printf("Enter total disk size\n"); for(i=index-1;i>=0;i--)
scanf("%d",&size); {
printf("Enter the head movement direction for high TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
1 and for low 0\n"); initial);
scanf("%d",&move); initial=RQ[i];
}
for(i=0;i<n;i++)
{ for(i=index;i<n;i++)
for(j=0;j<n-i-1;j++) {
{ TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
if(RQ[j]>RQ[j+1]) initial);
{ initial=RQ[i];
int temp;
temp=RQ[j]; }
RQ[j]=RQ[j+1]; }
RQ[j+1]=temp;
} printf("Total head movement is
%d",TotalHeadMoment);
} return 0;
} }
int index;
for(i=0;i<n;i++) OUTPUT:
{
if(initial<RQ[i]) [cse053@localhost cse053]$ cc ex15e.c
{
index=i; [cse053@localhost cse053]$ ./a.out
break;
}
}
Enter the number of Requests
if(move==1) 7
{ Enter the Requests sequence
for(i=index;i<n;i++) 82
{ 170
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]- 43
initial); 140
initial=RQ[i]; 24
16 200
190 Enter the head movement direction for high 1 and
Enter initial head position for low 0
50 0
Enter total disk size Total head movement is 208
EXNO-15(F) C - LOOK
PROGRAM:
#include<stdio.h> for(i=index;i<n;i++)
#include<stdlib.h> {
int main() TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
{ initial);
int initial=RQ[i];
RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move; }
printf("Enter the number of Requests\n");
scanf("%d",&n); for( i=0;i<index;i++)
printf("Enter the Requests sequence\n"); {
for(i=0;i<n;i++) TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
scanf("%d",&RQ[i]); initial);
printf("Enter initial head position\n"); initial=RQ[i];
scanf("%d",&initial);
printf("Enter total disk size\n"); }
scanf("%d",&size); }
printf("Enter the head movement direction for high
1 and for low 0\n"); else
scanf("%d",&move); {
for(i=index-1;i>=0;i--)
{
for(i=0;i<n;i++) TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
{ initial);
for( j=0;j<n-i-1;j++) initial=RQ[i];
{ }
if(RQ[j]>RQ[j+1])
{ for(i=n-1;i>=index;i--)
int temp; {
temp=RQ[j]; TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
RQ[j]=RQ[j+1]; initial);
RQ[j+1]=temp; initial=RQ[i];
}
}
} }
}
printf("Total head movement is
int index; %d",TotalHeadMoment);
for(i=0;i<n;i++) return 0;
{ }
if(initial<RQ[i])
{
index=i; OUTPUT:
break;
} [cse053@localhost cse053]$ cc ex15f.c
}
[cse053@localhost cse053]$ ./a.out
if(move==1)
{ Enter the number of Requests
7 Enter initial head position
Enter the Requests sequence 50
82 Enter total disk size
170 200
43 Enter the head movement direction for high 1 and
140 for low 0
24 0
16 Total head movement is 316
190