main.cpp

来自「操作系统」· C++ 代码 · 共 39 行

CPP
39
字号
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct operation
{
	int time;		//起始时间
	int block;		//内存页数
	int oper;		//操作
	int protection;	//权限
};

int main()
{
	FILE * file;
	file = fopen("opfile", "wb");	//"opfile"为二进制用确定内存操作
	operation op;

	for(int j = 0; j < 6; j++)
	{
		for(int i = 0; i <5; i++)
		{
			//0-PAGE_READONLY;
			//1-PAGE_READWRITE;
			//2-PAGE_EXECUTE;
			//3-PAGE_ECECUTE_READ;
			//4-PAGE_EXECUTE_READWRITE;
			op.time = rand() % 1000;		//随即生成等待时间
			op.block = rand() % 5 + 1;		//随即生成块大小
			op.oper = j;
			op.protection = i;
			fwrite(&op, sizeof( operation), 1, file);	//将生成的结构写入文件
		}
	}
	return 0;
}

⌨️ 快捷键说明

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