这是我自己做的一个版本,望斑竹给予指点!!!谢谢
5 j a' @# j1 a' w! j* P
2 H7 i1 X( F& z! Q! s5 |" g1 a! g: r#include2 B; i% n# d; w* w$ |% ^) ~
#include7 x% y: S H) W6 Z) u4 o" C, R
#include: ]( ]: d$ a5 j% _; o! U
#include. F6 |) \0 [7 y% M$ C
#define running 1 /*用running 表示进程处于运行态*/
2 m3 T$ v6 U- J% C5 q' D% v#define aready 2 /*用aready表示进程处于就绪态*/
{! @" s9 V8 v9 ^, z5 p#define blocking 3 /*用blocking表示进程处于等待态*/2 b& e9 W* y2 i6 H
#define sometime 5 /*用sometime 表示时间片大小*/6 S6 T; \: d/ u+ w' `2 [" W5 _
#define n 10 /* 假定系统允许进程个数为10 */
+ |' w& j& O9 s; M0 }1 Xstruct+ A# j" N! Z0 _8 V& s* {
{
) f: f) }+ f) P0 k) l7 J4 c% O, j4 gint name; /*进程标识符*/4 B9 P* O" o- Z
int status; /*进程状态*/
, P9 Y9 i1 t& {: R* p5 s* G& F# o& yint ax, bx, cx,dx; /*进程现场信息,通用寄存器内容*/
- B# B/ y; T4 Y5 T0 Y- fint pc; /*进程现场信息,程序计数器内容*/3 R ?) s! D% Y( R* ^
int psw; /*进程现场信息,程序状态字寄存器内容*/: `9 X$ i ?1 B6 o( w( W5 X& r
int next; /*下一个进程控制块的位置*/- @/ u; }1 M& i
}pcbarea[n]; /*定义模拟进程控制块区域的数组*/7 F" n* B* z/ C, M5 U: l
int PSW,AX,BX,CX,DX,PC,TIME; /*模拟寄存器*/
( J. C7 l9 Q( q; s7 L* }9 D' _int run; /*定义指向正在运行进程的进程控制块的指针*/5 ~& c- o* |; X; X( p/ X' p
struct5 z/ D/ u7 n( i+ W' [
{$ ^% m4 t8 d: M q
int head;
1 g1 m, A# T Mint tail;: O7 q* r0 Z" q$ {! }' p
}ready; /*定义指向就绪队列的头指针head和尾指针tail*/0 U7 x' l* i8 H1 k0 b. J
int block; /*定义指向等待队列的指针*/0 ^2 v7 U4 K* R" q; ]# h$ g4 W& K
int pfree; /*定义指向空闲进程控制块队列的指针*/9 q0 h- Q" O" o1 q6 ^) _
main()% ^& o% P8 z0 O4 W$ q! b
{ int gdriver=DETECT,gmode;
l+ Q' }/ j' m8 X, l. B/ w8 R6 i int i,x,y;$ B2 p5 n" @: w" p' \, D0 f
for(i=1;i<=n;i++)( ]6 _9 ]5 c) t3 {8 A [
{ready.head=pcbarea.next;}
: l' i/ k# b- B c3 F3 ^( m initgraph(&gdriver,&gmode,"");
+ C7 G) l! ~2 n+ P' ? setcolor(YELLOW);2 l1 l! V$ X( I4 M' u' A
for(i=1;i<=4;i++)
" r3 J; m* y1 T! ?* ?) Q { setfillstyle(8,i);
+ W' w, H% x4 B- H( x1 j circle(284+13*i,190,6);
/ P3 g0 y! M+ I2 v- v1 q8 d: @/ m8 S floodfill(284+13*i,190,YELLOW);
! U9 l% s- X7 A }* p$ Y4 S2 d$ ?5 j) o
setlinestyle(0,0,3);" ]* |% W1 C" H% u4 S7 h
circle(316,190,25);
3 U. f( @, N4 k9 x! m setcolor(5);$ d- i7 [* R# c9 J( x- C% }& G
settextstyle(3,0,4);
) |' @, a1 J- E7 n outtextxy(35,311,"press any key to create objects!");
5 s; T1 Q C1 \, v8 A getch();
$ D" k6 G. H, s$ Q* P5 Q0 o; J# Q setcolor(YELLOW);
8 _( T+ g+ S: Q5 T line(300,215,290,235);# N! X1 ^# P* k4 J9 ~. F& ~
line(323,215,333,235);) s m% K& J! _$ p* |$ x
delay(50000);
1 ]% n% Y0 q" n4 u7 | setlinestyle(0,0,1);
/ r ]" O( m1 Q- ~9 ?. ]2 a for(x=1;x<=2;x++)
" F i( j7 p* f% S1 L! c {setfillstyle(8,x);
# W! c$ N( Y; H circle(267+13*x,246,6);) e, l6 y# n l8 K& N' r4 B
floodfill(267+13*x,246,YELLOW);. B4 d% G! a2 g X$ x o
}
0 C+ e/ Z: n2 N6 ~% { for(y=3;y<=4;y++)+ C2 P5 J9 @" v3 W2 _+ B
{setfillstyle(8,y);
- t& S; x8 U6 K9 N circle(285+13*y,246,6);7 r: _+ z/ b, C, J
floodfill(285+13*y,246,YELLOW);
0 u5 D+ H. j1 [/ S- ]9 i- a }
. a# P) @: v3 U4 ~" y& \( A7 @ setlinestyle(0,0,3);6 L( t$ a" }$ m6 a7 Y0 U
circle(287,246,14);
# h/ s( D) t r% M. i- P8 O ~ setlinestyle(0,0,3);% ^; i& `5 h, x8 a1 h5 `5 |$ m
circle(330,246,14);$ {" _ r' ]4 m P' B
delay(50000);( U' ?. O _+ x+ L2 G! f0 f1 z
line(281,260,281,280);; o9 h0 {" P7 J& L+ r- @! ]
line(293,260,293,280);
- W1 H+ q' v. F7 p line(322,260,322,280);
8 T" M# O3 n4 \( O1 }( H line(333,260,333,280);
7 {; H" B0 S4 W* U delay(50000);
7 k" [7 t! I& K, ~9 q setlinestyle(0,0,1);
* g( W' @6 ~* ? s setfillstyle(8,1);
# f2 Z5 a8 s) |# o circle(281,286,6);
& J( h0 t, g9 v _3 O- R+ o floodfill(281,286,YELLOW);
' N9 g, ?! e( t setfillstyle(8,2);' ^5 c( b5 w, m- N0 T
circle(293,286,6);# Y" M' e7 C. F5 [4 Z
floodfill(293,286,YELLOW);, { P# y4 o S" F4 h$ V( q
setfillstyle(8,3);
/ @8 P& ?9 }7 g7 U5 P0 F circle(322,286,6);; u9 g) G! U& k
floodfill(322,286,YELLOW);6 P0 X% E8 w: z+ u/ A- v5 P
setfillstyle(8,4); k! H7 _! x f
circle(333,286,6);. b; N) F7 {0 L) H1 p; }: O
floodfill(333,286,YELLOW);
! w4 ]! G9 Y: y) V' ^1 x2 s getch();
. E6 g# k# d O/ H closegraph();% ~( i$ n6 W# U& `. |
}
: T, ^6 |8 f, t- p6 ?$ s7 }( n/ F" t! }9 Z
7 m" z- [5 |9 v0 Y8 T
|