Implement Banker’s Algorithm doc (DOC)

Description

This document contains Lab practicals of Operating System Lab for CSE students, under Kurukshetra University scheme.

Shared by: SandeepRao7
-
Stats
views:
54
posted:
4/30/2012
language:
English
pages:
3
Document Sample
scope of work template
							                              PROGRAM NO. -5

Aim: -WAP to Implement Banker’s Algorithm.
#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 char ch;
 int i,j,p,r,P[5][5],R[5],A[5][5],N[5][5],count;
 cout<<"Enter the no. of processes:";
 cin>>p;
 cout<<"Enter the no. of resources:";
 cin>>r;
 cout<<"Enter the vlaues of resources:";
 for(i=1;i<=r;i++)
   cin>>R[i];
 cout<<"\nEnter the maximum values of resources:\n";
 for(i=1;i<=p;i++)
  for(j=1;j<=r;j++)
   {
    cout<<"P"<<i<<" -->R"<<j<<" :";
    cin>>P[i][j];
   }

 cout<<"\nEnter the resources allocated:\n";
 for(i=1;i<=p;i++)
 for(j=1;j<=r;j++)
  {
   cout<<"P"<<i<<" -->R"<<j<<" :";
   cin>>A[i][j];
  }

 cout<<"Calculating the remaining requirement\n";
 for(i=1;i<=p;i++)
  {
   for(j=1;j<=r;j++)
    {
     if(A[i][j]<R[j])
      {
         N[i][j]=P[i][j]-A[i][j];
         R[j]=R[j]-A[i][j];
         cout<<N[i][j];
      }
    cout<<"\t";
   }
     cout<<"\n";
    }

    cout<<"\nChecking for remianing allocation\n";
    for(i=1;i<=p;i++)
     {
      count=0;
      for(j=1;j<=r;j++)
       {
         if(N[i][j]<=R[j])
            {
             count++;
            }

       }
      if(count==3)
       {
        for(j=1;j<=r;j++)
         {
            R[j]=R[j]-N[i][j];
            R[j]=R[j]+P[i][j];
            N[i][j]=10000;
         }
        cout<<"\nProcess:P"<<i<<" completed";
        for(j=1;j<=r;j++)
         cout<<R[j]<<"\t";
         cout<<"\n";
       i=0;
       }
     }
    getch();
}
                                    OUTPUT

Enter the no. of processes:3
Enter the no. of resources:3
Enter the values of resources:10
5
8
Enter the maximum values of resources:
P1 -->R1 :8
P1 -->R2 :3
P1 -->R3 :5
P2 -->R1 :7
P2 -->R2 :2
P2 -->R3 :6
P3 -->R1 :3
P3 -->R2 :2
P3 -->R3 :3

Enter the resources allocated:
P1 -->R1 :4
P1 -->R2 :2
P1 -->R3 :3
P2 -->R1 :0
P2 -->R2 :1
P2 -->R3 :0
P3 -->R1 :2
P3 -->R2 :1
P3 -->R3 :2


Process:P1 completed
Process:P2 completed
Process:P3 completed

						
Related docs
Other docs by SandeepRao7
Computer Graphics Lab Practicals
Views: 267  |  Downloads: 1
WAP to find the Optimal Solution for
Views: 15  |  Downloads: 0
Animate a ball by changing its color
Views: 11  |  Downloads: 0
Implementation of resource allocatio
Views: 1  |  Downloads: 0
WAP to find longest common subsequen
Views: 20  |  Downloads: 0
Give an algorithm to determine wheth
Views: 4  |  Downloads: 0
WAP to implement the Knapsack Proble
Views: 40  |  Downloads: 0
Using multimedia software_Extract audio
Views: 5  |  Downloads: 0