操作系统实验-PCB池的建立与撤除

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includeiostream.h#includestdlib.h#includestring.hconstintMAX_NAME=10;typedefstructpcb{charname[MAX_NAME];intpriority;inttime;//ËùÐèµÄʱ¼äƬstructpcb*next,*prev;}PCB;PCB*front=NULL,*rear=NULL;voidInsert_List(PCB*&s)//½«½ø³Ì¼ÓÈëÓÅÏȶÓÁÐ{if(front==NULL){front=rear=s;}else{PCB*r=rear;while(r){if(s-priorityr-priority)r=r-prev;elsebreak;}if(!r){s-next=front;front-prev=s;front=s;}elseif(r==rear){rear-next=s;s-prev=rear;rear=s;}else{s-next=r-next;s-prev=r;r-next-prev=s;r-next=s;}}}voidshow(PCB*&s){coutNAME:s-name\tPPRIORITY:s-priority\tTIME:s-timeendl;deletes;}voidrelease_PCB(char*name)//µ±½ø³ÌÔËÐÐÍê±Ïºó£¬½«ÆäPCB»ØÊÕ{PCB*r=front;while(r){if(!strcmp(r-name,name))break;elser=r-next;}if(!r){coutûÓд˽ø³Ì´æÔÚ£¡endl;return;}if(r==rear){if(rear==front){rear=front=NULL;show(r);return;}rear=r-prev;if(rear)rear-next=NULL;}elseif(r==front){front=r-next;if(front)front-prev=NULL;}else{r-prev-next=r-next;r-next-prev=r-prev;}show(r);}boolif_the_same_name_used_before(char*name){PCB*r=front;while(r){if(!strcmp(r-name,name))returntrue;elser=r-next;}returnfalse;}voidmain(){cout²Ù×÷ÀàÐÍ£º(1£º½ø³ÌÉêÇ룻2£º½ø³ÌÊÍ·Å)endl;cout°´ÆäËû¼ü½«ÍƳö³ÌÐò²¢Êä³ö¾ÍÐ÷½ø³ÌPCBÐÅÏ¢¡£endl;front=rear;while(true){intchoose;coutÇëÊäÈë²Ù×÷ÀàÐÍ;cinchoose;if(choose==1){PCB*s=newPCB;if(!s){coutÄÚ´æÉêÇëʧ°Ü£¡endl;exit(0);}coutÊäÈë½ø³Ì±êÖ¾·û:;cins-name;if(if_the_same_name_used_before(s-name)){cout´Ë½ø³ÌÃûÒÑ´æÔÚ£¬ÇëÓÃÁíÍâÃû×Ö£¡endl;deletes;continue;}coutÊäÈë½ø³ÌÓÅÏÈÊý:;cins-priority;coutÊäÈë½ø³ÌËùÐèµÄʱ¼äƬ:;cins-time;s-next=NULL;s-prev=NULL;Insert_List(s);}elseif(choose==2){coutÊäÈë½ø³Ì±êÖ¾·û:;charname[MAX_NAME];cinname;release_PCB(name);}elsereturn;}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功