Thursday, September 18, 2008

Operating System

palash.cseku@gmail.com
http://shahidul-haque-palash.blogspot.com


Deadlocks---------
MUL_DEAD



#include
#include

#define MAX 50

int n; //no of process

int m; //no of resources

int process_completed=0;

int marked[MAX]={0};


int E[MAX+1];

int A[MAX+1];

int C[MAX+1][MAX+1]={0};

int R[MAX+1][MAX+1]={0};



int match_request(int p)
{


for(int j=0;j {

if( A[j] < R[p][j]) return 0;

}



return 1;

}



void terminate_collect(int p)
{


for(int i=0;i {
A[i]=C[p][i]+A[i];

}

marked[p]=1;

printf("\nCompleted process: %d",p);

process_completed++;

}






void main()
{


printf("\nenter the no of processes\n");

scanf("%d",&n);

printf("\nenter the no of resources\n");

scanf("%d",&m);

//E input
printf("\nenter the Existing resource vector : %d elements \n",m);

for(int i=0;i

//A input

printf("\nenter the Available resources vecor : %d elements \n",m);

for(i=0;i




//C input
printf("\nenter the Current Allocation matrix : %d * %d elements\n",n,m);


for(i=0;i {

for(int j=0;j {

int value;

scanf("%d",&value);

C[i][j]=value;

}

}


//request matrix

printf("\nenter the request matrix %d * %d element\n",n,m);

for( i=0;i {
for(int j=0;j {

int value;

scanf("%d",&value);

R[i][j]=value;


}

}



///execution starts here


int turn=0;

while(1)
{


for(int i=0;i {

if( match_request(i) && !marked[i] )

{

terminate_collect(i);

}


}

turn++;


if(process_completed==n)
{
printf("\n No deadlock here.\n");

return;

}

else if(turn >n+1)
{

printf("\nThere is a deadlock\n");

return;

}
}
}



No comments: