43
Sr. No Assignment Name 01. Write the simulation program for scheduling algorithm using FCFS. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Waiting time for each process and average times. 02. Write the simulation program for scheduling algorithm using FCFS. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and Turnaround time for each process and average Turnaround time. 03. Write the simulation program for non- preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Waiting time for each process and average times 04. Write the simulation program for non-preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Turnaround Time for each process and average time. 05. Write the simulation program for non-preemptive scheduling algorithm using Priority. The arrival time, first CPU bursts and process priority of different jobs should be input to the system. The output should give the Grant chart and Waiting Time for each process and average times 06. Write the simulation program for non-preemptive scheduling algorithm using Priority. The arrival time, first CPU bursts and process priority of different jobs should be input to the system. The output should give the Grant chart and Turnaround Time for each process and average times 07. Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk

Syspro

Embed Size (px)

Citation preview

Page 1: Syspro

Sr. No Assignment Name01. Write the simulation program for scheduling algorithm using FCFS. The arrival time

and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Waiting time for each process and average times.

02. Write the simulation program for scheduling algorithm using FCFS. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and Turnaround time for each process and average Turnaround time.

03. Write the simulation program for non- preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Waiting time for each process and average times

04. Write the simulation program for non-preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Grant chart and Turnaround Time for each process and average time.

05. Write the simulation program for non-preemptive scheduling algorithm using Priority. The arrival time, first CPU bursts and process priority of different jobs should be input to the system. The output should give the Grant chart and Waiting Time for each process and average times

06. Write the simulation program for non-preemptive scheduling algorithm using Priority. The arrival time, first CPU bursts and process priority of different jobs should be input to the system. The output should give the Grant chart and Turnaround Time for each process and average times

07. Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head moment and current head position from the user. Display the list of request in the order in which it isServed. Also display the total number of head moments

Page 2: Syspro

ASSIGNMENT NO :-1

#include<stdio.h>#include<conio.h>void main(){int i,n,ar[10],b[10],m,sum=0,t;float avg;clrscr();printf("\n ** Enter The Number of Processes ==>> ");scanf("%d",&n);printf("\n ** Enter The Processs / CPU Arival Time & CPU Burst Time ==>> \n ");for(i=1;i<=n;i++){scanf("\n %d%d",&ar[i],&b[i]);}printf("\n*************************************** \n");printf("\n ** Gantt Chart ** \n");printf("\n--------------------|\n");for(i=1;i<=n;i++){printf("| p%d",i);}printf("\n--------------------|\n");printf("\n*********************************** \n");printf("\n ** Avg Turn arround Time ** \n ");m=0;for(i=1;i<=n;i++){m=m+b[i];printf("\n For p%d ==>> ",i);printf("\t%d \n ",m);sum=sum+m;}avg=(float)sum/n;printf("\n ** Avg Turn Arround Time ==>> %f \n ",avg);printf("\n********************************* \n");getch();

Page 3: Syspro

}

Output: ** Enter The Number of Processes ==>> 3

** Enter The Processs / CPU Arival Time & CPU Burst Time ==>> 1 24 2 3 3 3

**************************************************** ** Gantt Chart **--------------------|| p1| p2| p3--------------------|*************************************************** ** Avg Turn arround Time **

For p1 ==>> 24

For p2 ==>> 27

For p3 ==>> 30

** Avg Turn Arround Time ==>> 27.000000

Page 4: Syspro

ASSIGNMENT NO :-2

#include<stdio.h>#include<conio.h>void main(){int i,n,ar[10],b[10],m,sum=0,t;float avg;clrscr();printf("\n ** Enter The Number of Processes ==>> ");scanf("%d",&n);printf("\n ** Enter The Processs / CPU Arival Time & CPU Burst Time ==>> \n ");for(i=1;i<=n;i++){scanf("\n %d%d",&ar[i],&b[i]);}printf("\n**************************************** \n");printf("\n ** Gantt Chart ** \n");printf("\n--------------------|\n");for(i=1;i<=n;i++){printf("| p%d",i);}printf("\n--------------------|\n");printf("\n******************************************* \n");printf("\n ** Avg Waiting Time ** \n ");m=0;sum=0;

Page 5: Syspro

