操作系统源代码(15页).doc
《操作系统源代码(15页).doc》由会员分享,可在线阅读,更多相关《操作系统源代码(15页).doc(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-操作系统源代码-第 15 页#include#include#includeint memoryStartAddress = -1;int memorySize = -1;struct jobListint id; /* 作业ID */int size; /* 作业大小(需要的存储空间大小) */int status; /* 作业状态 0 : new job ,1 : in the memory , 2 : finished . */struct jobList *next; /* 作业链表指针 */struct freeListint startAddress; /* 分区起始地址 */i
2、nt size; /* 分区大小 */struct freeList *next; /* 分区链表指针 */struct usedList int startAddress; /* 分区起始地址 */int jobID; /* 分区中存放作业ID */struct usedList *next; /* 分区链表指针 */void errorMessage(void) /*出现严重错误时显示信息并结束程序*/printf(ntError !a);printf(nPress any key to exit !);getch();exit(1);void openFile(FILE *fp,char
3、 *filename,char *mode) /*以要求的方式打开文件*/if(*fp = fopen(filename,mode) = NULL)printf(nCant open %s in mode %s.,filename,mode);errorMessage();void makeFreeNode(struct freeList *empty,int startAddress,int size) /*根据参数startAddress、size创建空闲节点,由empty指针返回*/if(*empty = malloc(sizeof(struct freeList) = NULL)pri
4、ntf(nNot enough to allocate for the free node .);errorMessage();(*empty)-startAddress = startAddress;(*empty)-size = size;(*empty)-next = NULL;void iniMemory(void) /*初始化存储空间起始地址、大小*/char MSA10,MS10;printf(nPlease input the start address of the memory !);scanf(%s,MSA);memoryStartAddress = atoi(MSA);p
5、rintf(nPlease input the size of the memory !);scanf(%s,MS);memorySize = atoi(MS);char selectFitMethod(void) /*选择适应算法*/FILE *fp;char fitMethod;doprintf(nnPlease input a char as fallow to select the fit method !n 1 (Best fit) n 2 (Worst fit) n 3 (First fit) n 4 (Last fit)n);fitMethod = getche();while(
6、fitMethod 4); openFile(&fp,d:result.cl,a);switch(fitMethod)case 1: fprintf(fp,nnnntBest fit); fprintf(fp,n*); break;case 2: fprintf(fp,nnnntWorst fit); fprintf(fp,n*); break;case 3: fprintf(fp,nnnntFirst fit); fprintf(fp,n*); break;case 4: fprintf(fp,nnnntLast fit); fprintf(fp,n*); break;fclose(fp);
7、return fitMethod;void inputJob(void) /*从键盘输入作业到D盘的JOB文件*/int /*id,size, */status = 0,jobnum = 0;FILE *fp;char id10,size10;openFile(&fp,d:job.cl,w);fprintf(fp,job_IDtsizetstatus);printf(nnnnPlease input the jobs as fallow !nEnter a integer smaller than 1 to quit .njob_IDtsizen);do/*scanf(%d%d,&id,&si
8、ze); */scanf(%st%s,id,size);if(atoi(id) 0 & atoi(size) 0)fprintf(fp,n%st%st%d,id,size,status);/*fprintf(fp,n%dt%dt%d,id,size,status); */jobnum+;elsebreak;while(1);if(jobnum)printf(nFinished to input the jobs !);elseprintf(nNo job was given .);errorMessage();fclose(fp);int makeJobList(struct jobList
9、*jobs) /*从JOB文件中读出作业并创建作业链表*/char jobID10,size10,status10;struct jobList *rear;FILE *fp;openFile(&fp,d:job.cl,r);fscanf(fp,%s%s%s,jobID,size,status);if(*jobs = malloc(sizeof(struct jobList) = NULL)printf(nNot enough to allocate for the job .);fclose(fp);errorMessage();rear = *jobs;(*jobs)-next = NUL
10、L;while(!feof(fp)struct jobList *p;fscanf(fp,%s%s%s,jobID,size,status);if(p = malloc(sizeof(struct jobList) = NULL)printf(nNot enough to allocate for the job .);fclose(fp);errorMessage();p - next = rear - next;rear - next = p;rear = rear - next;rear - id = atoi(jobID);rear - size = atoi(size);rear -
11、 status = atoi(status);fclose(fp);return 0;int updateJobFile(struct jobList *jobs) /*更新作业链表中作业的状态*/FILE *fp;struct jobList *p;openFile(&fp,d:job.cl,w);fprintf(fp,job_IDtsizetstatus);for(p = jobs - next;p;p = p - next)fprintf(fp,n%dt%dt%d,p-id,p-size,p-status);fclose(fp);return 0;int showFreeList(str
12、uct freeList *empty) /*空闲分区队列显示*/FILE *fp;struct freeList *p = empty - next;int count = 0;openFile(&fp,d:result.cl,a);fprintf(fp,nnNow show the free list.);printf(nnNow show the free list.);if(p)fprintf(fp,nnumbertsizetstartAddress);printf(nnumbertsizetstartAddress);for(;p;p = p - next)fprintf(fp,n%
13、dt%dt%d,+count,p - size,p - startAddress);printf(n%dt%dt%d,count,p - size,p - startAddress);fclose(fp);return 1;elsefprintf(fp,nThe memory was used out !);printf(nThe memory was used out !); fclose(fp);return 0;void getJobInfo(struct jobList *jobs,int id,int *size,int *status) /*获取作业的信息*/struct jobL
14、ist *p = jobs-next;while(p & p-id != id)p = p-next;if(p = NULL)printf(nCant find the job which id is : %d .,id);errorMessage();else*size = p - size;*status = p - status;void updateJobStatus(struct jobList *jobs,int id,int status)struct jobList *p = (*jobs)-next;while(p & p-id != id)p = p-next;if(p =
15、 NULL)printf(nCant find the job which id is : %d .,id);errorMessage();elsep - status = status;int showUsedList(struct jobList *jobs,struct usedList *used) /*作业占用链表显示*/FILE *fp;struct usedList *p = used - next;int count = 0,size,status;openFile(&fp,d:result.cl,a);fprintf(fp,nnNow show the used list.)
16、;printf(nnNow show the used list.);if(p)fprintf(fp,nnumbertjobIDtsizetstartAddress);printf(nnumbertjobIDtsizetstartAddress);for(;p;p = p - next)getJobInfo(jobs,p - jobID,&size,&status);fprintf(fp,n%dt%dt%dt%d,+count,p-jobID,size,p- startAddress);printf(n%dt%dt%dt%d,count,p-jobID,size,p- startAddress
17、);fclose(fp);return 1;elsefprintf(fp,nNo job in the memory ! You should input some jobs to it.);printf(nNo job in the memory ! You should input some jobs to it.);fclose(fp);return 0;int showJobList(struct jobList *jobs) /*显示作业链表*/struct jobList *p;p = jobs-next;if(p = NULL)printf(nNo job in the list
18、 ! Try again next time.);return 0;printf(nnThe job list is as fallow :njob_IDtsizetstatus);while(p)printf(n%dt%dt%d,p-id,p-size,p-status);p = p-next;return 1;void moveFragment(struct jobList *jobs,struct freeList *empty,struct usedList *used)int size,status;struct usedList *p;int address = memorySta
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 源代码 15
限制150内