资源简介

操作系统 SPOOLing输出模拟 实验报告有实验代码 、可执行程序、实验分析 完整的实验报告。

资源截图

代码片段和文件信息


#include 
#include 
#include 
#include 
#include 
#include 

struct PCB         
{                   
   long ID;       
   int status;      
   long po;        
   long head;       
   long count;      
   long wait[1000]; 
}PCB[4];
struct ReqBlock    
{  long ID;       
   long len;      
   long head;     
}ReqBlock[128];
struct well       
{                   
   long num[1000];  
   long open;    
   long closed; 
}well[3];

long K[3]; 
long n;    
long r;    
long k;    
long a;   
long b;    
long i;    

void input()
{  printf(“Input the size of user1‘s output file:“);
   scanf(“%ld“&K[1]);
   printf(“Input the size of user2‘s output file:“);
   scanf(“%ld“&K[2]);
}

void init()
{
   memset(PCB0sizeof(PCB));
   PCB[1].ID=1;
   PCB[2].ID=2;
   PCB[3].ID=3;
   PCB[3].status=2;
   memset(well0sizeof(well));
   n=0;         
}

void UserServer(long kx)
{   a=rand()%10;
   ++PCB[kx].po;
   PCB[kx].wait[PCB[kx].po]=a;
   if (a==0)
   {   well[kx].open=well[kx].closed+1;
      for (i=1;i<=PCB[kx].po;i++)
 well[kx].num[++well[kx].closed]=PCB[kx].wait[i];
      PCB[kx].po=0;
      PCB[kx].count++;
      if (PCB[kx].count==K[kx])  
 PCB[kx].status=3;        
      if (PCB[3].status==2)       
 PCB[3].status=0;         
      if (well[kx].closed==1000 && PCB[kx].status==0)
 PCB[kx].status=1;         
      n++;
      ReqBlock[n].ID=kx;
      ReqBlock[n].head=well[kx].open;
      ReqBlock[n].len=well[kx].closed-well[kx].open+1;
      printf(“Process %ld produces a block %ld!\n“kxn);
   }
}

void SpoolingServer()
{    PCB[3].po++;
    b=PCB[3].po;
    printf(“Output block %ld: (ID=%ld)\n“bReqBlock[b].ID);
    for (i=1;i<=ReqBlock[b].len;i++)
{     printf(“%ld “well[ReqBlock[b].ID].num[i+ReqBlock[b].head-1]);
}
    printf(“\n“);
    if (PCB[3].po==n)
{    PCB[3].status=2;
      
       if (PCB[1].status==3 && PCB[2].status==3)
   PCB[3].status=3;
}
}

void work()
{    while (PCB[1].status!=3 || PCB[2].status!=3 || PCB[3].status!=3)
   {  r=rand()%100+1;       
      if (r<=45)
 k=1;
      else if (r<=90)
 k=2;
  else
    k=3;
      if (PCB[k].status!=0)
 continue;           
      switch (k)
      {
case 1:   UserServer(1);  break;
case 2:   UserServer(2);  break;
case 3:   SpoolingServer();  break;
      }
   }
}

void main()
{
  printf(“\nSPOOLing output simulation...\n\n“);
  srand(time(NULL));
  input();    
  init();    
  work();   
  printf(“\nsimulation over!!\n“);
  getch();

 }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    1499136  2009-11-22 21:29  操作系统-实验4-SPOOLing输出模拟实验\实验4.doc

     文件       2639  2009-11-16 20:29  操作系统-实验4-SPOOLing输出模拟实验\spl.c

     文件      50725  2009-11-16 23:21  操作系统-实验4-SPOOLing输出模拟实验\SPL.EXE

     目录          0  2009-11-22 21:29  操作系统-实验4-SPOOLing输出模拟实验

----------- ---------  ---------- -----  ----

              1552500                    4


评论

共有 条评论