for(i=1;i<=n;i++){m=m+b[i];t=m-b[i];printf("\n * For p%d ==>> ",i);printf("\t%d \n ",t);sum=sum+t;}avg=(float)sum/n;printf("\n ** Avg Waiting Time ==>> %f \n ",avg);printf("\n******************************************** \n");getch(); }

Output: ** Enter The Number of Processes ==>> 4

** Enter The Processs / CPU Arival Time & CPU Burst Time ==>> 1 12 2 3 3 8 4 5*************************************************** ** Gantt Chart **--------------------|| p1| p2| p3| p4--------------------|*************************************************** ** Avg Waiting Time **

* For p1 ==>> 0

* For p2 ==>> 12

* For p3 ==>> 15

Page 6: Syspro

* For p4 ==>> 23

** Avg Waiting Time ==>> 12.500000

ASSIGNMENT NO :-3

#include<stdio.h>#include<conio.h>void main(){ int p[10],a[10],b[10],wt[10],i,j,t,t1,n,w=0,at=0,c[10],s=0; float avg; clrscr(); printf("\n ** Enter The Number of Process ==>> "); scanf("%d",&n); for(i=0;i<n;i++) {

printf("\n ** Enter Proccess Name ==>> "); scanf("%d",&p[i]); printf("\n ** Enter Proccess Arrival Time ==>> "); scanf("%d",&a[i]);

Page 7: Syspro

printf("\n ** Enter Proccess Bust Time ==>> "); scanf("%d",&b[i]);

} for(i=0;i<n;i++) {

for(j=0;j<n-1;j++) { if(b[j]>b[j+1]) {

t=b[j]; b[j]=b[j+1]; b[j+1]=t; t1=p[j]; p[j]=p[j+1]; p[j+1]=t1;

} }

} rintf("\n***********************************************\n"); printf("\n ** Gantt Chart ** "); printf("\n------------------------\n"); for(i=0;i<n;i++) {

printf("| p%d",p[i]); } printf("\n------------------------\n"); j=0; for(i=0;i<n;i++) {

wt[i]=j; j=j+b[i];

} printf("\n***********************************************\n"); printf("\n Process Arrival Time Bust Time Wait Time "); for(i=0;i<n;i++) {

printf("\n\n\t%d\t\t%d\t\t%d\t\t%d",p[i],a[i],b[i],wt[i]); } printf("\n************************************************\n");

printf("\n ** Avg Wating Time ** \n ");

Page 8: Syspro

for(i=0;i<n;i++) {

w=w+wt[i]; } avg=w/n; printf("\n ** Avrage Waiting Time ==>> %f \n ",avg); printf("\n***********************************************\n"); getch();}

Output: ** Enter Proccess Name ==>> 1 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 6 ** Enter Proccess Name ==>> 2 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 8 ** Enter Proccess Name ==>> 3 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 7 ** Enter Proccess Name ==>> 4 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 3

** Gantt Chart **------------------------| p4| p1| p3| p2------------------------****************************************************************

Process Arrival Time Bust Time Wait Time

4 0 3 0

1 0 6 3

Page 9: Syspro

3 0 7 9

2 0 8 16****************************************************************

** Avg Wating Time **

** Avrage Waiting Time ==>> 7.000000*****************************************************************

ASSIGNMENT NO :-4#include<stdio.h>#include<conio.h>void main(){ int p[10],a[10],b[10],wt[10],i,j,t,t1,n,w=0,at=0,c[10],s=0; float avg; clrscr(); printf("\n ** Enter The Number of Process ==>> "); scanf("%d",&n); for(i=0;i<n;i++) {

printf("\n ** Enter Proccess Name ==>> ");

Page 10: Syspro

scanf("%d",&p[i]); printf("\n ** Enter Proccess Arrival Time ==>> "); scanf("%d",&a[i]); printf("\n ** Enter Proccess Bust Time ==>> "); scanf("%d",&b[i]);

} for(i=0;i<n;i++) {

for(j=0;j<n-1;j++) { if(b[j]>b[j+1]) {

t=b[j]; b[j]=b[j+1]; b[j+1]=t; t1=p[j]; p[j]=p[j+1]; p[j+1]=t1;

} }

} printf("\n**********************************************************\n"); printf("\n ** Gantt Chart ** "); printf("\n------------------------\n"); for(i=0;i<n;i++) {

printf("| p%d",p[i]); } printf("\n------------------------\n"); j=0; for(i=0;i<n;i++) {

wt[i]=j; j=j+b[i];

} printf("\n**********************************************************\n"); printf("\n Process Arrival Time Bust Time Wait Time "); for(i=0;i<n;i++) {

printf("\n\n\t%d\t\t%d\t\t%d\t\t%d",p[i],a[i],b[i],wt[i]); }

