操作系统课程设计

您所在的位置:网站首页 如何结束系统进程管理界面 操作系统课程设计

操作系统课程设计

2023-07-29 08:23| 来源: 网络整理| 查看: 265

目录 1.目的和要求2.实验内容3.设计思路4.源代码5.运行示例

1.目的和要求

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

2.实验内容

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

3.设计思路

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

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

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

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

运用了对象指针链表作为主要的数据结构。counter,capacity分别作为进程个数和进程容量的全局变量作为参数传入子函数模块中。宏定义增加空间常量increment为5。运用#include头文件中的time_t Time; time(&Time);操作实现时间实时显示。利用do-while循环与switch选择实现了菜单式界面利用system(“cls”);函数实现清屏操作,增加界面演示效果。 4.源代码 // F:\debug\c++debug\OperatingSystem\ProcessManagement.cpp // author:[email protected] #include #include #include #include # 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 return pid; } int Getstatus() { return status; } };//process void CreateNewprocess(process *headptr,int &counter,int capacity) { if(counter cout (headptr+i)->display(); } cout if((headptr+i)->Getpid()==pid) { for(int j=i;jGetpid()!=pid)) { cout if((headptr+i)->Getpid()==pid) { --counter; (headptr+i)->setall(counter); break; } else if((i==counter-1)&&((headptr+i)->Getpid()!=pid)) { cout if((headptr+i)->Getpid()==pid) { (headptr+i)->status=1; break; } else if((i==counter-1)&&((headptr+i)->Getpid()!=pid)) { cout if((headptr+i)->Getpid()==pid) { (headptr+i)->status=0; cout if(counter==capacity) { capacity+=increment; process *p=headptr; process *newheadptr = new process[capacity]; process *q=newheadptr; for(int i=0;i time_t Time; time(&Time); int control; process *headptr = new process[capacity]; do { cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3