pcbArea[temp].=temp+1; }pcbArea[temp].=-1; pfree=0; }
//就绪队列出队
int PopReady 〃返回结点在PCB区域数组的编号 {
第 3 页 共 7 页
int temp;
if(ready.head==-1) {
printf(“就绪队列为空,不能出队。\\n”); return -1; }
temp=ready.head;
ready.head=pcbArea[temp].; if(ready.head==-1) ready.tail=-1; pcbArea[temp].=-1; return temp; }
〃空闲队列出队
int PopFree 〃返回结点在PCB区域数组的编号 {
int temp; if(pfree==-1) {
printf(“空闲队列为空,不能出队。\\n”); return -1; }
temp=pfree;
pfree=pcbArea[temp].; pcbArea[temp].=-1; return temp; //就绪队列入队 void PushReady(int ) {
int temp;
第 4 页 共 7 页 //为入队结点的编号
if(ready.head==-1) {
ready.head=; ready.tail=; } else {
temp=ready.tail; ready.tail=; }
pcbArea[ready.tail].=-1; }
〃创建PCB
void CreatePCB(int ,PCB pcb) {
pcbArea[].a=pcb.a; pcbArea[].b=pcb.b; pcbArea[].c=pcb.c; pcbArea[].d=pcb.d; pcbArea[].name=pcb .n ame; pcbArea[].=-1; pcbArea[].pc=pcb.pc; pcbArea[].psw=pcb.psw; pcbArea[].status=pcb.status; }
//创建进程函数 void Create(PCB pcb) {
第 5 页 共 7 页
//为要创建PCB在PCB区域数组的编号
int temp; if(pfree==-1) {
printf(“空闲队列为空,不能创建进程。\\n”); return; }
temp=PopFree; pcb.status=Aready; CreatePCB(temp,pcb); PushReady(temp); //进程调度函数 void Schedule。 {
int temp;
if(ready.head==-1) {
printf(“系统内没有进程可以调度。”); return;
} temp=PopReady();
pcbArea[temp].status=R unning; TIME=SLOT;
//恢复 现场
A=pcbArea[temp].a; B=pcbArea[temp].b; C=pcbArea[temp].c; D=pcbArea[temp].d; PC=pcbArea[temp].pc; PSW=pcbArea[temp].psw; run=temp;
//将选中的进程赋给运行指针
第 6 页 共 7 页
printf(“当前运行的程序:\\n”); //输出调度结果
printf(“进程号:d\\n”,pcbArea[run].name); printf(“进程状态:d\\n”,pcbArea[ru n].status); printf(“寄存器内容:\\nA\B\C\D\PC\PSW\\n”); prin tf(“d\d\d\d\d\d\\n”,
pcbArea[ru n].a,pcbArea[ru n].b,pcbArea[ru n].c,pcbArea[ru n].d,pcbArea[ru n].pc,pcbArea[ru n ].psw);
} void mai n {
int temp; PCB tmppcb;
printf(“请输入进程号,以负数为结束(进程号应保持唯一)。\\n\\n按任意键进入输入模式: ”);
getchar; In itRu n; In itReady; In itFree;
\\n“);printf(”请开始输入进程号: while(1) \\n“); {
scan f(”d“, temp); if(tempvO)
break; tmppcb.name=temp; tmppcb.a=temp; tmppcb.b=temp; tmppcb.c=temp; tmppcb.d=temp; tmppcb.pc=temp; tmppcb.psw=temp;
Create(tmppcb); } prin tf(”\\nt;); Schedule; }
第 7 页 共 7 页