Page 11: Syspro

printf("\n**********************************************************\n");

printf("\n ** Avg Turn Around Time ** \n "); for(i=0;i<n;i++) {

at=at+b[i]; c[i]=at;

} for(i=0;i<n;i++) {

s=s+c[i]; } avg=(float)s/n; printf("\n ** Avrage Turn Arround Time ==>> %f \n ",avg); printf("\n**********************************************************\n");

getch();

Output: ** Enter Proccess Name ==>> 1 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 12 ** Enter Proccess Name ==>> 2 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 3 ** Enter Proccess Name ==>> 3 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 8 ** Enter Proccess Name ==>> 4 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 5************************************************************** ** Gantt Chart **------------------------| p2| p4| p3| p1------------------------****************************************************************

Process Arrival Time Bust Time Wait Time

2 0 3 0

Page 12: Syspro

4 0 5 3

3 0 8 8

1 0 12 16****************************************************************

** Avg Turn Around Time ** ** Avrage Turn Arround Time ==>> 13.750000

****************************************************************

ASSIGNMENT NO :-5

#include<stdio.h>#include<conio.h>void main(){ int p[10],a[10],pr[10],b[10],wt[10],i,j,t,t1,n,w=0,at=0,c[10],s=0; float avg; clrscr(); printf("\n ** Enter Number of Jobs in Ready Queue ==>> ");

Page 13: Syspro

scanf("%d",&n); for(i=0;i<n;i++) {

printf("\n ** Eenter Proccess Number ==>> "); scanf("%d",&p[i]); printf("\n ** Enter Proccess Arrival Time ==>> "); scanf("%d",&a[i]); printf("\n ** Enter Proccess Bust Time ==>> "); scanf("%d",&b[i]); printf("\n ** Enter Priority of Job ==>> "); scanf("%d",&pr[i]);

} for(i=0;i<n;i++) {

for(j=0;j<n-1;j++) { if(pr[j]>pr[j+1]) {

t=pr[j]; pr[j]=pr[j+1]; pr[j+1]=t; t1=p[j]; p[j]=p[j+1]; p[j+1]=t1; t=a[j]; a[j]=a[j+1]; a[j+1]=t; t=b[j]; b[j]=b[j+1]; b[j+1]=t;

} }

} printf("\n*************************************************** \n"); printf("\n ** Gantt Chart ** "); printf("\n------------------------\n"); for(i=0;i<n;i++) {

printf("| p%d",p[i]); } printf("\n------------------------\n");

Page 14: Syspro

j=0; for(i=0;i<n;i++) {

wt[i]=j; j=j+b[i];

} printf("\n******************************************************** \n"); printf("\n Process Arrival Time Bust Time Priority Wating Time "); for(i=0;i<n;i++) {

printf("\n\n%d\t\t%d\t\t%d\t\t%d\t\t%d \n",p[i],a[i],b[i],pr[i],wt[i]); } printf("\n******************************************************** \n");

printf("\n ** Avg Wating Time ** \n "); for(i=0;i<n;i++) {

w=w+wt[i]; } avg=w/n; printf("\n ** Avrage Waiting Time ==>> %f \n ",avg); printf("\n*************************************************** \n"); getch();}

Output:** Eenter Proccess Number ==>> 1 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 10 ** Enter Priority of Job ==>> 3** Eenter Proccess Number ==>> 2 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 1 ** Enter Priority of Job ==>> 1

Page 15: Syspro

** Eenter Proccess Number ==>> 3 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 2 ** Enter Priority of Job ==>> 5 ** Eenter Proccess Number ==>> 4 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 1 ** Enter Priority of Job ==>> 4 ** Eenter Proccess Number ==>> 5 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 5 ** Enter Priority of Job ==>> 2************************************************************** ** Gantt Chart **------------------------| p2| p5| p1| p4| p3------------------------************************************************************** Process Arrival Time Bust Time Priority Wating Time

2 0 1 1 0

5 0 5 2 1

1 0 10 3 6

4 0 1 4 16

