• 语录大全
  • 励志语录
  • 情感语录
  • 名人经典语录
  • 经典爱情语录
  • 网络经典语录
  • 经典台词
  • 当前位置: 工作范文网 > 语录 > 经典爱情语录 > 正文

    操作系统模拟实验:单处理机系统进程调度实验报告

    时间:2020-11-14 10:06:29 来源:工作范文网 本文已影响 工作范文网手机站

    数学与计算机学院 单处理机系统的进程调度 实验报告

    年级07 学号 2007429023 姓名 王阳 成绩

    专业 信计 实验地点 主楼402 指导教师 王硕

    实验项目 单处理机系统的进程调度 实验日期

    实验报告要求:

    一、 实验目的

    1、 加深对进程概念的理解,明确进程和程序的区别。

    2、 深入了解系统如何组织进程、创建进程。

    3、 进一步认识如何实现处理机调度。

    二、 实验原理

    三、 实验要求

    1、 采用时间片轮转调度算法实现进程调度。

    2、 确定进程控制块的内容,进程控制块的组织方式。

    3、 完成进程创建原语和进程调度原语。

    4、 编写主函数对所做工作进行测试。

    四、 实验结果(程序)及分析

    #i nclude <stdio.h>

    #defi ne N 10 〃系统中所允许的最大进程数量

    #defi ne SLOT 5 //时间片大小

    //进程状态枚举

    typedef enum

    {

    }

    }

    }

    }

    Running, 〃运行状态

    Aready, 〃就绪状态

    Block ing //阻塞状态 } ProStatus;

    //进程控制块 typedef struct

    {

    //进程标识符

    //进程标识符

    //进程状态

    //通用寄存器

    //程序计数器寄存器

    〃程序状态字寄存器

    //指向下一个进程的指针

    ProStatus status; int ax,bx,cx,dx; int pc;

    int psw;

    int next;

    } PCB;

    //就绪队列指针

    typedef struct

    {

    int head; // 头指针

    int tail; // 尾指针

    } Ready;

    //模拟寄存器

    //PCB的静态链表

    //PCB的静态链表 PCB pcbArea[N]; int run;

    Ready ready; int pfree;

    〃模拟PCB区域的数组

    〃运行状态程序的指针

    //就绪队列指针

    〃空闲队列的指针

    //初始化运行状态进程指针

    void Ini tRu n()

    {

    run=-1;

    }

    //初始化就绪状态队列

    void Ini tReady()

    {

    ready.head=ready.tail=-1;

    //初始化空闲队列

    void In itFree()

    {

    int temp;

    for(temp=0;temp<N-1;temp++)

    {

    pcbArea[temp]. next=temp+1;

    }

    pcbArea[temp]. next=-1;

    pfree=0;

    }

    //就绪队列出队

    int PopReady() 〃返回结点在PCB区域数组的编号

    {

    int temp;

    if(ready.head==-1)

    {

    printf("就绪队列为空,不能出队。\n"); return -1;

    }

    temp=ready.head;

    ready.head=pcbArea[temp]. next;

    if(ready.head==-1)

    ready.tail=-1;

    pcbArea[temp]. next=-1;

    return temp;

    }

    〃空闲队列出队

    int PopFree() 〃返回结点在PCB区域数组的编号

    {

    int temp;

    if(pfree==-1)

    {

    printf("空闲队列为空,不能出队。\n"); return -1;

    }

    temp=pfree;

    pfree=pcbArea[temp]. next;

    pcbArea[temp]. next=-1;

    return temp;

    //就绪队列入队

    void PushReady(int x) //x为入队结点的编号

    {

    int temp;

    if(ready.head==-1)

    {

    ready.head=x;

    ready.tail=x;

    }

    else

    {

    temp=ready.tail;

    ready.tail=x;

    }

    pcbArea[ready.tail]. next=-1;

    }

    〃创建PCB

    void CreatePCB(int x,PCB pcb) //x为要创建PCB在PCB区域数组的编号

    {

    pcbArea[x].ax=pcb.ax;

    pcbArea[x].bx=pcb.bx;

    pcbArea[x].cx=pcb.cx;

    pcbArea[x].dx=pcb.dx;

    pcbArea[x]. name=pcb .n ame;

    pcbArea[x]. next=-1;

    pcbArea[x].pc=pcb.pc;

    pcbArea[x].psw=pcb.psw;

    pcbArea[x].status=pcb.status;

    }

    //创建进程函数

    void Create(PCB pcb)

    {

    int temp;

    if(pfree==-1)

    {

    printf("空闲队列为空,不能创建进程。\n");

    return;

    }

    temp=PopFree();

    pcb.status=Aready;

    CreatePCB(temp,pcb);

    PushReady(temp);

    //进程调度函数

    void Schedule。

    {

    int temp;

    if(ready.head==-1)

    {

    printf("系统内没有进程可以调度。");

    return;

    } temp=PopReady();

    pcbArea[temp].status=R unning;

    TIME=SLOT; //恢复 CPU 现场

    AX=pcbArea[temp].ax;

    BX=pcbArea[temp].bx;

    CX=pcbArea[temp].cx;

    DX=pcbArea[temp].dx;

    PC=pcbArea[temp].pc;

    PSW=pcbArea[temp].psw;

    run=temp; //将选中的进程赋给运行指针

    printf("当前运行的程序:\n"); //输出调度结果

    printf("进程号:%d\n",pcbArea[run].name);

    printf("进程状态:%d\n",pcbArea[ru n].status);

    printf("寄存器内容:\nAX\tBX\tCX\tDX\tPC\tPSW\n");

    prin tf("%d\t%d\t%d\t%d\t%d\t%d\n",

    pcbArea[ru n].ax,pcbArea[ru n].bx,pcbArea[ru n].cx,pcbArea[ru n].dx,pcbArea[ru n].pc,pcbArea[ru n ].psw);

    } void mai n()

    {

    int temp;

    PCB tmp_pcb;

    printf("请输入进程号,以负数为结束(进程号应保持唯一)。\n\n按任意键进入输入模式: ");

    getchar();

    In itRu n();

    In itReady();

    In itFree();

    \n");printf("请开始输入进程号: while(1)

    \n");

    {

    scan f("%d", &temp);

    if(tempvO)

    break; tmp_pcb. name=temp; tmp_pcb.ax=temp; tmp_pcb.bx=temp; tmp_pcb.cx=temp; tmp_pcb.dx=temp; tmp_pcb.pc=temp; tmp_pcb.psw=temp;

    Create(tmp_pcb); } _ prin tf("\n");

    Schedule(); }

    有关的专题