Você está na página 1de 7

PRORITY:-

#include<stdio.h>

#include<conio.h>

int f[40];

void main()

int n,i,j,k,l;

int at[40],bt[40],ct[40],tat[40],wt[40],pro[40],pri[40];

int temp,prev,q[40];

clrscr();

printf("\nEnter no. of process:\n");

scanf("%d",&n);

printf("\nEnter arrival times:\n");

for(i=1;i<=n;i++)

pro[i]=i;

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

printf("\nEnter burst times:\n");

for(i=1;i<=n;i++)

f[i]=0;

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

printf("\nEnter priorities:\n");

for(i=1;i<=n;i++)

scanf("%d",&pri[i]);
//sort

for(i=1;i<=n;i++)

for(j=1;j<n;j++)

if(at[j+1]<at[j])

temp=pro[j+1];

pro[j+1]=pro[j];

pro[j]=temp;

temp=at[j+1];

at[j+1]=at[j];

at[j]=temp;

temp=bt[j+1];

bt[j+1]=bt[j];

bt[j]=temp;

temp=pri[j+1];

pri[j+1]=pri[j];

pri[j]=temp;

ct[1]=bt[1];

tat[1]=ct[1]-at[1];

wt[1]=tat[1]-bt[1];

prev=ct[1];

f[pro[1]]=1;i=2;
do

k=0;

for(j=1;j<=n;j++)

if(f[pro[j]]==0 )

if(at[j]<=prev)

q[k]=j;

k++;

if(k==1)

ct[q[0]]=prev+bt[q[0]];

tat[q[0]]=ct[q[0]]-at[q[0]];

prev=ct[q[0]];

wt[q[0]]=tat[q[0]]-bt[q[0]];i++;

f[pro[q[0]]]=1;

else if(k>1)

for(j=0;j<k;j++)

for(l=0;l<k-1;l++)
{

if(pri[q[l+1]]>pri[q[l]])

temp=q[l+1];

q[l+1]=q[l];

q[l]=temp;

else if(pri[q[l+1]]==pri[q[l]] &&


bt[q[l+1]]<bt[q[l]])

temp=q[l+1];

q[l+1]=q[l];

q[l]=temp;

ct[q[0]]=prev+bt[q[0]];

tat[q[0]]=ct[q[0]]-at[q[0]];

prev=ct[q[0]];

wt[q[0]]=tat[q[0]]-bt[q[0]];

f[pro[q[0]]]=1;i++;

else

ct[i]=at[i]+bt[i];

tat[i]=ct[i]-at[i];

prev=ct[i];

wt[i]=tat[i]-at[i];

f[pro[i]]=1;i++;
}

}while(i<n);

ct[q[1]]=prev+bt[q[1]];

tat[q[1]]=ct[q[1]]-at[q[1]];

prev=ct[q[1]];

wt[q[1]]=tat[q[1]]-bt[q[1]];

printf("\nProcess\tCT\tAT\tBT\tTAT\tWT");

for(i=1;i<=n;i++)

printf("\n%d\t%d\t%d\t%d\t%d\t%d",pro[i],ct[i],at[i],bt[i],tat[i],wt[i]);

getch();

LRU:-

#include<stdio.h>

Void main()

Int n1,n2,I,j,k=0,fault=0,l=1;

Int pt[40],pa[40],count,flag;

Printf(“Enter no. of pages:”);

Scanf(“%d”,&n1);

Printf(“Enter page table size:”);

Scanf(“%d”,&n2);

Printf(“Enter pages:”);

For(i=1;i<=n1;i++)

{scanf(“%d”,&pa[i]);

For(i=1;i<=n2;i++)

Pt[i]=0;

Pt[l++]=pa[1];
For(i=2;i<=n1;i++)

Count=0;flag=0;

For(j=1;j<=n2;j++)

If(pa[i]==pt[j])

{count=;break;}

If(l<=n2)

If(count==0)

Pt[l++]=pa[i];

Else

If(count==0)

K=pa[i-n2];

For(j=1;j<=n2;j++)

If(pt[j]==k)

{pt[j]=pa[i];fault++;}

Printf(“%d”,fault);

Você também pode gostar