进程管理模拟系统C语言源代码.docx
《进程管理模拟系统C语言源代码.docx》由会员分享,可在线阅读,更多相关《进程管理模拟系统C语言源代码.docx(18页珍藏版)》请在冰豆网上搜索。
![进程管理模拟系统C语言源代码.docx](https://file1.bdocx.com/fileroot1/2023-1/22/cf98bacc-ff30-4204-aad5-c773db510d9e/cf98bacc-ff30-4204-aad5-c773db510d9e1.gif)
进程管理模拟系统C语言源代码
模拟进程管理源代码:
#include"stdio.h"
#include"graphics.h"
#include"dos.h"
#include"stdlib.h"
#include"conio.h"
#defineSEC3
#defineNULL0
charhan1S[]={
0x00,0x80,0x00,0x80,0xFC,0x80,0x04,
0xFC,0x45,0x04,0x46,0x48,0x28,0x40,
0x28,0x40,0x10,0x40,0x28,0x40,0x24,
0xA0,0x44,0xA0,0x81,0x10,0x01,0x08,
0x02,0x0E,0x0C,0x04,
};
charhan2S[]={
0x00,0x00,0x41,0x84,0x26,0x7E,0x14,
0x44,0x04,0x44,0x04,0x44,0xF4,0x44,
0x14,0xC4,0x15,0x44,0x16,0x54,0x14,
0x48,0x10,0x40,0x10,0x40,0x28,0x46,
0x47,0xFC,0x00,0x00,
};
charhan3S[]={
0x02,0x20,0x42,0x20,0x22,0x28,0x2F,
0xFC,0x02,0x20,0x02,0x20,0xE2,0x20,
0x22,0x28,0x2F,0xFC,0x22,0x20,0x22,
0x20,0x22,0x20,0x24,0x20,0x50,0x26,
0x8F,0xFC,0x00,0x00,
};
charhan4S[]={
0x04,0x00,0x02,0x00,0x01,0x00,0x01,
0x00,0x01,0x00,0x02,0x80,0x02,0x80,
0x02,0x80,0x04,0x40,0x04,0x40,0x08,
0x20,0x08,0x20,0x10,0x10,0x20,0x10,
0x40,0x0E,0x80,0x04,
};
charhan5S[]={
0x10,0x10,0x11,0xF8,0x11,0x10,0x11,
0xF0,0xFC,0x04,0x17,0xBE,0x14,0xA4,
0x1F,0xBC,0x30,0x40,0xD0,0x44,0x1F,
0xFE,0x10,0xE0,0x11,0x50,0x12,0x4E,
0x54,0x44,0x20,0x40,
};
charhan6S[]={
0x09,0x00,0x09,0x00,0x09,0x04,0x11,
0xFE,0x12,0x80,0x32,0x80,0x54,0x90,
0x98,0xF8,0x10,0x80,0x10,0x80,0x10,
0x88,0x10,0xFC,0x10,0x80,0x10,0x80,
0x10,0x80,0x10,0x80,
};
charhan7S[]={
0x00,0x38,0x7F,0xC0,0x04,0x00,0x04,
0x10,0x08,0x20,0x3F,0xC0,0x01,0x00,
0x02,0x20,0x04,0x10,0x3F,0xF8,0x01,
0x08,0x09,0x20,0x09,0x10,0x11,0x08,
0x25,0x08,0x02,0x00,
};
charhan8S[]={
0x10,0x80,0x10,0x40,0x20,0x48,0x27,
0xFC,0x48,0x80,0xF9,0x10,0x12,0x08,
0x27,0xFC,0x41,0x24,0xF9,0x20,0x41,
0x20,0x01,0x20,0x1A,0x22,0xE2,0x22,
0x44,0x1E,0x08,0x00,
};
charhan9S[]={
0x11,0x10,0x11,0x14,0x1F,0xFE,0x11,
0x10,0xFD,0x18,0x13,0xFC,0x32,0x08,
0x3B,0xF8,0x56,0x08,0x53,0xF8,0x90,
0x40,0x1F,0xFE,0x10,0x40,0x10,0xB0,
0x11,0x0E,0x16,0x04,
};
charhan10S[]={
0x10,0x00,0x10,0x08,0x10,0x88,0x12,
0x48,0xFE,0x68,0x12,0x28,0x16,0x08,
0x1A,0x08,0x32,0x08,0xD2,0x08,0x12,
0x48,0x12,0x88,0x13,0x14,0x12,0x22,
0x50,0x42,0x20,0x80,
};
charhan11S[]={
0x02,0x20,0x42,0x20,0x22,0x28,0x2F,
0xFC,0x02,0x20,0x02,0x20,0xE2,0x20,
0x22,0x28,0x2F,0xFC,0x22,0x20,0x22,
0x20,0x22,0x20,0x24,0x20,0x50,0x26,
0x8F,0xFC,0x00,0x00,
};
charhan12S[]={
0x08,0x04,0x1D,0xFE,0xF1,0x04,0x11,
0x04,0x11,0x04,0xFF,0x04,0x11,0xFC,
0x38,0x00,0x37,0xFE,0x54,0x20,0x50,
0x28,0x91,0xFC,0x10,0x20,0x10,0x24,
0x17,0xFE,0x10,0x00,
};
charhan13S[]={
0x10,0x40,0x1F,0x7C,0x28,0x90,0x45,
0x08,0x01,0x00,0x7F,0xFE,0x40,0x02,
0x9F,0xF4,0x10,0x10,0x1F,0xF0,0x10,
0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,
0x1F,0xF0,0x10,0x00,
};
charhan14S[]={
0x00,0x08,0x13,0xFC,0xFA,0x48,0x22,
0x48,0x23,0xF8,0x22,0x48,0xFA,0x48,
0x23,0xF8,0x20,0x40,0x20,0x50,0x23,
0xF8,0x3C,0x40,0xE0,0x40,0x40,0x44,
0x0F,0xFE,0x00,0x00,
};
charhan15S[]={
0x20,0x00,0x10,0x00,0x10,0x04,0x05,
0xFE,0xFC,0x44,0x08,0x44,0x10,0x44,
0x34,0x44,0x58,0x44,0x94,0x44,0x10,
0x44,0x10,0x84,0x10,0x84,0x11,0x04,
0x12,0x28,0x14,0x10,
};
charhan16S[]={
0x10,0x40,0x10,0x40,0x10,0x40,0x10,
0x80,0xFC,0x88,0x25,0x04,0x27,0xFE,
0x24,0x02,0x24,0x04,0x49,0xFE,0x29,
0x04,0x11,0x04,0x29,0x04,0x45,0x04,
0x85,0xFC,0x01,0x04,
};
charhan17S[]={
0x08,0x80,0x08,0x80,0x08,0x80,0x10,
0x88,0x10,0x98,0x30,0xA0,0x50,0xC0,
0x90,0x80,0x11,0x80,0x12,0x80,0x14,
0x80,0x10,0x80,0x10,0x82,0x10,0x82,
0x10,0x7E,0x10,0x00,
};
charhan18S[]={
0x00,0x80,0x00,0xA0,0x00,0x90,0x3F,
0xFC,0x20,0x80,0x20,0x80,0x20,0x84,
0x3E,0x44,0x22,0x48,0x22,0x48,0x22,
0x30,0x2A,0x20,0x24,0x62,0x40,0x92,
0x81,0x0A,0x00,0x06,
};
charhan19S[]={
0x00,0x80,0x00,0x80,0x08,0x80,0xFC,
0x80,0x10,0x84,0x17,0xFE,0x10,0x84,
0x10,0x84,0x10,0x84,0x10,0x84,0x1D,
0x04,0xF1,0x04,0x41,0x04,0x02,0x44,
0x04,0x28,0x08,0x10,
};
charchu1S[]={
0x00,0x08,0x7F,0xFC,0x01,0x00,0x01,
0x00,0x01,0x00,0x01,0x00,0x11,0x10,
0x11,0xF8,0x11,0x00,0x11,0x00,0x11,
0x00,0x11,0x00,0x11,0x00,0x11,0x04,
0xFF,0xFE,0x00,0x00,
};
charchu2S[]={
0x02,0x00,0x02,0x00,0x02,0x04,0xFF,
0xFE,0x04,0x00,0x04,0x40,0x08,0x40,
0x08,0x50,0x13,0xF8,0x30,0x40,0x50,
0x40,0x90,0x40,0x10,0x40,0x10,0x44,
0x17,0xFE,0x10,0x00,
};
voiddrawmat(char*mat,intmatsize,intx,inty,intcolor)
{inti,j,k,n;
n=(matsize-1)/8+1;
for(j=0;jfor(i=0;ifor(k=0;k<8;k++)
if(mat[j*n+i]&(0x80>>k))
putpixel(x+i*8+k,y+j,color);
}
/*定义结构体*/
typedefstructPCB
{
intPID;
intUID;
structPCB*next;
}PCB;
PCB*really,*excute,*wait;
/*createqueueheader*/
/*queueoperation入队*/
intenqueue(PCB*head,PCB*node)
{
PCB*p;
p=head;
if(p->next==NULL)
{
head->next=node;
return1;
}
while(p)
{
if(p->next==NULL)
{
p->next=node;
return1;
}
elsep=p->next;
}
}/*enquue*/
/*dequeue出队列*/
PCB*dequeue(PCB*head)
{
PCB*p;
p=head;
if(p->next==NULL)
{
returnNULL;
}
else
{
p=p->next;
head->next=p->next;
p->next=NULL;
returnp;
}
/*headtonext*/
}/*dequeue*/
/*PCBoperate*/
/*新建进程*/
intcreate()
{
PCB*p;
p=(PCB*)malloc(sizeof(PCB));
p->next=NULL;
printf("inputPIDandUIDtoanewprocess\n");
scanf("%d%d",&p->PID,&p->UID);
if(enqueue(really,p))
printf("createaprocess:
PID=%dUID=%d\n",p->PID,p->UID);
else
printf("createFailed\n");
}/*create*/
/*执行fexcute*/
intfexcute()
{
PCB*p=dequeue(really);
if(p==NULL)
{
printf("NOprocessinqueue\n");
return0;
}
else
{
enqueue(excute,p);
printf("addaprocessintoexcutequeueprocess:
PID=%dUID=%d\n",p->PID,p->UID);
return1;
}
}/*excute*/
intwake()
{
PCB*p=dequeue(wait);
if(p==NULL)
{
printf("NOprocessinqueue\n");
return0;
}
else
{
enqueue(really,p);
printf("addaprocessintowaitreallyprocess:
PID=%dUID=%d\n",p->PID,p->UID);
return1;
}
}
intblock()
{
PCB*p=dequeue(excute);
if(p==NULL)
{
printf("NOprocessinqueue\n");
return0;
}
else
{
enqueue(wait,p);
printf("addaprocessintowaitqueueprocess:
PID=%dUID=%d\n",p->PID,p->UID);
return1;
}
}/*block*/
/*输出队列outputqueue*/
intoutputqueue(PCB*head)
{
PCB*p;
if(head->next==NULL)
{/*队列为空*/
printf("queueisnull\n");
return1;
}
p=head->next;
while(p)
{/*打印processidUID*/
printf("PID=%dUID=%d\n",p->PID,p->UID);
p=p->next;
}
return0;
}
/*output输出*/
intoutput()
{
printf("REALLLYQUEUE:
\n");
outputqueue(really);
printf("EXCUTEQUEUE:
\n");
outputqueue(excute);
printf("WAITQUEUE:
\n");
outputqueue(wait);
}/*output*/
/*init初始化*/
intinit()
{inti;
PCB*p;
clrscr();
really=(PCB*)malloc(sizeof(PCB));
really->next=NULL;
excute=(PCB*)malloc(sizeof(PCB));
excute->next=NULL;
wait=(PCB*)malloc(sizeof(PCB));
wait->next=NULL;
printf("_____________________________PROCESSSECHUDLE__________________________________\n");
printf("WELCOMETOPROCESSSECHUDLE");
for(i=0;i<18;i++)
{
printf(".");
delay(50000);
delay(50000);
}
printf("\nPleaseinputPIDandUIDasinteger,00asover\n");
while
(1)
{
p=(PCB*)malloc(sizeof(PCB));
p->next=NULL;
scanf("%d%d",&p->PID,&p->UID);
if(p->PID==0&&p->UID==0)
break;
else
{
if(enqueue(really,p))
{
printf("newprocessPID=%dUID=%dadded!
\n",p->PID,p->UID);
}
elsereturn0;
}
}
return1;
}/*init*/
/*运行一个process*/
intrun()
{
PCB*p=excute;
ints=SEC;
if(excute->next==NULL)
{
printf("noprocessinexcutequeue\n");
return0;
}
else
{
p=excute->next;
printf("systemwillsleep%dsasprocessrunning\n",s);
sleep(3);
printf("process:
PID=%dUID=%dexcutesuccessed..\n",p->PID,p->UID);
excute->next=p->next;
free(p);
}
}/*run*/
/*离开*/
intleave()
{
intCOMMAND;
printf("Areyousuretoleave?
YES-
(1),NO-
(2)\n");
scanf("%d",&COMMAND);
if(COMMAND==1)
{clrscr();
exit(0);
}
if(COMMAND==2)
{printf("\n");
help();
}
}
inthelp()
{
printf("__________________________HELPMENU____________________________\n");
printf("\t-hHELPshowhelpoption\n");
printf("\t-cCREATEcreateanewprocess,andputtoreallyqueue\n");
printf("\t-bBLOCKblockaprocessinexcutequeue\n");
printf("\t-wWAKEwakeaprocessinwaitqueue\n");
printf("\t-eEXCUTEexcuteaprocessinreallyqueue\n");
printf("\t-oOUTPUToutputallprocessesinqueues\n");
printf("\t-rRUNexcuteaprocessinexcutequeue\n");
printf("\t-xEXITexitthisprogram\n");
printf("_______________________________________________________________\n");
printf("\ttype'H'willshowthismenu\n");
}
intmain()
{
charCOMMAND=NULL;
inti,m;
intgdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
setbkcolor(LIGHTBLUE);
setcolor(21);
for(i=40;i<=600;i+=12)
{
rectangle(i,40,i+10,49);
rectangle(i,451,i+10,460);
}
for(i=40;i<=450;i+=12)
{
rectangle(40,i,49,i+10);
rectangle(601,i,610,i+10);
}
setcolor(14);
rectangle(150,100,475,250);
setcolor(11);
rectangle(145,93,480,258);
line(145,93,150,100);
line(480,258,475,250);
line(150,250,145,258);
line(475,100,480,93);
drawmat(han1S,16,200,150,BLUE);
delay(50000);
delay(20000);
drawmat(han2S,16,230,150,BLUE);
delay(50000);
delay(20000);
drawmat(han3S,16,260,150,BLUE);
delay(50000);
delay(20000);
drawmat(han4S,16,290,150,BLUE);
delay(50000);
delay(20000);
drawmat(han5S,16,320,150,BLUE);
delay(50000);
delay(20000);
drawmat(han6S,16,350,150,BLUE);
delay(50000);
delay(20000);
drawmat(han7S,16,380,150,BLUE);
delay(50000);
delay(20000);
drawmat(han8S,16,410,150,BLUE);
delay(50000);
delay(50000);
delay(50000);
drawmat(han9S,16,220,189,BLUE);
delay(50000);
delay(20000);
drawmat(han10S,16,250,189,BLUE);
delay(50000);
delay(20000);
drawm