Java 动态模拟操作系统进程调度算法
作者:肥学 时间:2023-04-10 15:09:20
实验目的
通过对进程调度算法的模拟,进一步理解进程的基本概念,加深对进程运行状态和进程调度过程、调度算法的理解。
设备与环境
硬件设备:PC机一台
软件环境:安装Windows操作系统,并安装相关的程序开发环境,如C \C++\Java 等编程语言环境。
实验内容
实验采用了java语言编程模拟N个进程采用动态高优先权优先进程调度算法。该算法就是按照优先权的大小运行进程,如果一个时间片内未运行完,则将优先权数减3后再插入到链表中按priority的顺序进行排序找到最大的priority作为下一个运行进程且在就绪队列里面的进程priority会加1。
主模块:
动态priority排序模块:
用来保证头部永远最大
到达时间进入就绪状态模块:
计算周转时间和带权周转时间:
实验结果及分析
输入的信息
初始权值都为100,needtime为还需要的时间
进程 到达时刻 服务时间
A03
B26
C44
D65
E82
以A为例:
最后结束时:
部分代码展示?
//创建结构
class PCB{
String ID;
int priority=-1;
int cputime;//服务的时间
int needtime;//进程还需的时间
String state="wait";
int arrivetime;
PCB next;
public PCB(String ID,int priority,int cputime,int arrivetime){
this.ID=ID;
this.priority=priority;
this.cputime=cputime;
this.arrivetime=arrivetime;
}
}
判断是否到达,进程进入时间
for(int i=0;i<arr.size();i++){
if(h==arr.get(i).arrivetime){
Dynamic_priority.sort(arr.get(i));
arr.remove(i);}}
//将进程转为就绪态并排序
public static void sort(PCB pcb){
PCB tmp=null;
if(ready==null){//当头结点为空
ready=pcb;
tail=pcb;}
else {if(pcb.priority>ready.priority){//如果这个结点priority大于头priority
pcb.next=ready;
ready=pcb;}
else {
boolean m=false;
tmp=ready;//q
while (m==false){
if(tail.priority>=pcb.priority){//插入尾端
tail.next=pcb;
tail=pcb;
pcb.next=null;
m=true; }
else {
if(tmp.priority>=pcb.priority&&pcb.priority>tail.priority){//逐渐遍历插到tmp前
pcb.next=tmp.next;
tmp.next=pcb;
m=true;
} else { tmp=tmp.next;
来源:https://blog.csdn.net/jiahuiandxuehui/article/details/121469614
标签:Java,操作系统,进程调度算法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java运行环境搭建的图文教程
2021-06-22 07:44:41
![](https://img.aspxhome.com/file/2023/5/106165_0s.png)
Android仿微信语音聊天界面设计
2023-01-10 01:33:28
C#版Tesseract库的使用技巧
2023-01-24 20:07:53
![](https://img.aspxhome.com/file/2023/0/108730_0s.png)
Android GridView实现滚动到指定位置的方法
2021-08-29 10:04:21
Android教程之开机流程全面解析
2023-02-18 21:02:44
面试初级Java开发问到Arrays
2023-11-27 05:40:04
Java类加载器和类加载机制实例分析
2021-07-18 03:32:26
详解Android StrictMode严格模式的使用方法
2023-09-14 17:03:39
C#开发Winform控件之打开文件对话框OpenFileDialog类
2023-04-19 10:53:16
![](https://img.aspxhome.com/file/2023/3/116513_0s.jpg)
关于Spring Cloud 本地属性覆盖的问题
2021-09-17 09:26:42
SpringBoot+SpringCache实现两级缓存(Redis+Caffeine)
2023-10-02 05:20:58
![](https://img.aspxhome.com/file/2023/5/97965_0s.png)
微服务分布式架构实现日志链路跟踪的方法
2023-11-29 15:43:16
![](https://img.aspxhome.com/file/2023/3/60123_0s.jpg)
Unity3D UGUI实现缩放循环拖动卡牌展示效果
2022-02-19 10:37:24
![](https://img.aspxhome.com/file/2023/3/98203_0s.gif)
Java如何在 Word 中设置上、下标
2023-10-15 21:04:10
![](https://img.aspxhome.com/file/2023/2/77972_0s.png)
SpringBoot整合TKMyBatis实现单表增删改查操作
2022-01-30 19:52:28
![](https://img.aspxhome.com/file/2023/2/82042_0s.png)
SpringMVC+Shiro的基本使用及功能介绍
2021-11-26 13:12:40
![](https://img.aspxhome.com/file/2023/2/126342_0s.png)
Java hashCode原理以及与equals()区别联系详解
2023-03-04 15:37:56
windows定时器配置执行java jar文件的方法详解
2023-04-17 16:40:21
![](https://img.aspxhome.com/file/2023/4/61544_0s.png)
Java计算文本MD5加密值的方法示例
2023-11-15 13:18:48
Java中驼峰命名与下划线命名相互转换
2021-10-01 00:56:47