1、进程管理模拟系统C语言源代码模拟进程管理源代码:#include stdio.h#includegraphics.h#include dos.h#include stdlib.h#include conio.h#define SEC 3#define NULL 0char han1S=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,0x
2、04,;char han2S=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,;char han3S=0x02,0x20,0x42,0x20,0x22,0x28,0x2F,0xFC,0x02,0x20,0x02,0x20,0xE2,0x20,0x22,0x28,0x2F,0xFC,0x22,0x20,0x22,0x20,0x2
3、2,0x20,0x24,0x20,0x50,0x26,0x8F,0xFC,0x00,0x00,;char han4S=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,;char han5S=0x10,0x10,0x11,0xF8,0x11,0x10,0x11,0xF0,0xFC,0x04,0x17,0xBE,0x14,0xA4
4、,0x1F,0xBC,0x30,0x40,0xD0,0x44,0x1F,0xFE,0x10,0xE0,0x11,0x50,0x12,0x4E,0x54,0x44,0x20,0x40,;char han6S=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,;char han7S=0x00,0x38,0x7F,0xC0,0x04,
5、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,;char han8S=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,0x0
6、8,0x00,;char han9S=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,;char han10S=0x10,0x00,0x10,0x08,0x10,0x88,0x12,0x48,0xFE,0x68,0x12,0x28,0x16,0x08,0x1A,0x08,0x32,0x08,0xD2,0x08,0x12,0x4
7、8,0x12,0x88,0x13,0x14,0x12,0x22,0x50,0x42,0x20,0x80,;char han11S=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,;char han12S=0x08,0x04,0x1D,0xFE,0xF1,0x04,0x11,0x04,0x11,0x04,0xFF,0x04,0x
8、11,0xFC,0x38,0x00,0x37,0xFE,0x54,0x20,0x50,0x28,0x91,0xFC,0x10,0x20,0x10,0x24,0x17,0xFE,0x10,0x00,;char han13S=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,;char han14S=0x00,0x08,0x13,0
9、xFC,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,;char han15S=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,0x1
10、2,0x28,0x14,0x10,;char han16S=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,;char han17S=0x08,0x80,0x08,0x80,0x08,0x80,0x10,0x88,0x10,0x98,0x30,0xA0,0x50,0xC0,0x90,0x80,0x11,0x80,0x12,0x
11、80,0x14,0x80,0x10,0x80,0x10,0x82,0x10,0x82,0x10,0x7E,0x10,0x00,;char han18S=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,;char han19S=0x00,0x80,0x00,0x80,0x08,0x80,0xFC,0x80,0x10,0x84,0
12、x17,0xFE,0x10,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x1D,0x04,0xF1,0x04,0x41,0x04,0x02,0x44,0x04,0x28,0x08,0x10,;char chu1S=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,;char chu2S=0x02,0x
13、00,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,;void drawmat(char *mat,int matsize,int x,int y,int color)int i,j,k,n;n=(matsize-1)/8+1;for(j=0;jmatsize;j+) for(i=0;in;i+) for(k=0;kk) putpixel(x+
14、i*8+k,y+j,color);/*定义结构体*/typedef struct PCB int PID; int UID; struct PCB * next;PCB;PCB *really , *excute , *wait;/*create queue header */*queue operation 入队*/int enqueue(PCB *head , PCB *node) PCB *p; p = head; if(p - next = NULL) head - next = node; return 1; while(p) if(p - next = NULL) p - next
15、 = node; return 1; else p = p - next; /*enquue*/*dequeue 出队列 */PCB * dequeue(PCB *head) PCB *p; p = head; if(p - next = NULL) return NULL; else p = p - next; head - next = p - next; p - next = NULL; return p; /*head to next*/*dequeue*/*PCB operate*/*新建进程*/int create() PCB *p; p = (PCB*)malloc(sizeof
16、(PCB); p - next = NULL; printf(input PID and UID to a new processn); scanf(%d %d,&p - PID,&p - UID); if(enqueue(really , p) printf(create a process: PID = %d UID = %dn, p - PID , p - UID); else printf(create Failedn);/*create*/*执行 fexcute*/int fexcute() PCB *p = dequeue(really); if(p = NULL) printf(
17、NO process in queue n); return 0; else enqueue(excute , p); printf(add a process into excute queue process: PID = %d UID= %d n ,p-PID , p-UID); return 1; /*excute*/int wake() PCB *p = dequeue(wait); if(p = NULL) printf(NO process in queue n); return 0; else enqueue(really , p); printf(add a process
18、into wait really process: PID = %d UID= %d n ,p-PID , p-UID); return 1; int block() PCB *p = dequeue(excute); if(p = NULL) printf(NO process in queue n); return 0; else enqueue(wait , p); printf(add a process into wait queue process: PID = %d UID= %d n ,p-PID , p-UID); return 1; /*block*/*输出队列 outpu
19、tqueue*/int outputqueue(PCB *head) PCB *p; if(head - next = NULL) /*队列为空*/ printf(queue is null n); return 1; p = head - next; while(p) /*打印process id UID*/ printf(PID = %d UID = %d n , p - PID , p - UID); p = p - next; return 0;/*output输出*/int output() printf(REALLLY QUEUE:n); outputqueue(really);
20、printf(EXCUTE QUEUE: n); outputqueue(excute); printf(WAIT QUEUE: n); outputqueue(wait);/*output*/*init 初始化*/int init() int i; 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 =
21、 NULL; printf(_PROCESS SECHUDLE_n); printf(WELCOME TO PROCESS SECHUDLE); for(i=0;i next = NULL; scanf(%d %d,&p - PID , &p - UID); if(p - PID = 0 & p - UID = 0) break; else if(enqueue(really , p) printf(new process PID = %d UID = %d added!n,p - PID , p - UID); else return 0; return 1;/*init*/*运行一个pro
22、cess*/int run() PCB *p = excute; int s = SEC; if(excute - next = NULL) printf(no process in excute queue n); return 0; else p = excute - next; printf(system will sleep %ds as process runningn,s); sleep(3); printf(process: PID = %d UID= %d excute successed.n , p - PID , p - UID ); excute - next = p -
23、 next; free(p); /*run*/*离开*/int leave() int COMMAND; printf(Are you sure to leave? YES-(1), NO-(2)n); scanf(%d,&COMMAND); if(COMMAND=1) clrscr(); exit(0); if(COMMAND=2) printf(n); help(); int help() printf(_HELP MENU_n); printf(t-h HELP show help optionn); printf(t-c CREATE create a new process , an
24、d put to really queuen); printf(t-b BLOCK block a process in excute queuen); printf(t-w WAKE wake a process in wait queuen); printf(t-e EXCUTE excute a process in really queuen); printf(t-o OUTPUT output all processes in queuesn); printf(t-r RUN excute a process in excute queuen); printf(t-x EXIT ex
25、it this programn); printf(_n); printf(t type H will show this menun);int main() char COMMAND = NULL; int i,m; int gdriver=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) re
26、ctangle(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,
27、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
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1