#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct link{
char name[100];
int memory;
struct link *next;
};
struct link2{
char name[100];
int memory;
struct link2 *next;
};
struct link3{
char name[100];
int memory;
struct link3 *next;
};
struct link *creat(struct link *head);
void menu(){
printf("1 代表创建新进程\n2 执行进程时间片到\n3 阻塞执行进 程\n4 唤醒第一个阻塞进程\n5 终止执行进程\n");
}
struct link *addtoone(struct link *head,struct link3 *head3);
struct link2 *addto2(struct link *head,struct link2 *head2);
void show(struct link *head);
void show2(struct link2 *head2);
void show3(struct link3 *head3);
struct link *two(struct link *head,struct link2 *head2);
struct link3 *three(struct link2 *head2,struct link3 *head3);
struct link *creat(struct link *head){
char name[100];
int memory;
struct link *p=NULL,*pr=head,*prr=head,*prrr=head;
printf("请输入您想要创建的进程的名称以及内存\n");
scanf("%s %d",&name,&memory);
p=(struct link*)malloc(sizeof(struct link));
strcpy(p->name,name);
p->memory=memory;
if(p==NULL){
printf("无法创建该进程\n");
return 0;
}
if(head==NULL){
head=p;
}
else{
while(pr->next!=NULL){
pr=pr->next;
}
pr->next=p;
}
p->next=NULL;
return head;
};
int main(){
int n,memory;
char name[100];
struct link *head=NULL;
struct link2 *head2=NULL;
struct link3 *head3=NULL;
menu();
struct link *p=NULL,*pr=head,*prr=head,*prrr=head;
struct link2 *pp=NULL,*pr2=head2,*prr2=head2;
while(scanf("%d",&n)!=EOF)
{
if(n==1){
head=creat(head);
prr=head;
int i=0;
while(prr!=NULL){
i=i+1;
printf("s1s1s1该进程的名字为%s,该进程的内存为%d\n",prr->name,prr->memory);
prr=prr->next;
}
//以上是建立进程进就绪队列,
//放到执行,
if(head2==NULL){
printf("执行链表仍然为空\n");
pp=(struct link2*)malloc(sizeof(struct link2));
pp->memory=head->memory;
strcpy(pp->name,head->name);
printf("执行列表为空\n");
head2=pp;
pp->next=NULL;
printf("1\n");
int j=0;
printf("2\n");
head=head->next;
prrr=head;
while(prrr!=NULL){
printf("最终的就绪列表为%s,%d",prrr->name,prrr->memory);
prrr=prrr->next;
}
}
pr2=head2;
while(pr2!=NULL){
printf("s2s2s2该程序的执行队列为名字为%s,所占内存大小为%d\n",pr2->name,pr2->memory);
pr2=pr2->next;
}
}
if(n==2){
//将执行队列的放回到就绪队列,再将就绪队列的第一个程序放到执行队列
head=two(head,head2);
head2=NULL;
head2=addto2(head,head2);
printf("执行\n");
show2(head2);
head=head->next;
printf("该就绪队列为\n");
show(head);
}
if(n==3){
//将执行放到阻塞,再将就绪放到执行,
if(head2==NULL){
printf("无执行程序\n");
}
else{
head3=three(head2,head3);
printf("就阻塞队列为\n");
show3(head3);
head2=NULL;
head2=addto2(head,head2);
printf("就执行队列为\n");
show2(head2);
head=head->next;
printf("就绪队列为\n");
show(head);
}
}
if(n==4){
//将阻塞队列的第一个放入到就绪队列
head=addtoone(head,head3);
printf("就绪队列为\n");
show(head);
head3=head3->next;
printf("阻塞队列为\n");
show3(head3);
printf("执行队列为\n");
show2(head2);
}
if(n==5){
return 0;
}
menu();
}
return 0;
}
struct link *two(struct link *head,struct link2 *head2){
struct link *p=NULL,*pr=head;
struct link2 *pr2=head2;
p=(struct link *)malloc(sizeof(struct link));
p->memory=head2->memory;
strcpy(p->name,head2->name);
if(p==NULL){
printf("无法创建该进程\n");
return 0;
}
if(head==NULL){
head=p;
}
else{
while(pr->next!=NULL){
pr=pr->next;
}
pr->next=p;
}
p->next=NULL;
return head;
};
void show(struct link *head){
while(head!=NULL){
printf("该就绪队列进程的名字为%s,内存为%d\n",head->name,head->memory);
head=head->next;
}
}
void show2(struct link2 *head2){
while(head2!=NULL){
printf("该执行队列进程的名字为%s,内存为%d\n",head2->name,head2->memory);
head2=head2->next;
}
}
void show3(struct link3 *head3){
while(head3!=NULL){
printf("该阻塞队列进程的名字为%s,内存为%d\n",head3->name,head3->memory);
head3=head3->next;
}
}
struct link2 *addto2(struct link *head,struct link2 *head2){
struct link2 *p=NULL, *pr=head2;
p=(struct link2 *)malloc(sizeof(struct link2));
p->memory=head->memory;
strcpy(p->name,head->name);
head2=p;
p->next=NULL;
return head2;
}
struct link3 *three(struct link2 *head2,struct link3 *head3){
struct link3 *ppp=NULL,*pr3=head3,*prr3=head3;
ppp=(struct link3 *)malloc(sizeof(struct link3));
ppp->memory=head2->memory;
strcpy(ppp->name,head2->name);
if(ppp==NULL){
printf("无法申请节点\n");
return 0;
}
if(head3==NULL){
head3=ppp;
}
else{
while(pr3->next!=NULL){
pr3=pr3->next;
}
pr3->next=ppp;
}
ppp->next=NULL;
return head3;
};
struct link *addtoone(struct link *head,struct link3 *head3){
struct link *p=NULL,*pr=head;
p=(struct link *)malloc(sizeof(struct link ));
p->memory=head3->memory;
strcpy(p->name,head3->name);
if(p==NULL){
printf("无法创建该进程\n");
return 0;
}
if(head==NULL){
head=p;
}
else{
while(pr->next!=NULL){
pr=pr->next;
}
pr->next=p;
}
p->next=NULL;
return head;
};