这是我自己做的一个版本,望斑竹给予指点!!!谢谢* s' S/ F, |5 T* p6 s
8 k7 l, f W5 L$ J8 v4 O3 h0 g
#include: ?# `+ Z# U5 e, Y$ N4 e
#include
* a7 j H3 C5 b' w+ f#include& y/ C/ _; I. ?" E' l* e
#include
* J% y* [2 l5 M. A* b/ i' Z) P#define running 1 /*用running 表示进程处于运行态*/* K7 G! a3 M+ t
#define aready 2 /*用aready表示进程处于就绪态*/
) q. |/ d- _2 P1 V" O8 x, o#define blocking 3 /*用blocking表示进程处于等待态*/
J4 M2 |2 {4 m: X- a' _#define sometime 5 /*用sometime 表示时间片大小*/
# H( z0 |% D7 R5 b. @#define n 10 /* 假定系统允许进程个数为10 */3 I9 \2 \9 `+ ^- X# y8 a
struct
$ Q( M7 L; U3 i, \7 y( Q: [{
0 [7 p& V1 C5 oint name; /*进程标识符*/3 D/ H2 x# u5 L5 L) O8 e5 c
int status; /*进程状态*/$ |0 F( x7 o1 g# e
int ax, bx, cx,dx; /*进程现场信息,通用寄存器内容*/+ J6 Z" X8 S% M* h# o4 z( a+ L! D
int pc; /*进程现场信息,程序计数器内容*/
/ h3 @$ |7 g2 g! Y0 tint psw; /*进程现场信息,程序状态字寄存器内容*/- J7 b4 x" P5 E. @! L- H
int next; /*下一个进程控制块的位置*/5 t& p; v& |% V) l! _: {
}pcbarea[n]; /*定义模拟进程控制块区域的数组*/7 h$ g( c# U' C4 N, w1 C! d
int PSW,AX,BX,CX,DX,PC,TIME; /*模拟寄存器*/
) U& X3 l( l) t+ ?" ]int run; /*定义指向正在运行进程的进程控制块的指针*/% `" u9 L9 y* {( g `) N5 f
struct
% B: L) \ l: C- g* q1 P{
7 J& Z+ V. _7 D R$ d' ?int head;3 P# n( F7 L3 }' @
int tail;
9 ^( _% J0 h% T% i. [* R}ready; /*定义指向就绪队列的头指针head和尾指针tail*/; m) C9 H+ i: ^5 d' t' K
int block; /*定义指向等待队列的指针*/! F$ U, J# c W* N# ^* a
int pfree; /*定义指向空闲进程控制块队列的指针*/
/ v5 ?% m, k% @; K1 pmain()
0 F# H9 H; S9 ~# N; X{ int gdriver=DETECT,gmode;4 Y6 A, p; ]) i
int i,x,y;
" Z! g, b/ F4 i' l for(i=1;i<=n;i++)) O; J! y7 s- w" g' K
{ready.head=pcbarea.next;}5 j& @ d: I4 ]" }$ e1 E
initgraph(&gdriver,&gmode,"");* x( C9 l1 J8 Q: M) ]6 x
setcolor(YELLOW);
# U3 L$ P+ l0 `: ?; C: L for(i=1;i<=4;i++)
- W9 ?0 j) j5 k: F, u' I9 H { setfillstyle(8,i);
( N; q ^1 |6 ]8 e9 y1 T( [ circle(284+13*i,190,6);
% T H: N1 k. O; A- x& Z floodfill(284+13*i,190,YELLOW);
5 l* R/ R# a& k( x- ~ }( Y; g% f9 T" v0 @8 W5 g
setlinestyle(0,0,3);
& X7 m5 _- s L2 S' u$ a circle(316,190,25);
, g: s$ G6 p) p1 l$ x setcolor(5);
2 H5 h5 @' q1 M6 R1 Q9 M settextstyle(3,0,4);2 D f! I r. K$ d, \$ T% x; e
outtextxy(35,311,"press any key to create objects!");
+ N" G4 J4 {% U/ F% a' b) w getch();
8 j" i0 ?* Z9 Z4 h( e2 g2 s setcolor(YELLOW);
& H4 _! U& C' S9 `3 u% g% C2 [" M line(300,215,290,235);
" {. ~! }' }" \. e$ z line(323,215,333,235);
# t: X2 g9 B5 a7 W, W delay(50000);# t' K! s& S/ R. Z% v$ ~1 N
setlinestyle(0,0,1);
* R7 Q2 o L4 @# _$ T9 q- r for(x=1;x<=2;x++)4 x3 L4 p2 m1 z0 B
{setfillstyle(8,x);
+ x% i. N1 k( Z. c% n8 F. z circle(267+13*x,246,6);/ b, x8 S6 ]; w/ T
floodfill(267+13*x,246,YELLOW);
5 \/ @. \9 {# t" \% W4 m- o }* {2 M% x! s3 @
for(y=3;y<=4;y++)
9 ?) Q6 K, Q: U( N; Y. X* J$ `7 R {setfillstyle(8,y);6 X, F5 {4 d) ~
circle(285+13*y,246,6);( B4 u% ?' V5 X8 w: w" R5 o, H0 y
floodfill(285+13*y,246,YELLOW);0 G. o0 b' _( [- h8 `0 t& H& }
}
. G: J9 J0 m' E( N setlinestyle(0,0,3);# _, `) e2 X2 P8 j) g! r9 c' O! C
circle(287,246,14);& B. @: ]3 i( k1 [: @
setlinestyle(0,0,3);
/ `+ \ ^ q5 u" Y1 B circle(330,246,14);
# ]5 e1 l1 ~& Q delay(50000);7 t9 H1 X* e! n8 E2 L- b" O
line(281,260,281,280);6 X. ?" i* I7 o
line(293,260,293,280);
; h7 A/ | x2 r) @% ]) r line(322,260,322,280);1 {0 {8 U4 s( r
line(333,260,333,280);$ X7 k# k# z0 E3 {0 t% h7 h
delay(50000);
. v& m( Z3 X$ U setlinestyle(0,0,1);! l1 o& c/ J3 B
setfillstyle(8,1);
. L8 Q- D! Y; O6 O# w5 z circle(281,286,6);
F% n. K1 |/ L' ^1 y floodfill(281,286,YELLOW);/ ]4 z1 j. L6 R* _
setfillstyle(8,2);
& L7 K) O8 W5 J3 e2 D! r circle(293,286,6);
, h$ a8 Z& G( x& { floodfill(293,286,YELLOW);7 a" Q- P( }9 ?
setfillstyle(8,3);* ^( \* L5 I* c) L6 \
circle(322,286,6);/ `8 S, H% T& S9 {3 T* m
floodfill(322,286,YELLOW);2 p p A2 P* V' P! `- |1 F
setfillstyle(8,4);
* s4 Q8 v: T1 S; _ {& d( } circle(333,286,6);7 a5 `- a. n8 a* G
floodfill(333,286,YELLOW);
: x' z' Q+ b' e getch();
3 K' P% F2 X- g2 K. C7 t/ x closegraph();
) ~" `3 r% I) Y}
5 G( ?3 a. A- P) B8 q2 r
+ ^9 F$ i6 h( Q# ~ c9 h$ e1 T# W! ?! `
|