OS作业的第一步骤
来源:互联网 发布:软件著作权样例 编辑:程序博客网 时间:2024/05/01 07:31
进程用链表表示,资源也是用链表表示。类似一个十字链表。能在进程里面去查看资源。
#include<iostream>
#include<time.h>
using namespace std;
#define Sort 5
#define Number 20
struct Resource{
int r_No;
int max;
int allocation;
int need;
Resource *next;
};
struct Process{
int p_No;
Process * next;
Resource * Rhead;
};
Process *Creat_Process(int n){
Process *pP;
Process *pEnd;
Process *pHead;
pHead = NULL;
pP = new Process;
pEnd = pP;
for(int i = 0 ; i < n ; i++){
Resource *rR;
Resource *rEnd;
Resource *rHead;
if(pHead == NULL){
pHead = pP;
pP->p_No =i+1;
rHead = NULL;
rR = new Resource;
rEnd =rR;
for(int j = 0; j < Sort; j++)
{
if(rHead == NULL){
pP->Rhead=rHead = rR;
rR->r_No = j+1;
rR->max = rand()%Number + 1;
rR->allocation = rand()%rR->max;
rR->need = rR->max - rR->allocation;
}//if
else {
rEnd->next = rR;
rR->r_No = j+1;
rR->max = rand()%Number + 1;
rR->allocation = rand()%rR->max;
rR->need = rR->max - rR->allocation;
rEnd = rR;
}
rR = new Resource;
}//for
rEnd->next =NULL;
delete rR;
}//if
else{
pEnd->next=pP;
pEnd = pP;
pP->p_No = i+1;
rHead = NULL;
rR = new Resource;
rEnd =rR;
for(int f=0;f<Sort;f++){
if(rHead ==NULL){
pP->Rhead=rHead = rR;
rR->r_No = f+1;
rR->max = rand()%Number + 1;
rR->allocation = rand()%rR->max;
rR->need = rR->max - rR->allocation;
}//if
else{
rEnd->next=rR;
rEnd=rR;
rR->r_No =f+1;
rR->max = rand()%Number + 1 ;
rR->allocation = rand()%rR ->max;
rR->need = rR ->max - rR->allocation;
}//else
rR = new Resource;
}//for
rEnd->next =NULL;
delete rR;
}//else
pP = new Process;
}//for
pEnd->next=NULL;
delete pP;
cout<<"1"<<endl;
return (pHead);
}
int main(void)
{
srand(time(NULL));
Process *show;
show = Creat_Process(5);
cout<<"2"<<endl;
while(show)
{
cout<<"P_NO: "<<show->p_No<<"Re: "<<show->Rhead->r_No<<endl;
for(int i=0;i<5;i++){
cout<<"R_NO:"<<show->Rhead->r_No<<" alloc: "<<show->Rhead->allocation<<endl;
show->Rhead=show->Rhead->next;
}
show=show->next;
}
return 0;
}
- OS作业的第一步骤
- 写的第一个作业
- 我的第一个作业
- sqlserver 作业调度(作业常用的几个步骤)
- sqlserver 定时作业的定制步骤
- Kettle 作业步骤循环执行的实现
- 关于OS中第一线程的问题解决.
- [第一弹]os.walk的相关用法
- 我的第一个map/reduce 作业
- 新建第一个Hibernate项目的步骤
- SpringMVC的第一个案例 Helloword 步骤
- 开发第一个C程序的步骤
- SpringMVC的第一个项目创建步骤
- OS作业调度中HRN的模拟实现
- OS作业调度FCFS,SJF,HRRN算法的C++实现
- Mac OS上安装Tomcat服务器的简单步骤
- JOB 创建包含步骤和计划的作业
- 第一个c++作业
- 获得VB类成员函数指针
- 解决在VS2005、VWD中创建用户时提示
- MSDE(MSSQL2000)安装自动回滚故障一例
- 5个顶级的硬盘数据恢复软件
- 名书推荐:硝烟中的Scrum与XP
- OS作业的第一步骤
- gloox 之 MainPage
- ZOJ-2091 Mean of Subsequence
- ERP的概念与历程
- ASP.NET提取超链接的正在表达式用法
- ERP的概念与历程
- 字迹看性格
- 简单配置SourceInsight
- Microsoft SQL Server 2000 安装出现的问题