本文介绍了资源分配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 ] [ 5 ];
  字符标志[ 5 ],t [ 5 ];
主要的()
{
 int  gm,gd = DETECT;
initgraph(& gd,& gm,"  c:\\ tc \\ bgi" );
  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<< " 输入最多5个进程的总数:" ;
  cin> p;
  同时(p< =  0  || p> 5)
  {
   gotoxy( 41  3 );
   cout<< " " ;
   gotoxy( 41  3 );
   cin> p;
  }
  gotoxy( 3  5 );
  cout<< " 输入最多5的资源总数:" ;
  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<< "  R" ;
       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<< "  R" ;
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<< "  R" ;
       col = col + 1;
       甲氧基(col,row);
       cin> res_req;
       如果(hold [i] [res_req] ==  1  || res_req<  0  || res_req> r-  1  || t [res_req] ==  '  T')
tag =  0 ;
      同时(标记==  0 )
{
甲氧基(col,row);
cout<< " " ;
甲氧基(col,row);
cin> res_req;
如果(hold [i] [res_req] ==  1  || res_req<  0  || res_req> = r || t [res_req] == '  T')
tag =  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;>  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 )// 如果战争中存在一个周期,
      找到=  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,"  c:\\ tc \\ bgi" );
  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,"  c:\\ tc \\ bgi" );
  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,"  R1" );
    如果(i ==  3 )
      outtextxy(u + 10,v + 10,"  R3" );
    如果(i ==  5 )
      outtextxy(u + 10,v + 10,"  R5" );
    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,"  R0" );
    如果(i ==  2 )
      outtextxy(u1 + 10,v1 + 10,"  R2" );
    如果(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 ) ;
    如果(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(); 
     }
   }
 }
返回;
} 
解决方案



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

08-31 04:30