Docstoc

Implementation of resource allocatio

Document Sample
Implementation of resource allocatio Powered By Docstoc
					                               PROGRAM NO. -3
AIM:-Implementation of resource allocation graph.
#include<iostream.h>
#include<conio.h>
void main()
{
   clrscr();
   char ch;
   int m,n,P[5],R[5],C[5][5],chk[5];
   cout<<"Enter the no. of processes:";
   cin>>m;
   cout<<"Enter the no. of resources:";
   cin>>n;
   for(int i=1;i<=m;i++)
   for(int j=1;j<=n;j++)
   {
         cout<<"Does process P"<<i<<" require resource R"<<j<<"(0/1):";
         cin>>C[i][j];
         if(C[i][j]==1)
         cout<<"P"<<i<<"------>R"<<j<<endl;
   }

  for(i=0;i<=n;i++)
  chk[i]=0;
  cout<<"\n\nThe Requirements phase";
  for(i=1;i<=m;i++)
  {
        cout<<"\n\nWhich resource does P"<<i<<" require:R";
        cin>>j;
        if(C[i][j]==1)



       {
             chk[j]++;
             C[i][j]=5;
             cout<<"P"<<i<<" ------>R"<<j;
           }
           else
              cout<<"R"<<j<<" has not been claimed by P"<<i;
  }
  cout<<"\n\nThe Assigning phase";
  for(i=1;i<=m;i++)
  {
        for(j=1;j<=n;j++)
{
               if(C[i][j]==5)
               {
                     if(chk[j]>0)
                     {
                           cout<<"\nP"<<i<<":The resource has been assigned ";
                           cout<<"R"<<j<<" -------->P"<<i;
                           chk[j]=0;
                     }
                     else
                           cout<<"\nP"<<i<<":The resource R"<<j<<" has already
                           been allocated!!Please wait...";
               }
         }
    }
    getch();
}
                                      OUTPUT

Enter the no. of processes:3
Enter the no. of resources:3
Does process P1 require resource R1(0/1):1
P1------>R1
Does process P1 require resource R2(0/1):1
P1------>R2
Does process P1 require resource R3(0/1):0
Does process P2 require resource R1(0/1):1
P2------>R1
Does process P2 require resource R2(0/1):0
Does process P2 require resource R3(0/1):1
P2------>R3
Does process P3 require resource R1(0/1):1
P3------>R1
Does process P3 require resource R2(0/1):1
P3------>R2
Does process P3 require resource R3(0/1):1
P3------>R3


The Requirements phase

Which resource does P1 require:R1
P1 ----->R1

Which resource does P2 require:R2
R2 has not been claimed by P2

Which resource does P3 require:R1
P3 ----->R1

The Assigning phase
P1:The resource has been assigned R1 -------->P1
P3:The resource R1 has already been allocated!!Please wait...

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:3
posted:4/30/2012
language:
pages:3
Description: This document contains Lab practicals of Operating System Lab for CSE students, under Kurukshetra University scheme.