当前位置:首页 > 思想汇报 > [关于操作系统的实验报告]实验报告
 

[关于操作系统的实验报告]实验报告

发布时间:2019-06-21 09:12:51 影响了:
文章摘要:对于小编来说简直就是天书呀。为此小编精心整理了一篇关于操作系统的实验报告,希望可以帮助到你。一、程序流程图:二、使用的数据结构及说明:{int P_Id;//PCB的ID号 //PCB状态 //PCB的所需要的运……

什么操作系统,编程,代码,数据结构分析,对于小编来说简直就是天书呀。为此小编精心整理了一篇关于操作系统的实验报告,希望可以帮助到你。

一、程序流程图:

二、使用的数据结构及说明:

{

int p_id;

//pcb的id号 //pcb状态 //pcb的所需要的运行时间 //pcb所需要的资源要求

操作系统实验报告免费

char p_name[10]; char p_state[10]; int p_runtime; int p_requiry;

在本实验中,主要用到的数据结构是pcb的结构,其中pcb的数据结构如下: struct pcb //pcb的名称

struct pcb * next ; //pcb块的下一个指针

} ;

其中,p_id,和p_name用来标示一个进程,而p_state用来标示进程的五种状态:create_state,ready_state,block_state,run_state,exit_state。p_runtime标示要完成一个进程所需要的时间。p_requiry标示一个进程的执行所需要的其他条件,当其他的条件满足,则p_requiry置1,否则置0。struct pcb * next 用来指向同一队列中的下一个pcb块。

三、程序源代码:

#include"stdlib.h"

#include"stdio.h"

#include"出现恶意脚本h"

出现恶意脚本******* globle structure and viable ******/

struct pcb

{

int p_id;

//pcb的id号 //pcb的名称 //pcb状态 //pcb的所需要的运行时间 //pcb所需要的资源要求 //pcb块的下一个指针 //创建状态 //运行状态 char p_name[10]; char p_state[10]; int p_runtime; int p_requiry; } ; struct pcb * create_state; struct pcb * run_state; struct pcb * ready_state; struct pcb * block_state; struct pcb * exit_state; int signal4=0; int signal5=0;

{

struct pcb * p,*q;

node->next=null;

if(*head==null)

{

*head=node;

}

else

{

p=*head;

q=p->next;

while(q!=null)

{

p=q;

q=q->next; //找到最后的元素位置 //队列不空 //如果队列为空 struct pcb * next ; //就绪状态 //阻塞状态 //退出状态 //标示进程4的完成状态 //标示进程5的完成状态 void insertqueue(struct pcb **head,struct pcb *node) /* insert node function */

}

p->next=node;

}

}

void deletequeue(struct pcb **head,struct pcb *node) //撤销进程,从队列中删除元素 {

}

void display_process(struct pcb * node)

{

printf("\n\nthis process id is : %d \n",node->p_id);

printf("this process name is : %s \n",node->p_name);

printf("this process state is : on %s \n ",node->p_state);

printf("this process runtime is : %d \n",node->p_runtime);

if(node->p_requiry)

printf("this process resource is ready \n");

else

printf("this process resource is not ready ! \n");

}

void dispatchtoblock(struct pcb *node) // /* dispatch to block function*/

{

//调度到阻塞状态的函数 //struct pcb *p=(struct pcb *)malloc(sizeof(struct pcb)); if(!node->p_requiry)

{

strcpy(node->p_state,"block"); //如果所需要的资源没有满足则,调度到阻塞状态 //打印进程状态的元素函数 struct pcb *p,*q; q=*head; if(*head==null||node==null) return ; if(*head==node) { } else { while(q->next!=p&&q->next!=null) q=q->next; q=p->next; p->next=null; } //如果不是队列的首元素 return; //如果要删除的元素是队首元素 //如果队列为空,返回 //将节点插入队列 *head=(*head)->next;

insertqueue(&block_state,node);

}

display_process(node); } //插入到阻塞队列

void dispatchtoready(struct pcb *node) // dispatch to ready state {

//调度到就绪状态的函数 //如果所需的资源满足,则调度 if(node->p_requiry)

{

}

void dispatchblocktoready() //dispatch the process to readyqueue

{ //从阻塞状态调度到就绪状态函数 struct pcb*p,*q;

q=block_state;

while(q!=null)

{

p=q;

q=q->next;

if(signal4&&p->p_id==4)

}

}

void create_process()

{ //创建进程函数 { deletequeue(&block_state,p); strcpy(p->p_state,"ready"); printf("process4 will be in the state of ready!\n"); display_process(p); } { deletequeue(&block_state,p); strcpy(p->p_state,"ready"); printf("process5 will be in the state of ready!\n"); display_process(p); } //如果所需要的资源满足 //如果阻塞状态队列不空 strcpy(node->p_state,"ready"); display_process(node); insertqueue(&ready_state,node); } insertqueue(&ready_state,p); if(signal5&&p->p_id==5) insertqueue(&ready_state,p);

int i;

struct pcb *p;

char name[10];

strcpy(name,"process");

for(i=1;i<3;i )

{

p=(struct pcb *)malloc(sizeof(struct pcb));

p->p_id=i;

name[7]=i ‘0‘;

name[8]=‘\0‘;

strcpy(p->p_name,name);

strcpy(p->p_state,"create");

p->p_runtime=1;

p->p_requiry=0;

display_process(p);

sleep(4);

printf(" \n process%d will be in the state of block, waiting the resource ready \n\n",i); dispatchtoblock(p);

}

for(i=3;i<7;i )

{

p=(struct pcb *)malloc(sizeof(struct pcb));

p->p_id=i;

name[7]=i ‘0‘;

name[8]=‘\0‘;

strcpy(p->p_name,name);

strcpy(p->p_state,"create");

p->p_requiry=1;

if(i==6)

else

p->p_runtime=1;

display_process(p);

sleep(4);

printf(" \n process%d will be in the state of ready, waiting to run \n\n",i);

dispatchtoready(p);

}

}

void display(struct pcb **head) //打印各个状态队列里进程数目 //在这里个进程6所需要的时间片为2 p->p_runtime=2; //创建4个就绪状态的队列 //同时调度到阻塞队列 //所需要的时间片为1 //动态创建2个处于阻塞状态的进程

{

struct pcb *p,*q;

p=*head;

while(p!=null)

{

sleep(2);

//printf("\n\n///////////////////////////////////\n");

printf("\n\nthis process id is : %d \n",p->p_id);

printf("this process name is : %s \n",p->p_name);

printf("this process state is : on %s \n ",p->p_state);

printf("this process runtime is : %d \n",p->p_runtime);

if(p->p_requiry)

printf("this process resource is ready \n");

else

printf("this process resource is not ready ! \n");

p=p->next;

}

}

void process_run()

{

struct pcb *p,*q;

p=ready_state;

q=p;

while(p!=null)

{

if(p->p_runtime<=0) break;

strcpy(p->p_state,"running");

display_process(p);

p->p_runtime=p->p_runtime-1;

sleep(4);

if(p->p_runtime>0)

{

printf("this process is not finished,will be dispatch to the ready queue!!\n"); deletequeue(&ready_state,p);

strcpy(p->p_state,"ready");

insertqueue(&ready_state,p);

display_process(p);

}

else

{

printf("\n\nprocess%d is finished and will be in the state of exit!\n\n",p->p_id); if(p->p_id==4) signal4=1; //执行完成,则跳出,并发送相应的信息 //没有完成,则进入就绪队列 //如果时间片执行完了,则跳出循环 //就绪队列不空则继续执行 //进程运行函数

if(p->p_id==5) signal5=1;

}

//如果资源满足,则将进程调度到就绪队列 if(signal4||signal5) dispatchblocktoready();

q=q->next; p=q;

}

if(q==null)

printf("\nthere is no process ready!\n stop machine!!!\n");

}

int main(int argc,char * argv[])

{

int i;

char c=‘c‘; //界面

printf("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n");

printf("...................................ding hai bo\n");

printf("......press s to start the process.......\n");

scanf("%c",&c);

while(1)

{

if(c==‘s‘)break;

scanf("%c",&c);

}

create_process(); //调用创建进程函数

printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");

printf("\n>>>>>>> display the ready queue >>>>>>>>>>>>>>>\n");

sleep(5);

display(&ready_state); ////////////////显示就绪队列里的进程

printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");

printf("\n>>>>>>>> display the block queue >>>>>>>>>>>>\n");

sleep(5); //显示阻塞队列函数

display(&block_state); /////////////////////

printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\n");

printf("\n>>>>>>>> now the process start to run >>>>>>>>>>>\n");

sleep(5);

process_run();

} //调用进程运行函数 //主函数

四、运行结果及说明:

运行结果的截图:

下面的运行结果是程序执行的每一步进程调度的显示,从进程的创建到进程的执行,结束,每一步进程调度都有显示。

操作系统实验报告免费

操作系统实验报告免费

操作系统实验报告免费

五.程序使用说明:

1)输入字符’s’启动程序 2)程序将自动执行,自动创建进程,运行进程和结束进程。 3)程序将自动显示每一步进程的执行状态。

操作系统实验报告免费

猜你想看
相关文章

Copyright © 2008 - 2022 版权所有 职场范文网

工业和信息化部 备案号:沪ICP备18009755号-3