资源分配os概念 [英] resource allocation os concept

查看:102
本文介绍了资源分配os概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我这是为什么它没有移到第二页的错误吗?

 #include   <   iostream.h  > 
 #include   <   stdio.h  > 
 #include   <   conio.h  > 
 #include   <   graphics.h  > 

 int  p,r,row,col,q,e,i,d,j,k,resno,res_held,res_req,temp,temp1,temp2;
 int 调整[ 15 ] [ 15 ] ,warsh [ 15 ] [ 15 ],找到了,tag =  1 ,flag1 =  0 ,req [ 5 ] [ 5 ] [字符标志[ 5 ],t [ 5 ];
主要的()
{
 int  gm,gd = DETECT;
initgraph(& gd,& gm," );
  settextstyle( 1  0  3 ) ;
  setcolor( 14 );
  setbkcolor( 0 );
   outtextxy( 10  20 " 操作系统");
  outtextxy( 10  50 "  PROJECT ON");
  settextstyle( 1  0  6 ) ;
  setcolor( 2 );
  setbkcolor( 0 );
  outtextxy( 60  120 " 资源分配");
  outtextxy( 230  230 "  GRAPH");
  settextstyle( 1  0  2 ) ;
  setcolor( 4 );
  setbkcolor( 0 );
  outtextxy( 250  350 "  BY:-shashi");
  outtextxy( 300  380 "  Shashi");
 getch();
 void  deadlock();
  getch();
  返回  0 ;
}
无效 deadlock()
{
  clrscr();
  void  screen();
  clrscr();
  textbackground( 7 );
  textcolor( 0 );
  clrscr();
  setbkcolor( 1 );
  gotoxy( 35  1 );
  cout<< " ;
  gotoxy( 35  2 );
  cout<< " ;
  gotoxy( 3  3 );
  cout<< " ;
  cin> p;
  同时(p< =  0  || p> 5)
  {
   gotoxy( 41  3 );
   cout<< " ;
   gotoxy( 41  3 );
   cin> p;
  }
  gotoxy( 3  5 );
  cout<< " ;
  cin> r;
    同时(r< =  0  || r> 5)
  {
   gotoxy( 41  5 );
   cout<< " ;
   gotoxy( 41  5 );
   cin> r;
  }
   for (i =  0 ; i< r;>标志[i] =  F';
       for (i =  0 ; i<(p + r); i ++)
     for (j =  0 ; j<(p + r); j ++)
      adj [i] [j] =  0 ;
 for (i =  0 ; i< p;>  for (j =  0 ; j< r;> {
     req [i] [j] =  0 ;
     hold [i] [j] =  0 ;
   }
  gotoxy( 3  7 );
  cout<< " ;
  gotoxy( 3  8 );
  cout<< " ;
  gotoxy( 19  7 );
  cout<< " ;
  gotoxy( 19  7 );
 //  printf("--------------------- -); 
  gotoxy( 45  8 );
  cout<< " ;
  gotoxy( 45  8 );
  //  printf("--------------"); 
  row =  10 ;
  temp =  0 ;
   for (i =  0 ; i< p; i ++)>
  {
    col =  7 ;
    甲氧基(col,row);
    cout< i;
    col = col +  15 ;
    甲氧基(col,row);
    cin> resno;
    temp = temp + resno;
     while (温度> r || temp<  0 )
    {
     temp = temp-resno;
     甲氧基(col,row);
     cout<< " ;
     甲氧基(col,row);
     cin> resno;
     temp = temp + resno;
    }
    col = col + 24;
    同时(resno> 0)
    {
       甲氧基(col,row);
       cout<< " ;
       col = col + 1;
       cin> res_held;
       同时(标志[res_held] == '  T' || res_held> r-  1  || res_held<  0 )
       {
col = col-  1 ;
甲氧基(col,row);
cout<< " ;
甲氧基(col,row);
cout<< " ;
col = col + 1;
甲氧基(col,row);
cin> res_held;
}
adj [p + res_held] [i] =  1 ;
hold [i] [res_held] =  1 ;
flag [res_held] = '  T';
col = col + 4;
resno--;
     }
     row = row + 2;
  }

  clrscr();
  gotoxy( 3  2 );
  cout<< " ;
  gotoxy( 3  3 );
  cout<< " ;
  gotoxy( 19  2 );
  cout<< " ;
  gotoxy( 19  3 );
  cout<< " ;
  gotoxy( 48  2 );
  cout<< " ;
  gotoxy( 48  3 );
  cout<< " ;
  row =  5 ;
   for (i =  0 ; i< p; i ++)>
  {
    col =  7 ;
    temp1 = temp2 =  0 ;
    flag1 =  1 ;
    甲氧基(col,row);
    cout< i;
    col = col +  15 ;
    甲氧基(col,row);
    cin> resno;
     (e =  0 ; e< r;> 如果(按住[i] [e]>  0 )
       temp1 = temp1 +  1 ;
     temp2 = r-temp1;
    如果(resno< 0 || resno> temp2)
     flag1 =  0 ;
    同时(标志1 ==  0 )
    {
     甲氧基(col,row);
     cout<< " ;
     甲氧基(col,row);
     cin> resno;
     如果(resno< 0 || resno> temp2)
      flag1 =  0 ;
     其他
      flag1 =  1 ;
    }
    col = col + 30;
     for (k =  0 ; k< r; k ++)>
t [k] = '  F';
    同时(resno> 0)
    {
       甲氧基(col,row);
       cout<< " ;
       col = col + 1;
       甲氧基(col,row);
       cin> res_req;
       如果(hold [i] [res_req] ==  1  || res_req<  1  || t [res_req] ==  T')
tag =  0 ;
      同时(标记==  0 )
{
甲氧基(col,row);
cout<< " ;
甲氧基(col,row);
cin> res_req;
如果(hold [i] [res_req] ==  1  || res_req< '  0 ;
其他
tag =  1 ;
}
t [res_req] = '  T';
adj [i] [p + res_req] =  1 ;
req [i] [res_req] =  1 ;
col = col + 4;
resno-; // 没有有效资源的请求,没有输入.
     }
     row = row + 2;
  }
  /*   WARSHALL算法的实现*/
   for (i =  0 ; i< p + r;>  0 ; j< p + r;> warsh [i] [j] = adj [i] [j];
    for (k =  0 ; k< p + r;>  0 ; i< p + r;>  0 ; j< p + r;> warsh [i] [j] =(warsh [i] [j] ||(warsh [i] [ k]&& warsh [k] [j]));
  i =  0 ;
  found =  0 ;
   while (i< p + r>  if (warsh [i] [i] ==  1 )// 如果战争中存在一个周期,
      找到=  1 ;
     其他
      i ++;
  clrscr();
   void  graph();
  settextstyle( 1  0  5 ) ;
  setcolor( 15 );
  如果(找到==  1 )
   outtextxy( 50  410 "  DEADLOCK EXISTS");
  其他
   outtextxy( 50  410 "  DEADLOCK不存在");
  //  getch(); 
  返回;
}
无效 screen()
{
   int 图形模式;
   int  graphdriver = DETECT;
  initgraph(& graphdriver,& graphmode," );
  settextstyle( 1  0  6 ) ;
  setcolor( 4 );
  setbkcolor( 15 );
  outtextxy( 80  100 " 单" );
  outtextxy( 130  200 " 资源");
  outtextxy( 200  300 "  INSTANCE");
  返回//  getch(); 
//  closegraph(); 
 //  return; 
}
无效 graph()
{
   int 图形模式;
   int  graphdriver = DETECT;
   int  x,y,i,u,v,w,u1,v1,w1,x1,linex,liney,linex1,liney1;
   int  col;
  initgraph(& graphdriver,& graphmode," );
  settextstyle( 1  0  4 ) ;
  setcolor( 5 );
  outtextxy( 100  10 " 资源分配图");
  setcolor( 4 );
  settextstyle( 1  0  3 ) ;
  outtextxy( 450  300 " 请求");
  setcolor( 1 );
  outtextxy( 450  340 "  HOLDING");
  u =  60 ; v =  60 ;
  w =  115 ; x =  90 ;
  u1 =  40 ; v1 =  230 ;
  w1 =  95 ; x1 =  260 ;
  col =  7 ;
  setbkcolor( 3 );
  setcolor( 15 );
   for (i =  0 ; i< r;> {
   如果(i%2!=  0 )
   {
    矩形(u,v,w,x);
    setcolor( 14 );
    settextstyle( 0  0  2 ) ;
    如果(i ==  1 )
      outtextxy(u + 10,v + 10," );
    如果(i ==  3 )
      outtextxy(u + 10,v + 10," );
    如果(i ==  5 )
      outtextxy(u + 10,v + 10," );
    u = u + 115;
    w = w + 115;
    setcolor( 15 );
   }
   其他
   {
    矩形(u1,v1,w1,x1);
    setcolor( 14 );
    settextstyle( 0  0  2 ) ;
    如果(i ==  0 )
      outtextxy(u1 + 10,v1 + 10," );
    如果(i ==  2 )
      outtextxy(u1 + 10,v1 + 10," );
    如果(i ==  4 )
      outtextxy(u1 + 10,v1 + 10," );
    u1 = u1 +  115 ;
    w1 = w1 +  115 ;
    setcolor( 15 );
   }
  }
  x =  50 ;
  y =  150 ;
  setcolor( 15 );
   for (i =  0 ; i< p;> {
    setcolor( 15 );
    circle(x,y, 35 );
    setcolor( 1 );
    settextstyle( 0  0  2 ) ;
    如果(i ==  0 )
     outtextxy(x-  20 ,y-  6 "  P0");
如果(i ==  1 )
     outtextxy(x-  20 ,y-  6 "  P1");
    如果(i ==  2 )
     outtextxy(x-  20 ,y-  6 "  P2");
    如果(i ==  3 )
     outtextxy(x-  20 ,y-  6 "  P3");
    如果(i ==  4 )
     outtextxy(x-  20 ,y-  6 "  P4");
    x = x +  85 ;
    col = col +  11 ;
  }
  setcolor( 4 );
  setlinestyle( 2  1  3 ) ;
   for (i =  0 ; i< p;> {
    for (j =  0 ; j< r;> {
     如果(req [i] [j]>  0 )
     {
       如果(j%2!=  0 )
       {
linex = 30 + 65 * j;
linex1 =  70 ;
liney1 =  123 ;
       }
       其他
       {
linex = 50 + 75 * j;
linex1 =  250 ;
liney1 =  177 ;
       }
线性= 50 + 85 * i;
line(liney,liney1,linex,linex1);
       //  getch(); 

      }
    }
  }
  setcolor( 1 );
  setlinestyle( 0  1  3 ) ;
   for (i =  0 ; i< p;> {
     for (j =  0 ; j< r;> {
      如果(保持[i] [j]> 0)
      {
       如果(j%2!=  0 )
       {
linex = 30 + 65 * j;
linex1 =  90 ;
       }
       其他
       {
linex = 70 + 65 * j;
linex1 =  230 ;
       }
线性= 50 + 85 * i;
liney1 =  150 ;
line(liney,liney1,linex,linex1);
       //  getch(); 
     }
   }
 }
返回;
} 

解决方案

在您的main()中,您有以下几行:

getch();
void deadlock();
getch();



您可能想写这个:

getch();
deadlock();
getch();



在第一种情况下,该函数不会被调用. />

can any body tell me wats the error in this why it is not moving to second page

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

int p,r,row,col,q,e,i,d,j,k,resno,res_held,res_req,temp,temp1,temp2;
int adj[15][15],warsh[15][15],found,tag=1,flag1=0,req[5][5],hold[5][5];
  char flag[5], t[5] ;
main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"c:\\tc\\bgi");
  settextstyle(1,0,3);
  setcolor(14);
  setbkcolor(0);
   outtextxy(10,20,"  OPERATING SYSTEM");
  outtextxy(10,50,"            PROJECT ON");
  settextstyle(1,0,6);
  setcolor(2);
  setbkcolor(0);
  outtextxy(60,120,"RESOURCE ALLOCATION ");
  outtextxy(230,230,"GRAPH");
  settextstyle(1,0,2);
  setcolor(4);
  setbkcolor(0);
  outtextxy(250,350,"BY:- shashi ");
  outtextxy(300,380,"   Shashi");
 getch();
void deadlock();
  getch();
  return 0;
}
void deadlock()
{
  clrscr();
 void screen();
  clrscr();
  textbackground(7);
  textcolor(0);
  clrscr();
  setbkcolor(1);
  gotoxy(35,1);
  cout<<"RESOURCE ALLOCATION";
  gotoxy(35,2);
  cout<<"--------------------";
  gotoxy(3,3);
  cout<<"Enter the total number of processes upto 5 : ";
  cin>>p;
  while (p<=0 || p>5)
  {
   gotoxy(41,3);
   cout<<"     ";
   gotoxy(41,3);
   cin>>p;
  }
  gotoxy(3,5);
  cout<<"Enter the total number of resources upto 5 : ";
  cin>>r;
    while (r<=0 || r>5)
  {
   gotoxy(41,5);
   cout<<"     ";
   gotoxy(41,5);
   cin>>r;
  }
  for (i=0; i<r;>    flag[i] = 'F';
      for (i=0; i<(p+r); i++)
    for (j=0; j<(p+r); j++)
      adj[i][j]=0;
	for (i=0; i<p;>   for(j=0; j<r;>   {
     req[i][j] = 0;
     hold[i][j] = 0;
   }
  gotoxy (3,7);
  cout<<"PROCESSES";
  gotoxy(3,8);
  cout<<"---------";
  gotoxy(19,7);
  cout<<"NO: OF RESOURCES HELD";
  gotoxy(19,7);
 // printf("----------------------");
  gotoxy(45,8);
  cout<<"RESOURCES HELD";
  gotoxy(45,8);
  //printf("--------------");
  row=10;
  temp=0;
  for (i=0;i<p;i++)>
  {
    col=7;
    gotoxy(col,row);
    cout<<i;
    col = col + 15;
    gotoxy(col,row);
    cin>>resno;
    temp=temp+resno;
    while (temp > r || temp < 0)
    {
     temp=temp-resno;
     gotoxy(col,row);
     cout<<"     ";
     gotoxy(col,row);
     cin>>resno;
     temp=temp+resno;
    }
    col= col+24;
    while(resno>0)
    {
       gotoxy(col,row);
       cout<<"R";
       col=col+1;
       cin>>res_held;
       while (flag[res_held] == 'T' || res_held > r-1 || res_held < 0)
       {
	  col=col-1;
	  gotoxy(col,row);
	  cout<<"            ";
	  gotoxy(col,row);
	  cout<<"R";
	  col=col+1;
	  gotoxy(col,row);
	  cin>>res_held;
	}
	adj[p+res_held][i]=1;
	hold[i][res_held]=1;
	flag[res_held] = 'T';
		col=col+4;
	resno--;
     }
     row=row+2;
  }

  clrscr();
  gotoxy (3,2);
  cout<<"PROCESSES";
  gotoxy(3,3);
  cout<<"---------";
  gotoxy(19,2);
  cout<<"NO: OF RESOURCES REQUESTED";
  gotoxy(19,3);
  cout<<"--------------------------";
  gotoxy(48,2);
  cout<<"RESOURCES REQUESTED";
  gotoxy(48,3);
  cout<<"-------------------";
  row=5;
  for (i=0;i<p;i++)>
  {
    col=7;
    temp1 = temp2 = 0;
    flag1=1;
    gotoxy(col,row);
    cout<<i;
    col = col + 15;
    gotoxy(col,row);
    cin>>resno;
    for (e=0; e<r;>     if (hold[i][e] > 0)
       temp1 = temp1 + 1;
     temp2 = r - temp1;
    if (resno<0 || resno>temp2)
     flag1=0;
    while (flag1==0)
    {
     gotoxy(col,row);
     cout<<"     ";
     gotoxy(col,row);
     cin>>resno;
     if (resno<0 || resno>temp2)
      flag1=0;
     else
      flag1=1;
    }
    col= col+30;
    for (k=0;k<r;k++)>
	t[k]='F';
    while (resno>0)
    {
       gotoxy(col,row);
       cout<<"R";
       col=col+1;
       gotoxy(col,row);
       cin>>res_req;
       if (hold[i][res_req] == 1 || res_req < 0 || res_req > r-1 || t[res_req] == 'T')
	tag = 0;
      while (tag==0)
	     {
	  gotoxy(col,row);
	  cout<<"   ";
	  gotoxy(col,row);
	  cin>>res_req;
	  if (hold[i][res_req] == 1 || res_req < 0 || res_req >=r || t[res_req] == 'T')
	     tag = 0;
	  else
	     tag = 1;
		}
	t[res_req]='T';
	adj[i][p+res_req] = 1;
	req[i][res_req] = 1;
	col=col+4;
	resno--;//requested no of valid resource no inputs are taken.
     }
     row=row+2;
  }
  /* Implementation of WARSHALL'S ALGORITHM */
  for (i=0; i<p+r;>   for (j=0; j<p+r;>    warsh[i][j] = adj[i][j];
   for (k=0; k<p+r;>    for (i=0; i<p+r;>     for (j=0; j<p+r;>      warsh[i][j] = (warsh[i][j] || (warsh[i][k] && warsh[k][j]));
  i=0;
  found=0;
  while (i<p+r>    if (warsh[i][i] == 1)//if a cycle exists in the warshall algorithim
      found = 1;
     else
      i++;
  clrscr();
  void graph();
  settextstyle(1,0,5);
  setcolor(15);
  if (found == 1)
   outtextxy(50,410,"DEADLOCK EXISTS");
  else
   outtextxy(50,410,"DEADLOCK DOES NOT EXIST");
  //getch();
  return;
}
void screen()
{
  int graphmode;
  int graphdriver=DETECT;
  initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
  settextstyle(1,0,6);
  setcolor(4);
  setbkcolor(15);
  outtextxy(80,100,"SINGLE");
  outtextxy(130,200,"RESOURCE");
  outtextxy(200,300,"INSTANCE");
  return ;
//  getch();
//  closegraph();
 // return;
}
void graph()
{
  int graphmode;
  int graphdriver=DETECT;
  int x,y,i,u,v,w,u1,v1,w1,x1,linex,liney,linex1,liney1;
  int col;
  initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
  settextstyle(1,0,4);
  setcolor(5);
  outtextxy(100,10,"RESOURCE ALLOCATION GRAPH");
  setcolor(4);
  settextstyle(1,0,3);
  outtextxy(450,300,"REQUESTING");
  setcolor(1);
  outtextxy(450,340,"HOLDING");
  u=60;v=60;
  w=115;x=90;
  u1=40;v1=230;
  w1=95;x1=260;
  col = 7;
  setbkcolor(3);
  setcolor(15);
  for (i=0; i<r;>  {
   if (i%2!=0)
   {
    rectangle(u,v,w,x);
    setcolor(14);
    settextstyle(0,0,2);
    if (i==1)
      outtextxy(u+10,v+10,"R1");
    if (i==3)
      outtextxy(u+10,v+10,"R3");
    if (i==5)
      outtextxy(u+10,v+10,"R5");
    u = u+115;
    w = w+115;
    setcolor(15);
   }
   else
   {
    rectangle(u1,v1,w1,x1);
    setcolor(14);
    settextstyle(0,0,2);
    if (i==0)
      outtextxy(u1+10,v1+10,"R0");
    if (i==2)
      outtextxy(u1+10,v1+10,"R2");
    if (i==4)
      outtextxy(u1+10,v1+10,"R4");
    u1 = u1 + 115;
    w1 = w1 + 115;
    setcolor(15);
   }
  }
  x=50;
  y=150 ;
  setcolor(15);
  for (i=0; i<p;>  {
    setcolor(15);
    circle(x,y,35);
    setcolor(1);
    settextstyle(0,0,2);
    if (i==0)
     outtextxy(x-20,y-6,"P0");
	if (i==1)
     outtextxy(x-20,y-6,"P1");
    if (i==2)
     outtextxy(x-20,y-6,"P2");
    if (i==3)
     outtextxy(x-20,y-6,"P3");
    if (i==4)
     outtextxy(x-20,y-6,"P4");
    x = x + 85;
    col = col + 11;
  }
  setcolor(4);
  setlinestyle(2,1,3);
  for (i=0; i<p;>  {
   for (j=0; j<r;>   {
     if (req[i][j] > 0)
     {
       if (j%2!=0)
       {
	linex=30+65*j;
	linex1=70;
	liney1=123;
       }
       else
       {
	linex=50+75*j;
	linex1=250;
	liney1=177;
       }
	liney=50+85*i;
	line(liney,liney1,linex,linex1);
       //	getch();

      }
    }
  }
  setcolor(1);
  setlinestyle(0,1,3);
  for (i=0; i<p;>  {
    for (j=0; j<r;>    {
      if (hold[i][j]>0)
      {
       if (j%2!=0)
       {
	linex=30+65*j;
	linex1=90;
       }
       else
       {
	linex=70+65*j;
	linex1=230;
       }
	liney=50+85*i;
	liney1=150;
	line(liney,liney1,linex,linex1);
       //	getch();
     }
   }
 }
return;
}

解决方案

In your main() you have the following lines:

getch();
void deadlock();
getch();



you probably meant to write this:

getch();
deadlock();
getch();



In the first case, the function won''t get called.


i want to execute this code as .cpp extention so plz help it out....


这篇关于资源分配os概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