单处理器进程调度算法模拟,FCFS,RR(q=1),SPN,SRT,HRRN1

这篇博客详细介绍了如何模拟单处理器上的进程调度算法,包括先来先服务(FCFS)、时间片轮转(RR, q=1)、短作业优先(SPN)、最短剩余时间优先(SRT)以及高响应比优先(HRRN1)。内容基于《操作系统——精髓和设计原理》一书的第七版,确保在书中给出的五个进程场景下正确调度。" 110503584,10296038,Python Selenium 自动答题实践:广东开放大学在线作业,"['Python自动化', 'Web自动化', 'selenium库', '在线教育', '爬虫技术']
摘要由CSDN通过智能技术生成

oslab4.h

#ifndef OSLAB4_H
#define OSLAB4_H

#include<iostream>
using namespace std;

class SelectionFunction
{
public:
	SelectionFunction();
	~SelectionFunction();
	void InputProcess();
	void FCFS();
	void RR();
	void SPN();
	void SRT();
	void HRRN(); 

private:

	
	void OutputInformation( char * name);
	int FindTheShortestProcess( int runTime);
	int FindHightestRate (int runTime);
	int FindShortestRemain(int runTime);
	int FindNextExcuteProcess( int currentProcess, int runTime);
	void SetProInformation(int currentProcess , int runTime);

	void ClearProcessInformation();
	//inputed processes information
	struct Process
	{
		char ID;
		unsigned int arrivedTime;
		unsigned int serverTime;
		
	};

	//the calculated information of process 
	struct ProcessInformation
	{
		unsigned int finishTime;
		unsigned int turnaroundTime;
		double rate;
		bool isExcuted;
		bool isFirst;
		int remainTime;
	};

	int length;
	struct Process *process;
	struct ProcessInformation *proInformation;

	void put();
};

#endif

oslab4.cpp

#include"oslab4.h"
SelectionFunction::SelectionFunction()
{
	process = NULL;
	proInformation = NULL;
	length = 0;
}

SelectionFunction::~SelectionFunction()
{
	delete [] process;
	process = NULL;
	delete [] proInformation;
	proInformation = NULL;

}

void SelectionFunction::InputProcess()
{

	cout<<"Input the numbers of process:";
	cin>>length;

	if(length<1)
	{
		cout<<"The numbers of process can't less 1"<<endl;
		return ;
	}

	//dynamic new an array to store process information
	process = new struct Process[length];
	if(process == NULL)
	{
		cout<<"New function error! Quit!"<<endl;
		return ;
	}
	proInformation = new struct ProcessInformation[length];
	if (proInformation == NULL)
	{
		cout<<"New function error! Quit!"<<endl;
		return ;
	}
	ClearProcessInformation();
	
	cout<<"Two nonnagetive umbers for process arrive time and sever time:"<<endl;
	for (int i = 0; i < length; i++)
	{
		cin>>process[i].arrivedTime>>process[i].serverTime;
		process[i].ID = 'A'+i;
		if (process[i].serverTime == 0)
		{
			cout<<"Server time can't be zero!"<<endl;
			return ;
		}
	}


}

void SelectionFunction::FCFS()
{
	int runTime = 0;
	for (int i = 0; i < length; i++)
	{
		if (process[i].arrivedTime>runTi
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
$$完整代码+22页实验报告$$。#大车埋土#进程调度算法包括先来先服务调度算法 FCFS、最短作业时间优先 SJF(抢占式 和非抢占式)、最高响应比调度 HRN 算法 4 种。(每个人必须做非抢占式 SJF, 然后在后面的三种中任选一种,即每个人必须做 2 种调度算法模拟。) [2]. 衡量算法性能的参数 计算进程的平均周转时间和平均带权周转时间。 3. 实验内容 (1)编程实现本实验的程序,要求: [1]. 建立进程进程控制块,进程控制块至少包括: a) 进程名称; b) 进程需要执行时间; c) 进入就绪队列时间; d) 进程执行开始时间 e) 进程执行结束时间 [2]. 编程实现调度算法。 [3]. 进程及相关信息的输入。这些信息可以直接从键盘上输入,也可以从文件读 取。 [4]. 时间片与时间流逝的模拟。本实验需要对算法的执行计时,程序应该提供计 算时间的方法。一种最简的方法是使用键盘,比如每敲一次空格代表一个 2 时间片的流逝。另一种方法是使用系统时钟。 [5]. 一组进程序列执行完毕,打印出结果信息。程序需要计算出每个进程的开始 执行时间、结束时间、周转时间和带权周转时间,并为整个进程序列计算平 均周转时间和平均带权周转时间。程序将计算结果按一定的格式显示在计算 机屏幕上或输出到文件中。打印出进程调度顺序图。 [6]. 实现数据在磁盘文件上的存取功能。 (2)对下列就绪进程序列分别使用上面的几种算法进行调度,计算每种算 法下的平均周转时间和平均带权周转时间。 进程号 到达时间 要求执行时间 0 0 1 1 1 35 2 2 10 3 3 5 4 6 9 5 7 21 6 9 35 7 11 23 8 12 42 9 13 1 10 14 7 11 20 5 12 23 3 13 24 22 14 25 31 15 26 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值