这是我自己做的一个版本,望斑竹给予指点!!!谢谢
( g( {3 W5 A; _; F% D' n+ ^8 ?" ]0 F8 N- I- g- i
#include& V/ K; l R* K `
#include; t: B/ T) b) V" c, T! n! a
#include6 y; D% |9 S) G) K4 M( B
#include
Y4 O- S6 a8 W2 y. p8 M3 G#define running 1 /*用running 表示进程处于运行态*/
& g$ a- S6 ]3 r3 D5 b( T#define aready 2 /*用aready表示进程处于就绪态*/
2 |0 ]" H4 m9 X/ Z( J* y4 j; D#define blocking 3 /*用blocking表示进程处于等待态*/
. u. a+ Z0 E, u/ M7 M. ]#define sometime 5 /*用sometime 表示时间片大小*/3 _4 `9 P0 L: g8 ^3 k. r: `# `8 \/ n
#define n 10 /* 假定系统允许进程个数为10 */3 G1 C4 u. P9 K' I0 n0 P2 a( `) d `5 K
struct0 o9 v5 Y) f* J$ v: a+ [, t) K
{
" _2 I7 |$ {; {2 c3 ]2 ?int name; /*进程标识符*/- r) [+ U4 _9 v- n
int status; /*进程状态*/, V7 g& [9 M1 b7 Z. J
int ax, bx, cx,dx; /*进程现场信息,通用寄存器内容*/
* v) e6 c1 i; k& v5 |% Y* A- F) ]int pc; /*进程现场信息,程序计数器内容*/# _4 E8 w( v% h
int psw; /*进程现场信息,程序状态字寄存器内容*/" x: P* a3 ~! S9 w% Z2 @
int next; /*下一个进程控制块的位置*/
6 X1 E" c5 ^! h4 Q0 i2 I+ G}pcbarea[n]; /*定义模拟进程控制块区域的数组*/
[- i' X" H' t: e# h9 Wint PSW,AX,BX,CX,DX,PC,TIME; /*模拟寄存器*/
4 M+ U( x1 c6 W, fint run; /*定义指向正在运行进程的进程控制块的指针*/
/ X' r2 [, r# M# L& j5 wstruct
# a/ X4 f$ R7 v3 f5 s5 y( D{
+ I( _3 j8 T. B7 K$ }* D) Zint head;- |# M( a6 y3 O/ ~+ h Z
int tail;! y' s! [ R3 e" e0 N2 v
}ready; /*定义指向就绪队列的头指针head和尾指针tail*/
) h1 m8 k! q$ n, S. z) gint block; /*定义指向等待队列的指针*/. m9 t4 q4 o0 N$ H+ `' \
int pfree; /*定义指向空闲进程控制块队列的指针*/
# w) w# _* b: J# h7 I, \$ zmain()
+ ]! C/ N4 E! f" Y1 X6 {- {{ int gdriver=DETECT,gmode;! v- V& P, e8 E- J: a
int i,x,y;; N4 }; O$ |7 l Y9 I
for(i=1;i<=n;i++)0 a' _% ^/ J) I
{ready.head=pcbarea.next;}& t/ F1 d! v3 D. z% l: f
initgraph(&gdriver,&gmode,"");- G& C" D/ o9 q, `* f
setcolor(YELLOW);
: I* C- c3 ^- m' _+ } for(i=1;i<=4;i++)" c1 ]5 |! [5 g& R6 x: r. \
{ setfillstyle(8,i);& t8 v6 ?4 |; v- ?2 p! _
circle(284+13*i,190,6);0 K0 n8 |( E$ p3 v5 `( p
floodfill(284+13*i,190,YELLOW); k L* l+ `3 F. A- s* N! [5 x2 @9 f
}
; r! T {: ~( k {8 |8 j setlinestyle(0,0,3);
D4 @, D4 @, v4 \ circle(316,190,25);
! g; y3 A; G* v( T0 y setcolor(5);* U* J8 Q J4 S# T
settextstyle(3,0,4);
/ K- f9 o$ Q4 C5 J* \ outtextxy(35,311,"press any key to create objects!");
4 _: `2 `* u- e$ S getch();$ `2 O! b+ ]0 h! e' q6 W
setcolor(YELLOW);
- g4 z* J" y( B2 w$ a line(300,215,290,235);* v9 o, Z0 ^( \) i
line(323,215,333,235);% \& w ~7 N! l" T
delay(50000);% r5 t1 p8 n/ r% c
setlinestyle(0,0,1);
! K3 K A D& f+ ^4 |7 R1 B" l for(x=1;x<=2;x++)
$ `' A& X/ [4 ?9 W$ E# \! N2 F {setfillstyle(8,x);
* v W; i8 D0 ?4 Z circle(267+13*x,246,6);
* `6 P7 `' K4 e5 N% D& u floodfill(267+13*x,246,YELLOW);
/ D5 O; |; N0 m o, N }
; a' N( @, Q$ d3 w for(y=3;y<=4;y++)+ ]3 @8 O; a7 H8 m7 N+ O
{setfillstyle(8,y);
. ?4 V. Y# |7 i f circle(285+13*y,246,6);% @% r Z, ~) g) }7 D3 @
floodfill(285+13*y,246,YELLOW);5 z {, E+ |3 _! I( _) q
}
9 |: o0 @, n5 u, L2 ] setlinestyle(0,0,3); F* _/ S# l* S+ Z5 j
circle(287,246,14);+ X0 C. |0 j/ g! B( R3 c
setlinestyle(0,0,3);
0 E2 M5 t* G9 K0 w! C: x& ?' F, t circle(330,246,14);6 X6 h' E3 G, ~! q5 Y1 ]6 \
delay(50000);* |( t4 o% K; i+ z
line(281,260,281,280);1 }9 n5 H! Q9 Q; [
line(293,260,293,280);
5 h* ~1 `- U( S! N# t# y line(322,260,322,280);
1 C" g# W' v) W o( W; B3 s line(333,260,333,280);
2 ]7 w6 F) A* G9 } delay(50000);/ t8 f' [. ]: U% \* g3 B0 K
setlinestyle(0,0,1);
8 {3 R2 _, z7 v$ O9 t5 q setfillstyle(8,1);
0 @/ [) F8 k! `3 W. O circle(281,286,6);* W" T% V3 ?0 F9 h4 j. B: x% n
floodfill(281,286,YELLOW);
; Z- Z3 L0 j, Q$ F setfillstyle(8,2);0 G- O C4 S( H* \+ w' q
circle(293,286,6);
1 U( e4 Z; ~; f floodfill(293,286,YELLOW);
+ T/ e- b" a- R3 M+ l! D# r* J setfillstyle(8,3);* M9 P6 q7 g) ^9 J+ V, Q5 v
circle(322,286,6);/ ~) d+ z7 m3 K1 c
floodfill(322,286,YELLOW);
) [, G" K5 F7 s& ~. `3 r! ?% J p; W5 n* S setfillstyle(8,4);
* L7 N$ @6 b% H. X circle(333,286,6);- N) V9 W& b! Y$ Y* F
floodfill(333,286,YELLOW);
6 S9 T" p% E/ [0 C: n* g6 \ getch();' h* e! L8 J& k5 `+ ^% h& `: d
closegraph();8 \3 I& Y& p- d
}! g( q- {1 T$ p) h! X2 e
6 K( z! D) A# C9 T
0 Y& }4 B+ X! L% A1 m |