OPERATING SYSTM’s ALGORITHM (In LINUX OS) - FIRST FIT, BEST FIT, WORST FIT ALGORITHM


FIRST FIT, BEST FIT, WORST FIT ALGORITHM



PROGRAM:

#include<stdio.h>
int mem[20],proc[20],bp[20],bm[20],cm[20],cp[20],ms,ps,i,j,ch,y;
main()
{
            printf(“\nEnter the number of memory segments”);
            scanf(“%d”,&ms);
            printf(“\nEnter the memory segment”);
            for(i=0;i<ms;i++)
            {
                        scanf(“%d”,&mem[i]);
                        bm[i]=cm[i]=mem[i];
            }
            printf(“\nEnter the number of process”);
            scanf(“%d”,&ps);
            printf(“\nEnter the memory space for process”);
            for(i=0;i<ps;i++)
            {
                        scanf(“%d”,&proc[i]);
                        bp[i]=op[i]=proc[i];
            }
            do
            {
                        printf(“\nEnter the choice”);
printf(“\n1.First fit\n2.Best fit\n3.Worst fit\n4.Exit”);
scanf(“%d”,&ch);
switch(ch)
{
            case1:
                        all(mem,proc);
                        break;
            case2:
                        for(i=0;i<ms;i++)
                        {
                                    for(j=i+1;j<ms;j++)
                                    {
                                                if(bm[i]>bm[j])
                                                {
                                                            y=bm[i];
bm[i]=bm[j];
bm[j]=y;
                                                                        }
                                                            }
                                                }
                                                all(bm,bp);
                                                break;
                                    case3:
                                                for(i=0;i<ms;i++)
                                                {
                                                            for(j=i+1;j<ms;j++)
                                                            {
                                                                        if(cm[i]<cm[j])
                                                                        {
                                                                                    y=cm[i];
                                                                                    cm[i]=cm[j];
                                                                                    cm[j]=y;
                                                                        }
                                                            }
                                                }
                                                all(cm,cp);
                                                break;
                                    }
                        }while(ch!=4);
            }
int all(int a[20],int d[20])
{
            for(i=0;i<ms;i++)
            {
                        for(j=0;j<ps;j++)
                        {
                                    if(a[i]!=0&&d[j]!=0)
                                    {
                                                if(a[i]>d[j])
                                                {
                                                            printf(“\nSeg %d <- process %d”,i,j);
                                                            d[i]=0;
d[j]=0;
                                                }
                                    }
                        }
            }
}


OUTPUT:

Enter the number of memory segments 3
Enter the memory segment 4   5   6
Enter the number of process 3
Enter the memory space for process 2  4   5
Enter the choice
Enter the choice
1.First fit
2.Best fit
3.Worst fit
4.Exit
1

Seg 0 <- process 0
Seg 1 <- process 1
Seg 2 <- process 2

Enter the choice
1.First fit
2.Best fit
3.Worst fit
4.Exit
2

Seg 0 <- process 0
Seg 1 <- process 1
Seg 2 <- process 2


Enter the choice
1.First fit
2.Best fit
3.Worst fit
4.Exit
3

Seg 0 <- process 0
Seg 0 <- process 1
Seg 0 <- process 2

Comments

  1. helo can i help me to have a randomize program for c++ in worst fit

    ReplyDelete

Post a Comment

Popular posts from this blog

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE

BOOKS DETAILS USING C STRUCTURE

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE