操作系统课程设计

 
实验目的
了解进程管理的实现方法,理解和掌握处理进程同步问题的方法并完成程序设计。
实验内容:
实现银行家算法、进程调度的过程模拟。
实验步骤:
    理解银行家算法的核心机制;
设计相应数据结构;
编程实现;
测试。
 
理解进程的三状态调度过程;
设计调度算法;
编程实现;
测试。
实验结果 :
所实现的系统提供一个用户界面,可以在上边发出资源申请命令,系统应能给出是否可以接受申请,并且有结论输出;
所实现的系统根据一个进程调度命令文件,模拟进程的各种调度过程,用适合的表达方式表示出来。
// 进程调度的过程模拟

// PStateConvert.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include <malloc.h>
#include "trique.h"
#include "iostream.h"
int  r[3]={0};
void readFile(prdy &ready)

 int pid,runtime,iotime,ioclock,key=0;
 prdy p[4];
 FILE *fp=NULL;
 p[0] = ready;
 p[1] = (prdy)malloc(sizeof(rdy));
 p[2] = (prdy)malloc(sizeof(rdy));
 p[3] = (prdy)malloc(sizeof(rdy));
 p[1]->next = NULL;
 p[2]->next = NULL;
 p[3]->next = NULL;
 //p->next = NULL;
 if((fp = fopen("proCtrFile.txt","rb"))==NULL){
  printf("打开文件失败!"); 
 }
 do{ 
  key ++;  
  fscanf(fp,"%d",&pid);
  p[key]->que = pid;
   fgetc(fp);
  fscanf(fp,"%d",&runtime);
  p[key]->rtm = runtime;
  fgetc(fp);
  fscanf(fp,"%d",&ioclock);
  p[key]->iotm = ioclock; 
  fgetc(fp);
  fscanf(fp,"%d",&iotime);
  p[key]->iolong = iotime;
  fgetc(fp);
  p[0]->next = p[key];
  p[0] = p[0]->next;
  if(key == 3) break;
//用三个指针变量来存储中间的输入。因为同一个指针变量指向相同的空间,会使结果
//中出现的值都为一样的;  
 }while(true);
 fclose(fp);
}
void delFromReady(prdy &ready){
 prdy p,q;
 p = ready;
 q = p->next;
 p->next = q->next;
}
void insertToSus()
{
 printf("阻塞过程中... .../n");
}
void delFromSus()
{
 printf("阻塞结束!/n");
}
void insertToReady(prdy &ready,prdy runQue)
{
 prdy p;
 p = ready;
 while(p->next){
  p = p->next;
 }
 runQue->next = NULL;
 p->next = runQue;
}
void roundrun(prdy &ready)
{
 prdy p, runQue;
 int time;
 p = ready;
 do{
  getchar();//接受任意键
  //runQue = insertToRun(p->next);//就绪队列拿出一个进程放入运行队列
  runQue = p->next;
  delFromReady(ready);
  time = r[runQue->que] ++;
  if(time == runQue->iotm){
   for(int i=0;i < runQue->iolong;i++){    
    insertToSus();    
   }   
   delFromSus();
   insertToReady(ready,runQue);
  }else
   if(time == runQue->rtm){
    printf( "第%d个进程运行结束!" , runQue->que);    
   }
  else{
   printf("一个时间片结束!/n");
   insertToReady(ready,runQue);
  }
  printf("/n任意键继续... .../n");
  //delFromRun(runQue);
 }while(p->next!=NULL);
}

int main(int argc, char* argv[])
{
 prdy ready;   //就绪队列
 prun qrun=NULL;     //运行队列
 pspd suspend=NULL;  //阻塞队列
 ready = (prdy)malloc(sizeof(rdy));
 ready->next = NULL;
 readFile(ready);
ready;  
 roundrun(ready); 
 return 0;
}
 
实验目的: 了解虚拟存储器管理的方法,理解置换算法的工作原理。
实验内容: 编程实现 LRU 等置换算法,模拟实现虚拟存储器的地址变换过程。
实验步骤:
理解 LRU 等置换算法 ;理解 虚拟存储器的地址变换过程。
编程实现;
测试
实验结果: 所实现的系统应能形象地表示出置换算法的运行情况,以及将输入的逻辑地址变换成物理地址的过程。
 
 // LRU.cpp : Defines the entry point for the console application.
                      //
#include "stdafx.h"
#include <iostream.h>
int ye[10]={5,3,1,2,1,3,2,4,2,4};
int yeSize[3];
int isExists(int key)
{
 for(int i=0;i<3;i++)
  if(yeSize[i] == ye[key]) 
   return yeSize[i];  
 return 0;
}
void exchange(int pos,int key)
{
 int ecg;
 ecg = yeSize[pos];
 yeSize[pos] = yeSize[2];
 yeSize[2] = ecg;
}
void Print(bool isType,int key)
{
 if(isType)
  cout << ye[key] << "命中" << endl;
 else{
  cout << ye[key] << "未命中" <<endl;
  cout << "淘汰" << yeSize[0] <<endl;
 }
}
int LRU()
{
 int key = 0;
 int pos;
 while( key!=10 )
 {
  if( pos = isExists(key) )
  {
   Print(true,key);//命中
   exchange(pos,key);
  }
  else{
   Print(false,key);//淘汰yeSize[0]
   //替换
   yeSize[0]=yeSize[1];
   yeSize[1]=yeSize[2];
   yeSize[2] = ye[key];
  }
  key ++;
 }
 return 1;
}
int main(int argc, char* argv[])

 LRU();
 //Print();
 return 0;
}
 
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值