资源简介

实现作业调度(先来先服务)、进程调度功能(时间片轮转) 实现内存管理功能(连续分配)。 实现文件系统功能(选作) 这些功能要有机地连接起来

资源截图

代码片段和文件信息

import java.util.linkedList;
import java.util.Random;


public class ProcessMemoryController {

    private class PCB {
        String name;       //进程名
        double arrtime;    //到达时间
        double needtime;   //需要运行时间
        double usedtime;   //已用时间
        int needmemo;      //所需内存
        int address;       //主存起始位置
        char state;        //进程状态
    }

    private class MemoItem {//内存表条目
        int address = 0;
        int length = 0;
        char state = ‘F‘;//B代表busy或F代表free

        public MemoItem(int address int length) {
            this.address = address;
            this.length = length;
        }
    }

    int NUM = 6;//进程数
    int ACCURACY = 1;//控制格式化后小数点后面的位数
    int THRESHOLD = 3;//允许并发的进程数量,小于时从后备队列调入进程
    int MINSIZE = 10;//控制内存碎片的产生

    PCB[] pcb = new PCB[NUM];
    linkedList memoList = new linkedList<>();

    double pTime;     //时间片
    int run;       //当前运行的进程,没有则为-1
    long lastTime;  //每次调度程序都记录当前时间
    long beginTime;//程序开始时间

    boolean isAllFinished() {
        for (int i = 0; i < NUM; i++) {
            if (pcb[i].state != ‘F‘) return false;
        }
        return true;
    }

    void init() {
        run = -1;

        Random r = new Random();

        for (int n = 0; n < NUM; n++) {
            pcb[n] = new PCB();
            pcb[n].name = Character.toChars(65 + n)[0] + ““;
            pcb[n].needtime = r.nextDouble() * 5 + 5;//5到10秒
            pcb[n].needmemo = r.nextInt(120) + 30;//需要的内存为30到150的随机数


            if (n == 0) {
                pcb[n].arrtime = 0;
                pcb[0].needmemo = 50;
            } else {
                pcb[n].arrtime = r.nextDouble() * 5 + 1;
                pcb[n].needmemo = r.nextInt(120) + 30;//需要的内存为30到150的随机数
            }
        }
        for (int n = 0; n < NUM; n++) {
            pcb[n].usedtime = 0;
            pcb[n].address = 0;
            pcb[n].state = ‘U‘;
        }

        //设置起始地址为30,初始化的长度在50到100之间
        MemoItem first = new MemoItem(30 r.nextInt(50) + 50);
        memoList.add(first);
        MemoItem prev = first;
        for (; ; ) {
            int address = prev.address + prev.length;
            if (address >= 500) break;
            int length = r.nextInt(50) + 50;
            MemoItem ano = new MemoItem(address length);
            memoList.add(ano);
            prev = ano;
        }
    }


    String d2s(double d) {
        String tmp = d + ““;
        int index = tmp.indexOf(“.“);
        return tmp.substring(0 index + ACCURACY + 1);
    }


    void sortByArrtime() {
        int i j;
        PCB temp;
        for (i = 0; i < NUM - 1; i++) //按照到达时间排序
        {
            for (j = 0; j < NUM - 1 - i; j++) {
                if (pcb[j + 1].arrtime < pcb[j].arrtime) {
                    temp = pcb[j];
                    pcb[j] = pcb[j + 1];
                    pcb[j + 1] = temp;
                }
            }
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-20 13:19  操作系统课程设计\
     文件         217  2017-12-13 21:59  操作系统课程设计\ProcessMemoryController$1.class
     文件         532  2017-12-13 21:59  操作系统课程设计\ProcessMemoryController$MemoItem.class
     文件         689  2017-12-13 21:59  操作系统课程设计\ProcessMemoryController$PCB.class
     文件        6688  2017-12-13 21:59  操作系统课程设计\ProcessMemoryController.class
     文件       10205  2017-12-13 20:34  操作系统课程设计\ProcessMemoryController.java
     文件      332288  2018-01-20 13:18  操作系统课程设计\课程设计.doc

评论

共有 条评论