User:Dude009/sandbox

1. Banker algorithm

#include #include   void main {     int k=,output[10],d=,t=,ins[5],i,avail[5],allocated[10][5],need[10][5],MAX[10][5],pno,P[10],j,rz, count=; clrscr; printf("\n Enter the number of resources : "); scanf("%d", &rz); printf("\n enter the max instances of each resources\n"); for(i=;i<rz;i++) {    avail[i]=; printf("%c= ",(i+97)); scanf("%d",&ins[i]); }   printf("\n Enter the number of processes : "); scanf("%d", &pno); printf("\n Enter the allocation matrix \n    "); for(i=;i<rz;i++) printf(" %c",(i+97)); printf("\n"); for(i=;i <pno;i++) {          P[i]=i; printf("P[%d] ",P[i]); for(j=;j<rz;j++) {       scanf("%d",&allocated[i][j]); avail[j]+=allocated[i][j]; } }      printf("\nEnter the MAX matrix \n     "); for(i=;i<rz;i++) {         printf(" %c",(i+97)); avail[i]=ins[i]-avail[i]; }  printf("\n"); for(i=;i "); getch; }

2. Round Robine #include int main {  int count,j,n,time,remain,flag=0,time_quantum; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Enter Total Process:\t "); scanf("%d",&n); remain=n; for(count=0;count0) {                        time+=rt[count]; rt[count]=0; flag=1; }                    else if(rt[count]>0) {      rt[count]-=time_quantum; time+=time_quantum; }    if(rt[count]==0 && flag==1) {      remain--; printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]); wait_time+=time-at[count]-bt[count]; turnaround_time+=time-at[count]; flag=0; }    if(count==n-1) count=0; else if(at[count+1]<=time) count++; else count=0; }  printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n); printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); return 0; }

3. shortest job preemtive

int main { int arrival_time[10], burst_time[10], temp[10]; int i, smallest, count = 0, time, limit; double wait_time = 0, turnaround_time = 0, end; float average_waiting_time, average_turnaround_time; printf("\nEnter the Total Number of Processes:\t"); scanf("%d", &limit); printf("\nEnter Details of %d Processes\n", limit); for(i = 0; i < limit; i++) { printf("\nEnter Arrival Time:\t"); scanf("%d", &arrival_time[i]); printf("Enter Burst Time:\t"); scanf("%d", &burst_time[i]); temp[i] = burst_time[i]; } 	burst_time[9] = 9999; for(time = 0; count != limit; time++) {  smallest = 9; for(i = 0; i < limit; i++) {  if(arrival_time[i] <= time && burst_time[i] < burst_time[smallest] && burst_time[i] > 0) {  smallest = i; } } 	burst_time[smallest]--; if(burst_time[smallest] == 0) {  count++; end = time + 1; wait_time = wait_time + end - arrival_time[smallest] - temp[smallest]; turnaround_time = turnaround_time + end - arrival_time[smallest]; } } average_waiting_time = wait_time / limit; average_turnaround_time = turnaround_time / limit; printf("\n\nAverage Waiting Time:\t%lf\n", average_waiting_time); printf("Average Turnaround Time:\t%lf\n", average_turnaround_time); return 0; }
 * 1) include 

4.priorty algo.

#include int main { int p[30],pr[30],key,loc,bt[30],temp,max,wt[30],ta[30],sum=,i,j,n; wt[]=; printf("enter the number of processes="); scanf("%d",&n); printf("enter the burst time for each process"); for(i=;i<n;i++) { p[i]=i+1; printf("\np%d=",i+1); scanf("%d",&bt[i]); printf("\t priority of p%d=",i+1); scanf("%d",&pr[i]); } for(i=;i int main { int i,j,n,a[50],frame[10],no,k,avail,count=0; printf("\n ENTER THE NUMBER OF PAGES:\n"); scanf("%d",&n); printf("\n ENTER THE PAGE NUMBER :\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("\n ENTER THE NUMBER OF FRAMES :"); scanf("%d",&no); for(i=0;i main { 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:"); scanf("%d",&n); printf("Enter the reference string:"); for(i=0;i<n;i++) scanf("%d",&p[i]); printf("Enter no of frames:"); scanf("%d",&f); q[k]=p[k]; printf("\n\t%d\n",q[k]); c++; k++; for(i=1;i<n;i++) {                       c1=0; for(j=0;j<f;j++) {                                   if(p[i]!=q[j]) c1++; }                       if(c1==f) {                                   c++; if(k<f) {                                               q[k]=p[i]; k++; for(j=0;j<k;j++) printf("\t%d",q[j]); printf("\n"); }                                   else {                                               for(r=0;r<f;r++) {                                                           c2[r]=0; for(j=i-1;j<n;j--) {                                                           if(q[r]!=p[j]) c2[r]++; else break; }                                   }                                    for(r=0;r<f;r++) b[r]=c2[r]; for(r=0;r<f;r++) {                                               for(j=r;j<f;j++) {                                                           if(b[r]<b[j]) {                                                                       t=b[r]; b[r]=b[j]; b[j]=t; }                                               }                                    }                                    for(r=0;r<f;r++) {                                               if(c2[r]==b[0]) q[r]=p[i]; printf("\t%d",q[r]); }                                   printf("\n"); }           } } printf("\nThe no of page faults is %d",c); }

7.optimal

int n,page[20],f,fr[20],i; void display { for(i=0;i<f;i++) { printf("%d",fr[i]); } printf("\n"); } void request { printf("enter no.of pages:"); scanf("%d",&n); printf("enter no.of frames:"); scanf("%d",&f); printf("enter no.of page no.s"); for(i=0;i<n;i++) { scanf("%d",&page[i]); } for(i=0;i<n;i++) { fr[i]=-1; } } void replace { int j,flag=0,pf=0; int max,lp[10],index,m; for(j=0;j<f;j++) { fr[j]=page[j]; flag=1; pf++; display; } for(j=f;j
 * 2) include