Пример #1
0
int main(int argc, char* argv[])
{
	int i;
	char c;
	int flag = 0;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		do_request();
loop:	do_response();
		printf("按Y打印页表,按其他键不打印...\n");
loop1:	if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		if(flag == 1){
			flag = 0;
			goto loop1;
		}
		printf("按X退出程序,按I手动输入请求,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if (c == 'i' || c == 'I'){
			flag = do_input_request();
			if(flag == 1)
				goto loop;
			printf("1111\n");
		}
		while (c != '\n'){
			c = getchar();
		}
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Пример #2
0
static void do_print_info_multiple(struct rfc2045 *p, struct rfc2045id *id,
		void *ptr)
{
	printf("section: ");
	do_print_structure(p, id, ptr);
	do_print_info(p);
	printf("\n");
}
Пример #3
0
int main(int argc, char* argv[])
{
	char c;
	int i;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	JGdo_print_catalogue_info();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//do_request();
		while (JGdo_request()) ;
		do_response();
		printf("按Y打印页表,辅存和实存,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y'){
			JGdo_print_catalogue_info();
			do_print_info();
			JGdo_print_aux_info();
			JGdo_print_act_info();
		}
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Пример #4
0
void print_info(struct rfc2045 *p, const char *mimesection)
{
struct	rfc2045 *s;

	if (mimesection)
	{
		s=rfc2045_find(p, mimesection);
		if (!s)
			notfound(mimesection);
		printf("section: %s\n", mimesection);
		do_print_info(s);
		return;
	}
	rfc2045_decode(p, &do_print_info_multiple, 0);
}
Пример #5
0
/*打印辅存*/
void do_print_vir()
{
	int i;
	char temp_byte;
	FILE* p = fopen("vmm_auxMem","r");
	printf("print virtual memory\n");
	for(i = 0;i < VIRTUAL_MEMORY_SIZE;i++){
        printf("%c",fgetc(p));
	}
	/*while((temp_byte = fgetc(p)) != EOF){
		printf("%c",temp_byte);
	}*/

/* 获取页面保护类型字符串 */
char *get_proType_str(char *str, BYTE type)
{
	if (type & READABLE)
		str[0] = 'r';
	else
		str[0] = '-';
	if (type & WRITABLE)
		str[1] = 'w';
	else
		str[1] = '-';
	if (type & EXECUTABLE)
		str[2] = 'x';
	else
		str[2] = '-';
	str[3] = '\0';
	return str;
}

int main(int argc, char* argv[])
{
	char c;
	int i;
	int fifo2;
	int count;
	cmd req;
	struct stat statbuf;
	req.RT=NOR;
	if(stat("/tmp/doreq",&statbuf)==0){
		/* 如果FIFO文件存在,删掉 */
		if(remove("/tmp/doreq")<0)
			printf("remove failed\n");
	}

	if(mkfifo("/tmp/doreq",0666)<0)
		printf("mkfifo failed\n");
	/* 在非阻塞模式下打开FIFO */
	if((fifo2=open("/tmp/doreq",O_RDONLY|O_NONBLOCK))<0)
		printf("open fifo failed\n");

	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		if((count=read(fifo2,&req,CMDLEN))<0)
			printf("read fifo failed\n");
		switch(req.RT){
			case REQUEST: printf("addr=%ld\n",req.virAddr);
			do_request(req);req.RT=NOR;
			break;
			//case RESPONSE:printf("aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n");
			//do_response();req.RT=NOR;
			//break;
			default:
			break;
		}
		do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
        printf("按A打印实存,按其他键不打印...\n");
		if ((c = getchar()) == 'a' || c == 'A')
			do_print_act();
		while (c != '\n')
			c = getchar();
        printf("按V打印辅存,按其他键不打印...\n");
		if ((c = getchar()) == 'v' || c == 'V')
			do_print_vir();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo2);
	return (0);
}
Пример #6
0
int main(int argc, char* argv[])
{
	remove("/tmp/temp_mem");

	if (mkfifo("/tmp/temp_mem", 0666) < 0)

		printf("mkfifo failed");
	remove("/tmp/temp_info");

	if (mkfifo("/tmp/temp_info", 0666) < 0)

		printf("mkfifo failed");
	remove("/tmp/temp_var4");

	if (mkfifo("/tmp/temp_var4", 0666) < 0)

		printf("mkfifo failed");


	char c;
	int i;
	/**********************************************************************************/
	//用于进程间通信
	signal(SIGUSR1, setMark1);
	signal(SIGUSR2, setMark2);
	/**********************************************************************************/
	//if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	//创建辅存文件
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "w+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	//初始化页表,辅存和实存
	do_init();
	//打印页表信息
	do_print_info();
	//为访存请求申请空间
	ptr_memAccReq = (Ptr_MemoryAccessRequest)malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	/**********************************************************************************/
	pid = do_fork();
	/**********************************************************************************/


	while (TRUE)
	{
		//do_request();
		/***************************************************************************************/
		new_do_request();
		/***************************************************************************************/
		//do_response();
		while (mark2 == 0);
		mark2 = 0;

		c = getchar();
		while (c != '\n')
			c = getchar();


		int flag_y = 0;
		int flag_m = 0;

		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
		{
			//do_print_info();
			do_print_info_from_file();
			flag_y = 1;
		}
		if (flag_y == 0)
		{
			char temp_str[10000] = { 0 };

			int temp_fifo;
			if ((temp_fifo = open("/tmp/temp_info", O_RDONLY)) < 0)

				printf("open /tmp/temp_info failed");



			int count = 0;

			//读200个,关

			if ((count = read(temp_fifo, temp_str, 10000)) < 0)

				printf("read /tmp/temp_info failed");

			close(temp_fifo);
		}

		while (c != '\n')
			c = getchar();
		/***************************************************************************************/
		printf("按A打印辅存,按其他键不打印...\n");
		if ((c = getchar()) == 'a' || c == 'A')
			do_print_auxiliaryStorage();
		while (c != '\n')
			c = getchar();
		printf("按M打印实存,按其他键不打印...\n");
		if ((c = getchar()) == 'm' || c == 'M')
		{
			//do_print_memory();
			do_print_memory_from_file();
			flag_m = 1;
		}

		if (flag_m == 0)
		{
			char temp_str[10000] = { 0 };

			int temp_fifo;
			if ((temp_fifo = open("/tmp/temp_mem", O_RDONLY)) < 0)

				printf("open /tmp/temp_mem failed");



			int count = 0;

			//读200个,关

			if ((count = read(temp_fifo, temp_str, 10000)) < 0)

				printf("read /tmp/temp_info failed");

			close(temp_fifo);
		}


		while (c != '\n')
			c = getchar();
		/***************************************************************************************/
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Пример #7
0
int main(int argc, char** argv)
{

    string_map* parameters = parse_parameters(argc, argv);

    opkg_conf *conf = load_conf((char*)get_string_map_element(parameters, "config"));

    char* run_type                   = get_string_map_element(parameters, "run-type");
    int force_overwrite_other_files  = get_string_map_element(parameters, "force-overwrite")         != NULL ? 1 : 0;
    int force_overwrite_configs      = get_string_map_element(parameters, "force-overwrite-configs") != NULL ? 1 : 0;
    int force_depends                = get_string_map_element(parameters, "force-depends")           != NULL ? 1 : 0;
    int force_reinstall              = get_string_map_element(parameters, "force-reinstall")         != NULL ? 1 : 0;

    int remove_orphaned_depends      = get_string_map_element(parameters, "autoremove")                    != NULL ? REMOVE_ALL_ORPHANED_DEPENDENCIES : REMOVE_NO_ORPHANED_DEPENDENCIES;
    remove_orphaned_depends          = get_string_map_element(parameters, "autoremove-same-destination")   != NULL ? REMOVE_ORPHANED_DEPENDENCIES_IN_SAME_DEST : remove_orphaned_depends;

    char* install_root               = get_string_map_element(parameters, "install-destination");
    install_root                     = install_root == NULL ? strdup("root") : install_root;

    char* link_root                  = get_string_map_element(parameters, "link-destination");
    char* tmp_root                   = get_string_map_element(parameters, "tmp_dir");
    tmp_root                         = tmp_root == NULL ? strdup("/tmp") : tmp_root;
    string_map* pkgs                 = get_string_map_element(parameters, "package-list");

    char* format_str                 = get_string_map_element(parameters, "output-format");
    int format                       = OUTPUT_HUMAN_READABLE;
    if(format_str != NULL)
    {
        format = strcmp(format_str, "json") == 0 ? OUTPUT_JSON : format;
        format = strcmp(format_str, "js") == 0 || strcmp(format_str, "javascript") == 0 ? OUTPUT_JAVASCRIPT : format;
    }





    if(strcmp(run_type, "install") == 0)
    {
        do_install(conf, pkgs, install_root, link_root, 0, force_overwrite_configs, force_overwrite_other_files, force_reinstall, tmp_root);
    }
    else if(strcmp(run_type, "remove") == 0)
    {
        do_remove(conf, pkgs, !force_overwrite_configs, remove_orphaned_depends, force_depends, 1);
    }
    else if(strcmp(run_type, "upgrade") == 0)
    {
        do_upgrade(conf, pkgs, !force_overwrite_configs, install_root, link_root);
    }
    else if(strcmp(run_type, "update") == 0)
    {
        update(conf);
    }
    else if((strcmp(run_type, "list") == 0) || strcmp(run_type, "list-installed") == 0 || strcmp(run_type, "list_installed") == 0)
    {
        do_list(conf, parameters, format);
    }
    else if(strcmp(run_type, "dest-info") == 0 || strcmp(run_type, "dest_info") == 0)
    {
        do_print_dest_info(conf, format);
    }
    else if(strcmp(run_type, "info") == 0)
    {
        do_print_info(conf, parameters, install_root, format);
    }

    return(0);

}
Пример #8
0
Файл: vmm.c Проект: ZZJC1306/VMM
int main(int argc, char* argv[])
{
	char c;
	int countnum;
	struct stat statbuf;
	int i;
	CMD cmd;
	printf("start file");
	initFile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

//	printf("start");
	do_init();
	//printf("print info");
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	//获取文件信息,并将其保存在statbuf中
	if(stat("/tmp/server",&statbuf) == 0)
	{
		//如果文件删除失败
		if(remove("/tmp/server")<0)
		{
			do_error(ERROR_FIFO_REMOVE_FAILED);
			exit(1);
		}
	}
	//创建文件名称为"/tmp/server"的文件,0666为文件权限可读可写
	if(mkfifo("/tmp/server",0666)<0)
	{
		do_error(ERROR_FIFO_CREATE_FAILED);
		exit(1);
	}
	/*打开文件*/
	if((fifo = open("/tmp/server",O_RDONLY))<0)
	{
		do_error(ERROR_FIFO_OPEN_FAILED);
		exit(1);
	}
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//读取文件
		bzero(&cmd,DATALEN);
	//	printf("******************\n");
		if((countnum = read(fifo,&cmd,DATALEN))<0)
		{
			do_error(ERROR_FIFO_READ_FAILED);
			printf("errno=%d\n",errno);
			exit(1);
		}
		if(countnum == 0){
			continue;
		}
		c = cmd.c;

//		printf("按D手动输入命令,按其他键自动生成命令...\n");
		if(c == 'y'||c == 'Y')
			do_print_info();
		else if(c == 'a'||c == 'A')
			do_print_actual();
		else if(c == 'n'||c =='N')
		{
			ptr_memAccReq = &(cmd.request);
			do_response();
		}
		else if(c == 'b' || c == 'B')
			do_print_virtual();
		else if(c == 'c'||c == 'C'){
			ptr_memAccReq = &(cmd.request);
			do_response();
		}
//		printf("按Y打印页表,按其他键不打印...\n")
		else if (c == 'x'||c=='X')
			break;

	}
	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	fclose(fifo);
	return (0);

}
Пример #9
0
int main(int argc, char* argv[])
{
	int i;
	char c;
	int flag = 0;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
loop4:		do_request();
loop:	do_response();
		printf("按Y打印页表,按其他键不打印.........\n");
loop1:	if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		if(flag == 1){
			flag = 0;
			goto loop1;
		}
loop2:		printf("按X退出程序,按I手动输入请求,按P打印实存,按R打印辅存,按T转换模式,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if (c == 'i' || c == 'I'){
			flag = do_input_request();
			if(flag == 1)
				goto loop;
		}
		if (c == 'p' || c == 'P'){
			printf("实存\t对应值\t实存\t对应值\t实存\t对应值\t实存\t对应值\n");
			for(i = 0; i < ACTUAL_MEMORY_SIZE; i++){
				printf("%d \t%02X\t", i, actMem[i]);
				if(i % 4 == 3)
					printf("\n");
			}	
			goto loop1;
		}
		if (c == 'r' || c == 'R'){
			ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+");
			while(fscanf(ptr_auxMem, "%c", &c) != EOF)
				printf("%c",c);
			printf("\n");
			goto loop1;		
		}
		if (c == 't' || c == 'T'){
			goto loop3;		
		}
		while (c != '\n'){
			c = getchar();
		}
		
	}
	
	/* 在循环中模拟访存请求与处理过程 */
loop3:	while (TRUE)
	{
		umask(0);
		printf("进入读写FIFO模式\n");
		//do_request();
		FILE *fp;
		char *buf[100];
		mkfifo(FIFO,S_IFIFO|0666);
		/*if (mkfifo(FIFO,S_IFIFO|0666) < 0){
			printf("what the f**k\n");
			continue;
		}*/	
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		
		deal_request(buf);
		do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按T转换模式,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if(c == 't' || c == 'T'){
			flag = 1;
			printf("退出读写FIFO模式\n");
			goto loop4;		
		}
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Пример #10
0
int main(int argc, char* argv[])
{
	char c;
	int i;
    struct stat statbuf;

    if (access(AUXILIARY_MEMORY, F_OK) == -1)
    {
        if(creat(AUXILIARY_MEMORY, 0755) < 0)
        {
            do_error(ERROR_FILE_CREATE_FAILED);
        }
        initFile();
    }
    if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
    {
        do_error(ERROR_FILE_OPEN_FAILED);
        exit(1);
    }

    if(stat(FIFO, &statbuf)==0)
    {
        /* 如果FIFO文件存在,删掉 */
        if(remove(FIFO)<0)
        {
            printf("remove FIFO failed");
            exit(1);
        }
    }
    if(mkfifo(FIFO, 0666)<0)
    {
        printf("mkfifo failed");
        exit(1);
    }

    /* 在非阻塞模式下打开FIFO */
    if((fd = open(FIFO, O_RDONLY | O_NONBLOCK)) < 0) 
    {
        printf("open FIFO failed");
        exit(1);
    }

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
        printf("按S读取请求,按其他键不读取请求...\n");
        if ((c = getchar()) == 's' || c == 'S')
            do_response();
        while (c != '\n')
            c = getchar();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
	}
    close(fd);
	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Пример #11
0
int main(int argc, char* argv[])
{
	char c;
	int i;
	int lru_count = 0;

	int count;

	struct stat statbuf;//hzy
	

	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	update_LRU();		//LRU
	do_print_info();


	if(stat(fifoaddr,&statbuf)==0)//fifo exist?
		if(remove(fifoaddr)<0){
			printf("remove fifo failed");
			exit(1);
		}

	if(mkfifo(fifoaddr,0666)<0){
		printf("mkfifo failed");
		exit(1);
	}

	if((fifo=open(fifoaddr,O_RDONLY))<0)
	{
	//	do_error(ERROR_FIFO_OPEN_FAILED );
		printf("open fifo failed");
		exit(1);
	}

	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		bzero(&cmd,DATALEN);
//		sleep(5);
		if((count=read(fifo,&cmd,DATALEN))<0)
		{
		//	do_error(ERROR_FIFO_READ_FAILED);
			printf("read fifo failed");
			printf("errno=%d\n",errno);
			exit(1);
		}
		if(count==0)
		{
			continue;
		}
		c=cmd.type;
		if (c == 'y' || c == 'Y')
			do_print_info();
		else if(c == 'f' || c == 'F')
			do_print_auxmem();
		else if(c == 'm' || c == 'M')
			do_print_memory();
		else if(c == 'r' || c == 'R'){
			ptr_memAccReq=&(cmd.request);
			do_response();
		}
		else if(c == 'c' || c == 'C'){
			ptr_memAccReq=&(cmd.request);
			do_response();
		}
		else if(c == 'x' || c == 'X')
			break;
	
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo);
	return (0);
}
Пример #12
0
int main(int argc, char* argv[])
{
	char c;
	int i;
	time(&timer);//系统开始的时间
	initFile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	do_print_info();

	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
///////////////////////////在main中创建管道
	struct stat statbuf;
	int fifo;
	if(stat("/tmp/vmm",&statbuf)==0)
	{
		/* 如果FIFO文件存在,删掉 */
		if(remove("/tmp/vmm")<0)
		{
			perror("remove failed");
			exit(1);
		}
	}

	if(mkfifo("/tmp/vmm",0666)<0)
	{
		perror("mkfifo failed");
		exit(1);
	}
	if((fifo=open("/tmp/vmm",O_RDONLY))<0)
	{
		perror("open failed");
		exit(1);
	}
	
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//do_request();
		if((read(fifo,ptr_memAccReq,sizeof(MemoryAccessRequest)))<0)
		{
			perror("read failed");
			exit(1);
		}//读管道内容
		do_response();
		/////////
		time(&timerc);
		if((timerc-timer)>=Time)//经过一定时间,更新页面老化算法的计数器
		{
			for(i = 0; i < PAGE_SUM; i++)
			{
				pageTable[i].count_1=(pageTable[i].count_1>>1)|(pageTable[i].R<<31);
				pageTable[i].R=0;
			}
			timer=timerc;
		}
		printf("按1打印页表,按2打印页表和实存内容,按3打印页表、辅存和实存内容,按其他键不打印...\n");
		if ((c = getchar()) == '1')
			do_print_info();
		if (c== '2')
		{
			do_print_info();
			do_print_actMem();
		}
		if (c== '3')
		{
			do_print_info();
			do_print_actMem();
			do_print_auxMem();
		}
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo);
	return (0);
}
Пример #13
0
int main(int argc, char* argv[])
{
	char c,d;
	unsigned long k;
	int i,j;
	FILE *fp;
	char buf[BUFLEN];
	umask(0);
	if(mkfifo(FIFO,S_IFIFO|0660)<0)
		return -1;
	initfile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */

	
	while(TRUE)
	{
		printf("请输入请求\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		printf("Request is: %s\n",buf);
		fclose(fp);
		i=0;
		k=0;
		j=0;
		if(buf[i]=='r'||buf[i]=='w'||buf[i]=='x'){
			c='a';
            		d=buf[i];
            		k=0;
           		while(buf[i]<'0'||buf[i]>'9'){i++;}
			while(buf[i]>='0'&&buf[i]<='9'){
                		k=k*10+buf[i]-'0';
                		i++;
            		}
			while(buf[i]<'0'||buf[i]>'9'){i++;}
			while(buf[i]>='0'&&buf[i]<='9'){
                		j=j*10+buf[i]-'0';
                		i++;
            		}
            		deal_request(d,k,j);
            		do_response();	
	    	}
	    	else{
            		printf("无法识别命令");
	    	}
		printf("按Y打印页表,按其他键不打印...\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		fclose(fp);
		if (buf[0] == 'y' || buf[0] == 'Y')
			do_print_info();
		printf("按X退出程序,按其他键继续...\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		fclose(fp);
		if (buf[0] == 'e' || buf[0] == 'E')
			break;
	}


/*	while (TRUE)
	{
	do_request();
        do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}*/

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}