3 0 2 5 17************************************************************** ** Avg Wating Time ** ** Avrage Waiting Time ==>> 8.000000**************************************************************

ASSIGNMENT NO :-6

#include<stdio.h>#include<conio.h>void main(){ int p[10],a[10],pr[10],b[10],wt[10],i,j,t,t1,n,w=0,at=0,c[10],s=0;

Page 16: Syspro

float avg; clrscr(); printf("\n ** Enter Number of Jobs in Ready Queue ==>> "); scanf("%d",&n); for(i=0;i<n;i++) {

printf("\n ** Eenter Proccess Number ==>> "); scanf("%d",&p[i]); printf("\n ** Enter Proccess Arrival Time ==>> "); scanf("%d",&a[i]); printf("\n ** Enter Proccess Bust Time ==>> "); scanf("%d",&b[i]); printf("\n ** Enter Priority of Job ==>> "); scanf("%d",&pr[i]);

} for(i=0;i<n;i++) {

for(j=0;j<n-1;j++) { if(pr[j]>pr[j+1]) {

t=pr[j]; pr[j]=pr[j+1]; pr[j+1]=t; t1=p[j]; p[j]=p[j+1]; p[j+1]=t1; t=a[j]; a[j]=a[j+1]; a[j+1]=t; t=b[j]; b[j]=b[j+1]; b[j+1]=t;

} }

} printf("\n***************************************** \n"); printf("\n ** Gantt Chart ** "); printf("\n------------------------\n"); for(i=0;i<n;i++) {

Page 17: Syspro

printf("| p%d",p[i]); } printf("\n------------------------\n");

j=0; for(i=0;i<n;i++) {

wt[i]=j; j=j+b[i];

} printf("\n***************************************** \n"); printf("\n Process Arrival Time Bust Time Priority Wating Time "); for(i=0;i<n;i++) {

printf("\n\n%d\t\t%d\t\t%d\t\t%d\t\t%d \n",p[i],a[i],b[i],pr[i],wt[i]); } printf("\n****************************************** \n"); printf("\n ** Avg Turn Around Time ** \n "); for(i=0;i<n;i++) {

at=at+b[i]; c[i]=at;

} for(i=0;i<n;i++) {

s=s+c[i]; } avg=(float)s/n; printf("\n ** Avrage Turn Arround Time ==>> %f \n ",avg); printf("\n****************************************** \n");

getch();}

Page 18: Syspro

Output:** Eenter Proccess Number ==>> 1** Enter Proccess Arrival Time ==>> 0** Enter Proccess Bust Time ==>> 5 ** Enter Priority of Job ==>>2** Eenter Proccess Number ==>> 2** Enter Proccess Arrival Time ==>> 0** Enter Proccess Bust Time ==>> 2 ** Enter Priority of Job ==>> 4 ** Eenter Proccess Number ==>> 3 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 8 ** Enter Priority of Job ==>> 3 ** Eenter Proccess Number ==>> 4 ** Enter Proccess Arrival Time ==>> 0 ** Enter Proccess Bust Time ==>> 6 ** Enter Priority of Job ==>> 1*************************************************************** ** Gantt Chart **------------------------| p4| p1| p3| p2------------------------***************************************************************Process Arrival Time Bust Time Priority Wating Time

4 0 6 1 0

1 0 5 2 6

3 0 8 3 11

2 0 2 4 19

*************************************************************** ** Avg Turn Around Time ** ** Avrage Turn Arround Time ==>> 14.250000***************************************************************

Page 19: Syspro

ASSIGNMENT NO :-7#include<stdio.h>#include<conio.h>void main(){int n,d,tot,ch,i,sum=0,q[10],f[20],s[20];clrscr();printf("\n**********************************************************\n");printf("\n ** Enter The Total Number of Disk Block ==>> ");scanf("%d",&n);printf("\n ** Enter Request String ==>> ");for(i=0;i<n;i++){scanf("%d",&q[i]);}printf("\n ** Enter The Current Head Position ==>> ");scanf("%d",&ch);printf("\n ** Enter The Head Direction ** 0 = Lower ** 1 = Upper ==>> ");scanf("%d",&d);printf("\n**********************************************************\n");printf("\n ** By Using FCFS Disk Scheduling Algorithm ** \n ");f[0]=ch;for(i=0;i<n;i++){f[i+1]=q[i];}

