Sunday, November 25, 2012

Multiprogramming with variable Task --- MVT

/* simulate the mvt(multiprogramming with variable Task)*/


#include<stdio.h>
#include<conio.h>
#include<string.h>
int i=0;
void main()
{
    int tot,sz,b[20],ch,size[20];
    char p[20][20],pro[10];
    int j,k,status[10],tot1;
    clrscr();
    printf("\n Enter total Memory ::");
    scanf("%d",&tot);
    tot1=tot;
    printf("\n Enter the size of o.s::");
    scanf("%d",&sz);
    tot1=tot1-sz;
    do
    {
        printf("\n-----------------------------------------------------\n");
        printf("\n\t\tMulti Variable Task(MVT)");
        printf("\n-----------------------------------------------------\n");
        printf("\n\t\t1.Allocation\n\t\t2.Deletion\n\t\t3.Display\n\t\t4.Exit");
        printf("\n-----------------------------------------------------\n");
        printf("\n Enter Ur choice ::");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                printf("\n Enter process %d::",i+1);
                scanf("%s",&p[i]);
                printf("\n Enter memory size for process%d::",i+1);
                scanf("%d",&size[i]);
                if(tot1 >=size[i])
                {
                    b[i]=size[i];
                    tot1=tot1-size[i];
                    status[i]=1;
                    i++;
                    printf("\n Process is allocated ::");
                }
                else
                    printf("\n memory size is not Available ::");

                break;
            case 2:
                printf("\n Enter a process U want to delete ::");
                scanf("%s",&pro);
                j=0;
                while(j<i)
                {
                    if(strcmp(p[j],pro)==0)
                    {
                        status[j]=0;
                        tot1+=b[j];
                        b[j]-=size[j];
                    }
                    j++;
                }
                printf("\n Process is deleted ::");
                break;
               case 3:
                printf("\n\n Total Memory size ::%d",tot);
                printf("\n\n Memory size of o.s::%d",sz);
                printf("\n\n No.of processes   ::%d",i);
                printf("\n----------------------------------------------------------------------------\n");
                printf("\npname\tAllocated Memory\tStatus\n");
                printf("\n----------------------------------------------------------------------------\n");
                for(k=0;k<i;k++)
                {
                    if(b[k]!=0)
                    {
                        printf("\n%s\t\t%d\t\t",p[k],b[k]);
                        if(status[k]==1)
                            printf("Full");
                        else
                            printf("Available");
                    }
                }
                printf("\n----------------------------------------------------------------------------\n");
                printf("\n Total Available Space ::%d",tot1);
                break;
            case 4:
                exit(0);
            default:
                printf("\n Wrong Choice ::");
        }

    }while(1);
}

/* Input and output :-


 Enter total Memory ::600

 Enter the size of o.s::100

-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::1

 Enter process 1::p1

 Enter memory size for process1::250

 Process is allocated ::
-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::1

 Enter process 2::p2

 Enter memory size for process2::125

 Process is allocated ::
-----------------------------------------------------

                Multi Variable Task(MVT)
-----------------------------------------------------

                1.Allocation
                2.Deletion
                3.Display
                4.Exit
-----------------------------------------------------

 Enter Ur choice ::1

 Enter process 3::p3

 Enter memory size for process3::25

 Process is allocated ::
-----------------------------------------------------

                Multi Variable Task(MVT)
-----------------------------------------------------

                1.Allocation
                2.Deletion
                3.Display
                4.Exit
-----------------------------------------------------

 Enter Ur choice ::1

 Enter process 3::p4

 Enter memory size for process4::200

 Memory size is not Available::

-----------------------------------------------------

                Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::3

 Total memory size is::600

 Memory size for o.s::100

 No.of processes   ::3
----------------------------------------------------------------------------

pname   Allocated Memory        Status

----------------------------------------------------------------------------

p1              250             Full
p2              125             Full
p3              25              Full
----------------------------------------------------------------------------

 Total Available Space ::100
-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::

-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::1

 Enter process 4::p4

 Enter memory size for process4::100

  Process is allocated ::

  -----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::2

 Enter a process U want to delete ::p3

 Process is deleted ::
-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::3

 Total memory size is::600

 Memory size for o.s::100

 No.of processes   ::3
----------------------------------------------------------------------------

pname   Allocated Memory        Status

----------------------------------------------------------------------------

p1              250             Full
p2              125             Full
p4              100             Full
p3              0               Available
----------------------------------------------------------------------------

 Total Available Space ::25
-----------------------------------------------------

        Multi Variable Task(MVT)
-----------------------------------------------------

        1.Allocation
        2.Deletion
        3.Display
        4.Exit
-----------------------------------------------------

 Enter Ur choice ::4*/


No comments:

Post a Comment