当前位置:文档之家› 东北大学操作系统实验 绝对自创 实验报告 含可执行源代码 linux环境可运行 有截图

东北大学操作系统实验 绝对自创 实验报告 含可执行源代码 linux环境可运行 有截图

running.push(ch);
running.pop();
}
cout << endl;
cout << "block: ";
for(int i = 0;i < n3;i++)
{
ch = block.front();
cout << ch;
block.push(ch);
block.pop();
}
cout << endl;
{
cout << M_Frame[n] << " ";
}
cout << endl;
flag_l = 1;//表示命中
cout << "请输入随机数数组长度: " ;
cin >> total_instruction;
int Acess_Series[total_instruction];
int Acess_Num;//页程序个数
cout << "请输入页程序个数:";
cin >> Acess_Num;
srand(time(NULL));//初始化随机数组
read(fd[0],father,17);
cout << father << endl;
}
}
}
return 0;
}
三、实验结果
实验四页面置换算法
一、实验目的
进一步加深理解父子进程之间的关系及其并发执行。
理解内存页面调度的机理。
掌握页面置换算法及其实现方法。
培养综合运用所学知识的能力。
二、实验内容
#include <iostream>
float lru_ok = 0;//lru命中数
float lru_miss = 0;//lru缺页数
intframe_num;//内存中分配页面个数
cout << "请输入内存中分配页面个数:";
cin >> frame_num;
int M_Frame[frame_num] = {0};
int total_instruction;//随机数组长度
{
int n1,n2,n3;
char ch;
n1 = ready.size();
n2 = running.size();
n3 = block.size();
cout << "___________________" << endl;
cout << "ready: ";
for(int i = 0;i < n1;i++)
while(scanf("%d",&p)!= EOF)
{
switch(p)
{
case 2: f2();break;
case 3: f3();break;
case 4: f4();break;
default:break;
}
}
return 0;
}
void f1()
{
char c = ready.front();
char father[20] ;
int main()
{
int fd[2];
int re = pipe(fd);
pid_t p1,p2,p3;
int *status = NULL;
p1 = fork();
if(p1 == 0)
{
lockf(fd[1],1,0);
printf("子进程一正在写入,prd = :%d\n",getpid());
ready.pop();
running.push(c);
print();
}
void f2()
{
char c = running.front();
running.pop();
ready.push(c);
print();
f1();
}
void f3()
{
char c = running.front();
running.pop();
if(p1 > 0)
{
int p2 = fork();//创建子进程二
if(p2 == 0)//子进程二 LRU
{
cout << "这里是子进程二:LRU算法" << endl;
for(int i = 0;i < total_instruction;i++)
{
for(int j = 0;j < frame_num;j++)
queue<int> blockp;//等待进入缓冲区的数据
int data = 0;//生产者生产的数据
int num = 0;//缓冲区元素个数
int np = 0;//正在等待的生产者
int nc = 0;//正在等待的消费者
int main()
{
print();
char c;
while(scanf("%c",&c)!='e')
cout << "访问页的顺序为:";
for(int i = 0;i < total_instruction;i++)
{
Acess_Series[i] = rand() % Acess_Num+1;
cout << Acess_Series[i] << " ";
}
cout << endl;
int p1 = fork();//创建子进程一
buffer.push(ch);
buffer.pop();
}
printf("\n");
}
三、实验结果
实验三进程的管道通信
一、实验目的
加深对进程概念的理解,明确进程和程序的区别。
学习进程创建的过程,进一步认识进程并发执行的实质。
分析进程争用资源的现象,学习解决进程互斥的方法。
学习解决进程同步的方法。
掌握Linux系统中进程间通过管道通信的具体实现。
{
ch = ready.front();
cout << ch;
ready.push(ch);
ready.pop();
}
cout << endl;
cout << "running: ";
for(int i = 0;i < n2;i++)
{
ch = running.front();
cout << ch;
{
if(Acess_Series[i] == M_Frame[j])//命中
{
cout << "子程序2 命中: " ;
lru_ok++;
int t;
t = M_Frame[frame_num-1];
M_FramBiblioteka [frame_num-1] = M_Frame[j];
M_Frame[j] = t;
for(int n = 0;n < frame_num;n++)
lockf(fd[1],0,0);
exit(0);
}
else if(p2 > 0)
{
p3 = fork();
if(p3 == 0)
{
lockf(fd[1],1,0);
printf("子进程三正在写入,prd = :%d\n",getpid());
write(fd[1],child_3,27);
lockf(fd[1],0,0);
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
using namespace std;
int main()
{
intflag_f = 0;
intflag_l = 0;
float fifo_ok = 0;//fifo命中数
float fifo_miss = 0;//fifo缺页数
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
void producer();//生产者
void print();//显示缓冲区
void consumer();//消费者
queue<int> buffer;//缓冲区
{
switch(c)
{
case 'p': producer();print();break;
case 'c': consumer();print(); break;
case 'e': exit(0);
}
}
}
void producer()//生产者
{
if(num < 8)
{
if(nc > 0)
{
data++;
相关主题