printf("\n ** String is ** \n\n ");for(i=0;i<=n;i++){printf("%d\t",f[i]);}for(i=0;i<n;i++){if(f[i]<f[i+1]) s[i]=f[i+1]-f[i];else s[i]=f[i]-f[i+1];

Page 20: Syspro

}printf("\n\n");for(i=0;i<n;i++){printf(" %d ",s[i]);sum=sum+s[i];}printf("\n**********************************************\n");printf("\n ** Total Head Position ==>> %d \n ",sum);printf("\n******************************************\n");getch();}

Output: ** Enter The Total Number of Disk Block ==>> 8

** Enter Request String ==>> 98 183 37 122 14 124 65 67

** Enter The Current Head Position ==>> 53

** Enter The Head Direction ** 0 = Lower ** 1 = Upper ==>> 0

*******************************************************************

** By Using FCFS Disk Scheduling Algorithm **

** String is **

53 98 183 37 122 14 124 65 67

45 85 146 85 108 110 59 2*******************************************************************

** Total Head Position ==>> 640

*******************************************************************

Page 21: Syspro

ASSIGNMENT NO :-8

#include<stdio.h>#include<conio.h>#include<stdlib.h>int job[10],i,n,head,cnt[10];void array_sort(){ int i,j,k,temp;

for(i=0;i<n;i++)for(j=0;j<n-i-1;j++){

if(job[j]>job[j+1]){

temp=job[j+1];job[j+1]=job[j];job[j]=temp;

}}

}int find(){

int i;for(i=0;i<n;i++){

if(head<job[i])return i;

}}void scan(){

Page 22: Syspro

int choice,index,min,max,sum1,sum2;printf("\n**********************************\n");printf("\n ** Enter The Range(Min...Max ==>> ");scanf("%d%d",&min,&max);printf("\n**********************************\n");printf("\n ** Enter The Direction Of Head ==>> \n");printf("\n ** 1:Lower...\n");printf("\n ** 2:Upper...\n");printf("\n ** Enter The Choice ==>> ");scanf("%d",&choice);index=find();//printf("\n%d\t",head);if(choice==1){

for(i=index-1;i>=0;i--)printf("%d\t",job[i]);

printf("%d\t",min);for(i=index;i<n;i++)

printf("%d\t",job[i]);sum1=head-min;sum2=job[i-1]-min;printf("\n\n ** %d - %d = %d",head,min,sum1);printf("\n\n ** %d - %d = %d\n",job[i-1],min,sum2);printf("\n***********************************\n");printf("\n ** Total Head Movement ==>> %d\n",

(sum1+sum2));printf("\n**********************************\n");

}if(choice==2){

for(i=index;i<n;i++)printf("%d\t",job[i]);

printf("%d\t",max);for(i=index-1;i>=0;i--)

printf("%d\t",job[i]);

Page 23: Syspro

sum1=max-head;sum2=max-job[i+1];printf("\n\n ** %d - %d = %d",max,head,sum1);printf("\n\n ** %d - %d = %d\n",max,job[i+1],sum2);printf("\n**********************************\n");printf("\n ** Total Head Movement ==>> %d\n",

(sum1+sum2));printf("\n***********************************\n");

}}

main(){ clrscr();

printf("\n----------------------SCAN ALGORITHM-----------------------\n");

printf("\n ** Enter The Total Number Of Disk Blocks ==>> ");

scanf("%d",&n);printf("\n ** Enter The Request String ==>> ");for(i=0;i<n;i++)scanf("%d",&job[i]);printf("\n ** Enter Initial Head Position ==>> ");scanf("%d",&head);array_sort();scan();getch();

}OUTPUT:----------------------SCAN ALGORITHM------------------

** Enter The Total Number Of Disk Blocks ==>> 9 ** Enter The Request String ==>> 160 90 58 55 18 38 39 150 184 ** Enter Initial Head Position ==>> 100 ** Enter The Range(Min...Max) ==>> 0 200

Page 24: Syspro

** Enter The Direction Of Head ==>> ** 1:Lower... ** 2:Upper... ** Enter The Choice ==>> 2

150 160 184 200 90 58 55 39 38 18

** 200 - 100 = 100

** 200 - 18 = 182** Total Head Movement ==>> 282

ASSIGNMENT NO :-9#include<stdio.h>#include<conio.h>main(){

