操作系统-进程管理实验c语言

操作系统-进程管理实验c语言

ID:6380079

大小:44.00 KB

页数:6页

时间:2018-01-12

操作系统-进程管理实验c语言_第1页
操作系统-进程管理实验c语言_第2页
操作系统-进程管理实验c语言_第3页
操作系统-进程管理实验c语言_第4页
操作系统-进程管理实验c语言_第5页
资源描述:

《操作系统-进程管理实验c语言》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、#include"stdio.h"#include"stdlib.h"#defineready1#definerun2structpcb{charname[10];intpriority;/*进程的优先级*/intstate;/*进程的状态:可以有run、ready、finish(可有可无)*/intneedtime;/*进程需要运行的时间*/intruntime;inttime;/*进程已运行的时间*/structpcb*next;/*指向下一个进程PCB的指针*/};typedefstructpcbPCB;PCB*h

2、ead=NULL;/*此函数用于创建进程队列*/voidcreate(void){PCB*p,*q;intn,i;printf("Enterthenumberoftheprocess:");scanf("%d",&n);/*输入要创建的进程的数量*/head=(PCB*)malloc(sizeof(PCB));/*创建一个表头结点*/p=head;for(i=1;i<=n;i++)/*用循环来创建指定个结点*/{q=(PCB*)malloc(sizeof(PCB));p->next=q;p=q;printf("ent

3、ertheNO.%dnameofprocess:",i);scanf("%s",&p->name);printf("enterthepriorityofprocess:");scanf("%d",&p->priority);printf("enterthetimeneed:");scanf("%d",&p->needtime);p->state=ready;p->runtime=0;p->next=NULL;}}/*删除执行完毕的进程*/voiddelete(PCB*head,PCB*p){PCB*q;q=head;wh

4、ile(q->next!=p)q=q->next;q->next=p->next;free(p);}/*找出执行时间最短的进程*/PCB*getminneedtime(PCB*head){PCB*p,*q;p=head->next;q=p->next;while(q){if(p->needtime>q->needtime)p=q;q=q->next;}return(p);}/*找出优先级最高的进程*/PCB*getpriority(PCB*head){PCB*p,*q;p=head->next;q=p->next;whi

5、le(q){if(p->priority>q->priority)p=q;}return(p);}/*时间片轮转*/voidRR(void){PCB*p,*q,*r;inttime;printf("inputthetime:");scanf("%d",&time);for(p=head->next;p->next;p=p->next){r=p;}while(head->next){p=head->next;/*选出就绪队列的第一个进程*/p->state=run;printf("***Nowtherunningp

6、rocessis:");/*输出该进程的信息*/printf("%st",p->name);printf("state:runt");printf("needtime:%dt",p->needtime);printf("runtime:%d",p->needtime);q=head->next;if(p->needtime-p->runtime<=p->time)/*时间片内,进程运行结束否*/{p->runtime=p->needtime;printf("runtime:%d",p->runtime)

7、;}else{p->runtime=p->runtime+p->time;printf("runtime:%d",p->runtime);}q=p->next;if(q!=NULL)/*输出就绪队列中的进程信息*/printf("***Nowthereadyquenueis:");elseprintf("***NowthereadyquenueisNONE!");while(q){printf("%st",q->name);printf("state:readyt");printf("needtime:%d

8、t",q->needtime);printf("runtime:%dt",q->runtime);printf("");q=q->next;}if(p->runtime==p->needtime){delete(head,p);}else{head->next=p->next;r->next=p;r=p;r->

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。