没有合适的资源?快使用搜索试试~ 我知道了~
操作系统源代码.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 157 浏览量
2023-05-26
13:35:07
上传
评论
收藏 351KB PDF 举报
温馨提示
试读
19页
操作系统源代码.pdf
资源推荐
资源详情
资源评论
-
-
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int memoryStartAddress = -1;
int memorySize = -1;
struct jobList
{
int id; /* 作业 ID */
int size; /* 作业大小〔需要的存储空间大小〕 */
int status;
/* 作业状态 0 : new job ,1 : in the memory , 2 : finished . */
struct jobList *next; /* 作业链表指针 */
};
struct freeList
{
int startAddress; /* 分区起始地址 */
int size; /* 分区大小 */
struct freeList *next; /* 分区链表指针 */
};
struct usedList
{
int startAddress; /* 分区起始地址 */
int jobID; /* 分区中存放作业 ID */
struct usedList *next; /* 分区链表指针 */
};
void errorMessage(void) /*出现严重错误时显示信息并完毕程序*/
{
printf(" Error !");
printf("Press any key to exit !");
getch();
exit(1);
}
void openFile(FILE **fp,char *filename,char *mode)
/*以要求的方式翻开文件*/
{
if((*fp = fopen(filename,mode)) == NULL)
{
printf("Can't open %s in mode %s.",filename,mode);
errorMessage();
-
word.zl-
-
-
}
}
void makeFreeNode(struct freeList **empty,int startAddress,int size)
/*根据参数 startAddress、size 创立空闲节点,由 empty 指针返回*/
{
if((*empty = malloc(sizeof(struct freeList))) == NULL)
{
printf("\nNot enough to allocate for the free node .");
errorMessage();
}
(*empty)->startAddress = startAddress;
(*empty)->size = size;
(*empty)->next = NULL;
}
void iniMemory(void) /*初始化存储空间起始地址、大小*/
{
char MSA[10],MS[10];
printf("\nPlease input the start address of the memory !");
scanf("%s",MSA);
memoryStartAddress = atoi(MSA);
printf("\nPlease input the size of the memory !");
scanf("%s",MS);
memorySize = atoi(MS);
}
char selectFitMethod(void) /*选择适应算法*/
{
FILE *fp;
char fitMethod;
do{
printf("\n\nPlease 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(fitMethod < '1' || fitMethod > '4');
openFile(&fp,"d:\\result.cl","a");
switch(fitMethod)
{
-
word.zl-
-
-
case '1':
fprintf(fp,"\n\n\n\n\tBest fit");
fprintf(fp,"\n**********************************************");
break;
case '2':
fprintf(fp,"\n\n\n\n\tWorst fit");
fprintf(fp,"\n**********************************************");
break;
case '3':
fprintf(fp,"\n\n\n\n\tFirst fit");
fprintf(fp,"\n**********************************************");
break;
case '4': fprintf(fp,"\n\n\n\n\tLast fit");
fprintf(fp,"\n**********************************************");
break;
}
fclose(fp);
return fitMethod;
}
void inputJob(void) /*从键盘输入作业到 D 盘的 JOB 文件*/
{
int /*id,size, */status = 0,jobnum = 0;
FILE *fp;
char id[10],size[10];
openFile(&fp,"d:\\job.cl","w");
fprintf(fp,"job_ID\tsize\tstatus");
printf("\n\n\n\nPlease input the jobs as fallow !\
\nEnter a integer smaller than 1 to quit .\njob_ID\tsize\n");
do{
/* scanf("%d%d",&id,&size); */
scanf("%s\t%s",id,size);
if(atoi(id) > 0 && atoi(size) > 0)
{
fprintf(fp,"\n%s\t%s\t%d",id,size,status);
/* fprintf(fp,"\n%d\t%d\t%d",id,size,status); */
jobnum++;
-
word.zl-
-
-
}
else break;
}while(1);
if(jobnum)
printf("\nFinished to input the jobs !");
else
{
printf("\nNo job was given .");
errorMessage();
}
fclose(fp);
}
int makeJobList(struct jobList **jobs)
/*从 JOB 文件中读出作业并创立作业链表*/
{
char jobID[10],size[10],status[10];
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 = NULL;
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;
-
word.zl-
剩余18页未读,继续阅读
资源评论
hhappy0123456789
- 粉丝: 62
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功