資源簡介
進(jìn)程管理 執(zhí)行 喚醒 阻塞 結(jié)束
代碼片段和文件信息
#include
#include
void?Instruction();
typedef?struct?node
{
int?data;
struct?node?*next;
}linklist;
linklist?*head;
typedef?struct?node1
{
int?data;
struct?node1?*next;
}dlinklist;
dlinklist?*head1;
int?j?=?0;
void?CreatePCB()//創(chuàng)建PCB
{
linklist?*r;
r?=?head;
while(r->next?!=?NULL)
r?=?r->next;
if(r->next?==?NULL&&?j?!=?11)
{
int?x;
linklist?*p;
printf(“請輸入進(jìn)程名\n“);
scanf(“%d“&x);
p?=?(linklist*)malloc(sizeof(linklist));
p->data?=?x;
r->next?=?p;
r?=?p;
printf(“%d“p->data);
printf(“創(chuàng)建成功\n“);
j++;
}
????if(j?==?11)?
{
r->next?=?NULL;
printf(“進(jìn)程已滿\n“);
getchar();
Instruction();
}
????else?if(head->next?!=?NULL)//head->next作為執(zhí)行態(tài)
{
printf(“%d“head->next->data);
printf(“處于執(zhí)行態(tài)\n“);
r->next?=?NULL;
getchar();
Instruction();
}
}
void?Block()
{
dlinklist?*t*r;
linklist?*q;
r?=?head1;
while(r->next!=NULL)
{
r=r->next;
}
if(head->next?!=?NULL)//有執(zhí)行態(tài)就將執(zhí)行態(tài)阻塞
{
t=(dlinklist*)malloc(sizeof(dlinklist));
t->data?=?head->next->data;
r->next?=?t;
r?=?t;
printf(“%d“t->data);
printf(“已處于阻塞態(tài)\n“);
q?=?head->next;
head->next?=?head->next->next;
free(q);
j--;
if(head->next?!=?NULL)
{
printf(“%d“head->next->data);
printf(“處于執(zhí)行態(tài)\n“);
}
else
printf(“進(jìn)程為空\n“);
}
else
{
printf(“錯(cuò)誤操作\n“);
}
r->next?=?NULL;
getchar();
Instruction();
}
void?Wakeup()
{
int?x;
dlinklist?*t*s*m*w;
linklist?*p*q;
t?=?head1;
s?=?head1;
p?=?head;
if(head1->next?==?NULL)?printf(“沒有可喚醒的進(jìn)程\n“);
else
{
printf(“請選擇喚醒進(jìn)程\n“);
while(t->next?!=?NULL)//輸出阻塞態(tài)
{
printf(“%d????“t->next->data);
t?=?t->next;
}
t?=?head1;
scanf(“%d“&x);
while(t->next?!=?NULL)
{
if(x?==?t->next->data)
{
while(p->next?!=?NULL)//找到鏈表PCB的尾
p?=?p->next;
q?=?(linklist*)malloc(sizeof(linklist));
q->data?=t->next->data;
p->next?=?q;
p?=?q;
p->next=NULL;
printf(“%d“x);
printf(“喚醒成功\n“);
printf(“%d“head->next->data);
printf(“正在執(zhí)行\(zhòng)n“);
j++;
w?=?t->next;//刪除多余項(xiàng)
m?=?head1;
while(m?!=?t)
m?=?m->next;
m->next?=?m->next->next;
free(w);
break;
}
els
評論
共有 條評論