这是我自己做的一个版本,望斑竹给予指点!!!谢谢" E1 B2 {+ n6 W) @5 A
$ j% v0 B2 ~: Z0 t#include1 q3 C4 D+ h& U+ R% h N# G! [
#include9 @) s, C+ ^ L& r' c$ c
#include! A* @; s( [0 K1 o
#include- M( _& J- E9 [
#define running 1 /*用running 表示进程处于运行态*/. R9 d* G9 D' m* t; k( M( r
#define aready 2 /*用aready表示进程处于就绪态*/
/ V& i1 ^* l/ p0 |0 r9 Y#define blocking 3 /*用blocking表示进程处于等待态*/
! c3 i& j& J) W7 L1 d#define sometime 5 /*用sometime 表示时间片大小*// h% s8 W8 G5 n# ~1 A
#define n 10 /* 假定系统允许进程个数为10 */9 w( C% n) ]+ F i" @
struct
' L! }) }# G Y k( _' \: m{2 o5 F' V1 w5 i5 G1 o! c
int name; /*进程标识符*/
% f8 G3 q( A! h0 m$ r$ oint status; /*进程状态*/
' D! x6 Q7 _- v1 h0 U, c1 U7 Jint ax, bx, cx,dx; /*进程现场信息,通用寄存器内容*/
# ?' C" Z2 s( xint pc; /*进程现场信息,程序计数器内容*/
0 j! v* @6 ~( R6 y6 l% yint psw; /*进程现场信息,程序状态字寄存器内容*/
7 Q! D7 }# H9 f: [3 h/ cint next; /*下一个进程控制块的位置*/( b8 A3 V5 E) K- M! j$ f
}pcbarea[n]; /*定义模拟进程控制块区域的数组*/+ m, Q- L$ P" O6 O" i
int PSW,AX,BX,CX,DX,PC,TIME; /*模拟寄存器*/
) [0 ^1 x0 W4 T( z. @; y4 cint run; /*定义指向正在运行进程的进程控制块的指针*/
) ?( m, t7 I7 {struct" ~/ A; b" g- S( d4 x$ G! [
{
+ m/ X/ ~# s6 f/ |int head;9 F |- t/ S+ t5 ~
int tail;' e- L8 Z j, e" U" @. @% _" m
}ready; /*定义指向就绪队列的头指针head和尾指针tail*// Y6 Y2 r* G2 J& r1 T9 M0 a
int block; /*定义指向等待队列的指针*/4 H4 d7 j6 v% K6 `0 Y! `* _& Q
int pfree; /*定义指向空闲进程控制块队列的指针*/1 g6 B+ j: @6 f" ~5 z
main()
5 M* u8 x# h, g% [8 E6 |{ int gdriver=DETECT,gmode;
+ Q5 I2 b d8 J6 |, e5 b$ m" X int i,x,y;) d6 `+ T" M4 u# B1 J1 I9 c7 {
for(i=1;i<=n;i++)
9 Z. u9 Z# C8 {- g) V( s {ready.head=pcbarea.next;}
$ q5 j8 R' `3 d3 D initgraph(&gdriver,&gmode,"");4 E$ {' c1 c; ?8 |, A5 ?6 C0 k) n6 q, m
setcolor(YELLOW);; y2 @) B7 Q# g2 N( M0 b
for(i=1;i<=4;i++)0 K- }/ n$ P0 Z8 T) w" v
{ setfillstyle(8,i);
% P5 Z8 B1 U% K1 p circle(284+13*i,190,6);4 w- ^; ^: N }) [' h* }! ~
floodfill(284+13*i,190,YELLOW);" L3 p1 M! ~6 {
}7 T) p) ?8 ~( z( J9 e4 l6 Q
setlinestyle(0,0,3);
/ u1 S' g7 E7 Y: } circle(316,190,25);
, {& H) a% @' A$ ?/ V( P& X setcolor(5);& A- P3 S8 I' U& {
settextstyle(3,0,4);" q; m5 b; u7 F: y8 ]* r' Z
outtextxy(35,311,"press any key to create objects!");9 T6 P+ p3 ^6 X2 a9 D! s
getch();
: h; d$ r- n, e2 G4 o/ [ setcolor(YELLOW);! |! d) w/ v/ P" w" X
line(300,215,290,235);+ O3 o0 J5 `' O* g8 |
line(323,215,333,235);( ?' U0 n& e: Y7 f- ~
delay(50000);
+ L; K9 |4 T/ |0 q; @) g( C setlinestyle(0,0,1);
1 {7 _, w& C4 C" @ for(x=1;x<=2;x++)
6 n2 {3 W$ ^# M+ j {setfillstyle(8,x);
& i: L+ z7 W8 `. W circle(267+13*x,246,6);
' Y+ N& B% O$ D6 n. Z" @ floodfill(267+13*x,246,YELLOW);
4 o+ o9 D6 i$ i- v5 |+ i y1 n. t9 D }9 d- z, {1 \0 |! a( c" ?3 E8 I
for(y=3;y<=4;y++)
8 G+ y' i( E8 [ @# B: h {setfillstyle(8,y);
% a, S4 X P: q3 T9 m* q circle(285+13*y,246,6);
5 n$ Q! J3 r9 y; R9 j, }1 b floodfill(285+13*y,246,YELLOW);* j& T! o$ F6 g
}
5 q5 p& f) i0 Y& Y setlinestyle(0,0,3);
9 e% Q4 t; h% v d w circle(287,246,14);8 Z7 @5 z6 ?8 s$ f/ B& M
setlinestyle(0,0,3);
+ L T5 k& Z' } circle(330,246,14);
( d, _7 y5 M1 j7 M delay(50000);
5 k/ T+ a6 b8 [" ~5 P' c8 q line(281,260,281,280);) s: N0 X! K) r$ J2 \+ w5 n
line(293,260,293,280);" p9 d4 O$ U5 j" x s# i) p
line(322,260,322,280);
/ Z* W4 O, L8 M& y2 W( W) Q* H3 {# ~1 ` line(333,260,333,280);
* {# V0 C: Y: g# Z+ ]5 Z delay(50000);
2 \7 {2 ^( R/ d u" |9 m setlinestyle(0,0,1);
8 _$ V% B0 f8 f7 F$ S. X setfillstyle(8,1);+ V+ j e$ y% I; C
circle(281,286,6);
& {3 p5 Y8 c8 k+ C% W7 g/ O# V0 w floodfill(281,286,YELLOW);
5 V# G8 q) a5 _. n# g setfillstyle(8,2);' W* v1 Y+ X: u3 C" O
circle(293,286,6);, J& u7 f4 V4 h1 `- M3 a8 F
floodfill(293,286,YELLOW);
o; t- I) H3 Z& J7 H+ Q setfillstyle(8,3);7 [; i6 g! |4 V4 ]5 ]7 L/ m" @3 e
circle(322,286,6);9 N+ I; ]7 `$ I! K+ |+ Z
floodfill(322,286,YELLOW);
% e3 m8 v9 w1 ]' \! X+ L setfillstyle(8,4);5 Y3 {+ n5 X* n1 D) ], L
circle(333,286,6);% m5 ?, w$ W. }! Y! f! q8 y
floodfill(333,286,YELLOW);
: f7 q& g5 A) f- [' @! ~6 E getch();& F+ L/ M; G' Z) z$ l* t" S' ?$ L
closegraph();5 J4 W1 w5 c: H* G# {, T8 {
}
4 E$ C2 T$ e/ s7 p4 N/ m+ F! y
* C2 E: _! T( i# Z; r
. f6 X( l0 k; r! m! v6 [ |