操作系统课程设计-进程管理-c++描述

1.目的和要求

通过实验理解进程的概念,进程的组成(PCB结构),进程的并发执行和操作系统进行进程管理的相关原语(主要是进程的创建、执行、撤消)。

2.实验内容

用C/C++语言编程模拟进程管理,至少要有:创建新的进程;查看运行进程;换出某个进程;杀死运行进程以及进程之间通信等功能。

3.设计思路

Process类包括以下字段:进程名,进程优先数,轮转时间片,进程所占用的CPU时间,进程的状态;和创建进程,显示进程,取出进程名,取出状态等方法。
图3-1程序类图

在类外设计了7个函数来分别实现各自的功能

  1. CreateNewprocess(headptr,counter,capacity)创建新的进程函数
  2. ViewProcess(headptr,counter) 查看运行进程函数
  3. SwapOutProcess(headptr,counter) 换出新的进程函数
  4. KillProcess(headptr,counter) 杀死运行进程函数
  5. SuspendProcess(headptr,counter) 挂起运行进程函数
  6. WakeupProcess(headptr,counter) 唤醒挂起进函数
  7. ApplyForNewMemory(headptr,capacity,counter))申请新的内存函数

在主函数int main()中用process类指针headptr指向new的process对象数组,同时还包括以下内容:

  1. 运用了对象指针链表作为主要的数据结构。
  2. counter,capacity分别作为进程个数和进程容量的全局变量作为参数传入子函数模块中。
  3. 宏定义增加空间常量increment为5。
  4. 运用#include头文件中的time_t Time; time(&Time);操作实现时间实时显示。
  5. 利用do-while循环与switch选择实现了菜单式界面
  6. 利用system(“cls”);函数实现清屏操作,增加界面演示效果。

4.源代码

// F:\debug\c++debug\OperatingSystem\ProcessManagement.cpp
// author:1045263694@qq.com
#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>

# define increment 5
using namespace std;
//以下是进程类的定义
class process
{
   
	friend void SuspendProcess(process *headptr,int counter);	//友元函数
	friend void WakeupProcess(process *headptr,int counter);	//友元函数
protected:
	int pid;				  //进程名
	int priority;		      //进程优先级
	int cputime;			  //进程使用CPU时间
	int status;		          //进程状态
	int Rotationtimeslice;    //轮转时间片
	int large;                //进程大小
public:
	process(){
   }				  //默认构造函数
	process(process &p)
	{
   
		p.pid=pid;
		//p.priority=priority;
		//p.cputime=cputime;
		//p.large=large;
		p.status=status;
	}
	virtual ~process(){
   }
	void display()
	{
   
		cout<<"进程名:"<<pid<<endl//<<"优先级:"<<priority<<endl<<"CPU时间:"<<cputime<<endl<<"大小:"<<large<<endl
		<<"状态:"<<status<<endl;
	}
	void setall(int &counter)
	{
   
		cout<<"0-正常,1-挂起,2-唤醒" <<endl;
		cout<<"请输入新的进程名:"; cin>>pid;
		//cout<<"请输入新的进程优先级:"; cin>>priority;
		//cout<<"请输入新进程大小:"; cin>>large;
		//cout<<"请输入新进程使用CPU时长:"; cin>>cputime;
		cout<<"请输入新进程状态:"; cin>>status;         //0-正常,1-挂起,2-唤醒
		counter++;
	}
	int Getpid()
	{
   
		return pid;
	}
	int Getstatus()
	{
   
		return status;
	}
};//process

void CreateNewprocess(process *headptr,
  • 14
    点赞
  • 129
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值