int f[3]={-1,-1,-1},cnt[3]={-1,-1,-1},i,no,a[50],pf=0,ref[20],k=0;

clrscr();printf("\n ** Enter The No of Pages ==>> ");scanf("%d",&no);printf("\n ** Enter The Pages ==>> ");for(i=0;i<no;i++)

scanf("%d",&a[i]);

for(i=0;i<no;i++)ref[i]=0;

printf("\n***********************************\n");printf("\nPage_No\t Frame\t\t Result \n ");for(i=0;i<no;i++){

printf("\n %d",a[i]);if(f[0]!=a[i] && f[1]!=a[i] && f[2]!=a[i] )

Page 25: Syspro

{pf++;if(f[0]==-1){

f[0]=a[i];cnt[0]=i;ref[0]=1;

}else

if(f[1]==-1){

f[1]=a[i];cnt[1]=i;ref[1]=1;

}else

if(f[2]==-1){

f[2]=a[i];cnt[2]=i;ref[2]=1;

}else{

while(1){if(ref[k]==0){

f[i]=a[i];ref[i]=1;k=(k+1)%3;break;

}else{

Page 26: Syspro

ref[k]=0;k=(k+1)%3;

} }

if(cnt[0]<cnt[1] &&cnt[0]<cnt[2]){

f[0]=a[i];cnt[0]=i;

}else

if(cnt[1]<cnt[0] &&cnt[1]<cnt[2]){

f[1]=a[i];cnt[1]=i;

}else{

f[2]=a[i];cnt[2]=i;

}}

printf("\t%d %d %d\t\tPage Fault\n",f[0],f[1],f[2]);}else

printf("\t%d %d %d\t\tNo Fault\n",f[0],f[1],f[2]);}printf("\

n****************************************************\n");printf("\n ** Total No Page Faults ==>> %d\n ",pf);printf("\n************************************\n");getch();

}OUTPUT: ** Enter The No of Pages ==>> 16 **Enter The Pages ==>>7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0

Page 27: Syspro

*****************************************************Page_No Frame Result

▼7 7 -1 -1 Page Fault ▼0 7 0 -1 Page Fault ▼1 7 0 1 Page Fault ▼2 2 0 1 Page Fault ▼0 2 0 1 No Fault ▼3 2 3 1 Page Fault ▼0 2 3 0 Page Fault ▼4 4 3 0 Page Fault ▼2 4 2 0 Page Fault ▼3 4 2 3 Page Fault ▼0 0 2 3 Page Fault ▼3 0 2 3 No Fault ▼2 0 2 3 No Fault ▼1 0 1 3 Page Fault ▼2 0 1 2 Page Fault ▼0 0 1 2 No Fault***************************************************** ** Total No Page Faults ==>> 12*****************************************************

ASSIGNMENT NO :-10#include<stdio.h>#include<conio.h>main(){

int f[3]={-1,-1,-1},cnt[3]={-1,-1,-1},pfault=0,i,j,no,a[50];clrscr();

printf("\n++++++++++++++++++ Least Recently Used Page Algo +++++++++++++++++++\n");

printf("\n ** How Many Pages ==>> ");scanf("%d",&no);printf("\n ** Enter The Pages ==>> ");

Page 28: Syspro

for(i=0;i<no;i++)scanf("%d",&a[i]);

printf("\n****************************************************\n");

printf("\nPageNo\tFrame\t\tResult\n");for(i=0;i<no;i++){

printf("\n %d",a[i]);if(f[0]!=a[i] && f[1]!=a[i] && f[2]!=a[i]){

pfault++;if(f[0]==-1){

f[0]=a[i];cnt[0]=i;

}else

if(f[1]==-1){

f[1]=a[i];cnt[1]=i;

}else

if(f[2]==-1){

f[2]=a[i];cnt[2]=i;

}else{

if(cnt[0]<cnt[1] && cnt[0]<cnt[2]){

f[0]=a[i];

Page 29: Syspro

cnt[0]=i;}elseif(cnt[1]<cnt[0] && cnt[1]<cnt[2]){

f[1]=a[i];cnt[1]=i;

}else{

f[2]=a[i];cnt[2]=i;

}}

printf("\t%d %d %d\t\tPage Fault\n",f[0],f[1],f[2]);}else{ //llllll

for(j=0;j<3;j++){

if(f[j]==a[i])cnt[j]=i;

} printf("\t%d %d %d\t\tNo Page fault Occurs.....\n",f[0],f[1],f[2]);

}}printf("\

n****************************************************\n");printf("\nTotal No of Page Faults ==>> %d \n",pfault);printf("\

n*****************************************************");getch();

}OUTPUT:

