⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcb.cpp

📁 进程管理 用链表实现的 有三种算法实现的
💻 CPP
字号:
#include "stdafx.h"
#include "PCB.h"
#include <iostream.h>
#include <iomanip.h>
PCB::PCB()
{
	name = new char[80];
	state = 0;
	submitTime = 0;
	priority = 0;
	runTime = 0;
	beginRunTime = 0;
	assignTime = 0;
	realRunTime = 0;
	remainTime = 0;
	completeTime = 0;
	turnOverTime = 0;
	powerTurnOverTime = 0;
	nextPCB = 0;
	prePCB = 0;	
}
PCB::~PCB()
{
	delete name;
}
//systemAssignTime系统分配到的时间
void PCB::DealTime(int &curTime, int systemAssignTime)
{
	//如果当前时间小于进程提交时间,把当前时间提前到进程提交时间
	if(curTime < submitTime)
	{
		curTime = submitTime;
	}
	beginRunTime = curTime;//开始执行时间 = 当前时间
	assignTime = systemAssignTime;
	if(systemAssignTime >= remainTime)
	{
		state = 1;//标志完成
		realRunTime = remainTime;
		remainTime = 0;
		completeTime = beginRunTime + realRunTime;//完成时间=开始运行时间+实际运行时间
		turnOverTime = completeTime - submitTime;//周转时间 = 完成时间 - 提交时间
		powerTurnOverTime = turnOverTime / runTime;
		curTime = completeTime;
	}
	else
	{
		state = 0;
		realRunTime = systemAssignTime;
		remainTime -= realRunTime;
		curTime += systemAssignTime;
		priority += 2;
	}
}
//打印每一个作业的详细时间
void PCB::PrintDetail(int i)
{
	cout << setiosflags(ios::left) << setw(4) << i << setw(6) << this->name;
	if(this->state == 0)
		cout << setw(8) << "未完成";
	else
		cout << setw(8) << "已完成";
	cout << setw(6) << this->submitTime << setw(6) << this->priority << setw(6) << this->runTime
	<< setw(6) << this->beginRunTime << setw(6) << this->assignTime << setw(6) << this->realRunTime
	<< setw(6) << this->remainTime;
	if(this->state == 1)
	{
		cout << setw(6) << this->completeTime << setw(6) << this->turnOverTime
		<< setw(6) << this->powerTurnOverTime << endl;;
	}
	else
		cout << setw(6) << "--"	<< setw(6) << "--"	<< setw(6) << "--" << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -