操作系统实验报告(5)

2019-05-17 12:17

q->size = q->size + s->size + p->size; }else{

if(s->sPosition + s->size == p->sPosition){ //only bottom is free space; s->size = s->size + p->size;

if((tmp = (free_block * )malloc(sizeof(free_block))) == NULL){ printf(\ }

tmp->size = s->size;

tmp->sPosition = s->sPosition; tmp->next = p->next; q->next = tmp; free(p); }else{

if(q->sPosition + q->size == s->sPosition){ //only top is free space q->size = q->size + s->size;

}else{ //neither bottom or top is free space

if((tmp = (free_block * )malloc(sizeof(free_block))) == NULL){ printf(\ }

tmp->size = s->size;

tmp->sPosition = s->sPosition; tmp->next = p; q->next = tmp; } } }

}else{ //no bottom free space;

if(q->sPosition + q->size == s->sPosition){ //only top is free space q->size = q->size + s->size;

}else{ //neither bottom or top is free space

21

if((tmp = (free_block * )malloc(sizeof(free_block))) == NULL){ printf(\ }

tmp->size = s->size;

tmp->sPosition = s->sPosition; tmp->next = NULL; q->next = tmp; } } }

//释放空间函数 void cfree() {

int pid;

process * p_p,*p_q;

p_p = p_head->next; printf(\

printf(\ scanf(\

//find the process of the specify pid while(p_p->pid != pid && p_p != NULL){

p_q = p_p; //p_p stand for the process ;p_q stand for pre process p_p = p_p->next; }

if(p_p == NULL){

printf(\ }else{

cfree2(p_p); if(p_p == NULL){

22

p_q->next = NULL; }else{

p_q->next = p_p->next; } }

//free space showFreeChain(); showProcessChain(); } //主页面 void prtUsage() {

printf(\\

printf(\ printf(\ printf(\ printf(\

printf(\} int main() { init(); int a; while(1){ prtUsage();

printf(\/2/0 to select\\n\ scanf(\ if(a > 2 || a < 0){

23

printf(\ continue; } switch(a){

case 1:cmalloc();break; case 2:cfree();break; case 0:goto end; default:

printf(\ break; } } end: getchar();

printf(\}

主要功能模块:

void init() 初始化

void showFreeChain() 显示空闲内存信息 void showProcessChain()显示进程信息 void cmalloc()申请空间函数 void cfree()释放空间函数 void prtUsage()主页面

24

运行结果:

主界面

申请内存

释放内存

25


操作系统实验报告(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:监理规划

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: