操作系统原理
实验报告
实验题目: 实验3:处理机调度 学号姓名:
同组成员:
实验要求
了解引起处理机调度的原因 分析先来先服务算法,给出代码注释
实验内容及步骤
进程调度算法的数据结构主要有:进程函数定义,建立进程函数,进程调度函数。
1.在源程序上写出注释。
#include \"stdio.h\" #include typedef struct node //声明结构体 { char name; //进程名称 int status; //进程状态 int precendence; //进程优先级 int ax,bx,cx,dx; int pc; int psw; struct node *next;//指向下一个进程 }pcb; 2 pcb *createprocess(pcb *head) //进程创建 { pcb *p,*q; int a,b,c,d,m,n,pre; char ID; //进程ID int s; q=NULL; printf(\"\\ninput the first seven status pcb:\"); scanf(\"\\n%c\//输入的第一个信息为进程ID scanf(\"%d%d%d%d%d%d\//输入进程其它信息 while(ID!='*') //当进程ID号为“*”时,终止 { p=(pcb*)malloc(sizeof(pcb)); //分配内存空间 p->name=ID; p->ax=a; p->bx=b; p->cx=c; p->dx=d; p->pc=m; p->psw=n; p->precendence=pre; //进程优先级 p->status=aready; //进程状态 if(head==NULL) //如果头结点为空,指向p head=p; else q->next=p; //否则将q的下一个结点指向p q=p; printf(\"\\ninput the next pcb: \"); scanf(\"\\n%c\ scanf(\"%d%d%d%d%d%d\ 3 } if(q!=NULL) q->next=NULL; q=head; while(q) { printf(\"\\n peocess name. status.ax. bx. cx. dx. pc. psw.\\n \"); printf(\"%10c%5d%8d%5d%5d%5d%5d%5d%5d\ q->bx,q->cx,q->dx,q->pc,q->psw); void processfifo(pcb *head) //进程运行 { pcb *p; //声明结构体 p=head; //p指向头指针 printf(\"\\n the process use fifo method.\\n\"); printf(\"running the frist process:\\n\"); while(p!=NULL) { p->status=running; printf(\"\\nprocess name status. ax. bx. cx. dx. pc. psw.\"); printf(\"\\n%10c%5d%8d%5d%5d%5d%5d%5d\ } } return head;/*createprocess end*/ q=q->next; >cx,p->dx,p->pc,p->psw); /*check process running status */ } p->status=0; p=p->next; 4 printf(\"\\ncheck weatherfer the process complete: \"); p=head; while(p) { printf(\"\\n%3c%3d\ p=p->next; } printf(\"\\ngame is over!\\n\"); } main() { pcb *head; head=NULL; head=createprocess(head); processfifo(head); } 2.画出程序流程图。 5 3.调试程序并写出运行结果。 教师评语 6 因篇幅问题不能全部显示,请点此查看更多更全内容