资源描述:
《操作系统源代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#includeintmemoryStartAddress=-1;intmemorySize=-1;structjobList{intid;/*作业ID*/intsize;/*作业大小(需要的存储空间大小)*/intstatus;/*作业状态0:newjob,1:inthememory,2:finished.*/structjobList*next;/*作业链表指针*/};structfreeList{intstartAddress;/*分区起始地址*/intsize;/*分区
2、大小*/structfreeList*next;/*分区链表指针*/};structusedList{intstartAddress;/*分区起始地址*/intjobID;/*分区中存放作业ID*/structusedList*next;/*分区链表指针*/};voiderrorMessage(void)/*出现严重错误时显示信息并结束程序*/{printf("tError!a");printf("Pressanykeytoexit!");getch();exit(1);}voidopenFile(FILE**fp,char*filename,cha
3、r*mode)/*以要求的方式打开文件*/{if((*fp=fopen(filename,mode))==NULL){printf("Can'topen%sinmode%s.",filename,mode);errorMessage();}}voidmakeFreeNode(structfreeList**empty,intstartAddress,intsize)/*根据参数startAddress、size创建空闲节点,由empty指针返回*/{if((*empty=malloc(sizeof(structfreeList)))==NULL){print
4、f("Notenoughtoallocateforthefreenode.");errorMessage();}(*empty)->startAddress=startAddress;(*empty)->size=size;(*empty)->next=NULL;}voidiniMemory(void)/*初始化存储空间起始地址、大小*/{charMSA[10],MS[10];printf("Pleaseinputthestartaddressofthememory!");scanf("%s",MSA);memoryStartAddress=atoi(M
5、SA);printf("Pleaseinputthesizeofthememory!");scanf("%s",MS);memorySize=atoi(MS);}charselectFitMethod(void)/*选择适应算法*/{FILE*fp;charfitMethod;do{printf("Pleaseinputacharasfallowtoselectthefitmethod!1(Bestfit)2(Worstfit)3(Firstfit)4(Lastfit)");fitMethod=getche();}whil
6、e(fitMethod<'1'
7、
8、fitMethod>'4');openFile(&fp,"d:\result.cl","a");switch(fitMethod){case'1':fprintf(fp,"tBestfit");fprintf(fp,"**********************************************");break;case'2':fprintf(fp,"tWorstfit");fprintf(fp,"************************************
9、**********");break;case'3':fprintf(fp,"tFirstfit");fprintf(fp,"**********************************************");break;case'4':fprintf(fp,"tLastfit");fprintf(fp,"**********************************************");break;}fclose(fp);returnfitMethod;}voidinputJob(void
10、)/*从键盘输入作业到D