Page 30: Syspro

+++++++ Least Recently Used Page Algo+++++++++++++++++ ** How Many Pages ==>> 20 ** Enter The Pages ==>> 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1******************************************************PageNo Frame Result 7 7 -1 -1 Page Fault 0 7 0 -1 Page Fault 1 7 0 1 Page Fault

2 2 0 1 Page Fault 0 2 0 1 No Page fault Occurs..... 3 2 0 3 Page Fault

0 2 0 3 No Page fault Occurs..... 4 4 0 3 Page Fault 2 4 0 2 Page Fault

3 4 3 2 Page Fault 0 0 3 2 Page Fault 3 0 3 2 No Page fault Occurs.....

2 0 3 2 No Page fault Occurs..... 1 1 3 2 Page Fault 2 1 3 2 No Page fault Occurs.....

0 1 0 2 Page Fault 1 1 0 2 No Page fault Occurs..... 7 1 0 7 Page Fault

0 1 0 7 No Page fault Occurs..... 1 1 0 7 No Page fault Occurs.....

******************************************************Total No of Page Faults ==>> 12******************************************************

Page 31: Syspro

ASSIGNMENT NO :-11

#include<stdio.h>#include<conio.h>main(){

int f[3]={-1,-1,-1},cnt[3]={-1,-1,-1},a[50],i,j,no,pfault=0;clrscr();printf("\n++++++++++++++Most Recently Used Page

Algo +++++++++\n");printf("\n ** Enter The No of Pages ==>> ");scanf("%d",&no);printf("\n ** Enter The Pages ==>> ");for(i=0;i<no;i++)

scanf("%d",&a[i]);printf("\

n****************************************************\n");printf("\nPageNo\tFrame\t\tResult \n");for(i=0;i<no;i++){

printf("\n%d",a[i]);if(f[0]!=a[i] &&f[1]!=a[i] &&f[2]!=a[i] ){

pfault++;if(f[0]==-1){

f[0]=a[i];cnt[0]=i;

}else

if(f[1]==-1){

f[1]=a[i];cnt[1]=i;

}

Page 32: Syspro

elseif(f[2]==-1){

f[2]=a[i];cnt[2]=i;

}else{

if(cnt[0]>cnt[1] && cnt[0]>cnt[2]){

f[0]=a[i];cnt[0]=i;

}elseif(cnt[1]>cnt[0] && cnt[1]>cnt[2]){

f[1]=a[i];cnt[1]=i;

}else{

f[2]=a[i];cnt[2]=i;

}}

printf("\t%d %d %d\t\tPage Fault \n",f[0],f[1],f[2]);}else{

for(j=0;j<3;j++)if(f[j]==a[i])

cnt[j]=i;printf("\t%d %d %d\t\tNo Page Fault.... \

n",f[0],f[1],f[2]);}

}

Page 33: Syspro

printf("\n***********************************\n");printf("\n ** Total No of Page Faults ==>> %d \n",pfault);printf("\n***********************************");getch();

}OUTPUT: ++++++++ Most Recently Used Page Algo ++++++++++

** Enter The No of Pages ==>> 19

** Enter The Pages ==>> 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0*********************************************************************PageNo Frame Result

7 7 -1 -1 Page Fault0 7 0 -1 Page Fault1 7 0 1 Page Fault

2 7 0 2 Page Fault0 7 0 2 No Page Fault....3 7 3 2 Page Fault

0 7 0 2 Page Fault4 7 4 2 Page Fault2 7 4 2 No Page Fault....

3 7 4 3 Page Fault0 7 4 0 Page Fault3 7 4 3 Page Fault2 7 4 2 Page Fault1 7 4 1 Page Fault2 7 4 2 Page Fault

0 7 4 0 Page Fault

Page 34: Syspro

1 7 4 1 Page Fault7 7 4 1 No Page Fault....

0 0 4 1 Page Fault

********************************************************************* ** Total No of Page Faults ==>> 16*****************************************************