ImageVerifierCode 换一换
格式:DOCX , 页数:45 ,大小:541.39KB ,
资源ID:20148273      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/20148273.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(操作系统实验报告.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

操作系统实验报告.docx

1、操作系统实验报告(此文档为word格式,下载后您可任意编辑修改!)计算机操作系统实验报告学 号:姓 名:提交日期:成 绩: 实验二 进程的创建和控制 实验目的:(1)加深对进程概念的理解,明确进程和程序的区别。(2)进一步认识并发执行的实质。(3)加深对进程管理概念的理解。(4)分析进程的创建过程。 实验内容:(1) 进程的创建# includestdio. ( )int p1,p2;while (pl = fork ( ) = = -1 ); * 创建子进程p1 *if (pl=0) * 子进程创建成功 * putchar (b);elsewhile (p2 = fork ( ) = = -

2、1); * 创建另一个子进程 *if ( p2 = = 0) * 子进程创建成功 *putchar (c);else putchar(a); * 父进程执行 *(2 ) 进程的控制# includestdio ( )int pl,p2,i;while (p1 = fork( ) ) = = -1);if (p1 = =0) for ( i0 ; i500;i+) printf ( child dn”,i);elsewhile (p2 = fork ( ) ) = = -1);if (p2 = =0) for (i = 0 ; i500 ; i+) printf ( “sondn” ,i )el

3、sefor (i0,i500; i+)printf (daughterdn”,i );# includestdio( )int p1,p2,i; while (pl = fork ( ) ) = = -1);if (pl = = 0)lockf(1,1,0),for(i = 0 ; i500 ; i+) printf (“child %dn”,i );lockf(1,0,0);elsewhile (p2 =fork ( ) = = -1);if (p2 = =0)lockf(1,1,0);for(i = 0; i500; i+) printf(“son %dn”,i );lockf(1,0,0

4、);elselockf(1,1,0);for(i = 0; i500; i+) printf(“daughter %dn”,i );lockf(1,0,0); 实验三 实现进程的软中断通信实验目的:1 掌握基本的软中断通信方法。2 利用系统调用signal( ) 捕捉中断信号。3 理解Linux系统中的进程通信的基本原理。实验内容:# include0)while (p2 = fork() = = -1);if (p20)wait_mark = 1;signal ( SIGINT,stop); * 接收Del信号,并转stop*waiting (0);kill (p1,16); *向p1发中断

5、信号16*kill (p2,17); * 向p2发中断信号17*wait (0); *同步*wait (0);printf(“parent process is killed! n”)exit(0);elsewait_mark = 1;signal(SIGINT,SIG_IGN);*signal (17,stop);printf(“%d”,SIG_DFL);waiting ( );lockf ( stdout,1,0);printf (“child process 2 is killed by parent! n”);lockf (stdout,0,0);exit (0); elsewait_

6、 mark = l;signal(SIGINT,SIG_IGN);*signal (16,stop);printf(%d”,SIG_DEL);waiting ( );lockf (stdout,1,0);printf (child process 1 is killed by parent!n”);1ockf ( stdout,0,0);exit (0); void waiting ( )while (wait_mark !=0);void stop ( ) wait_mark = 0;# include unistd”);exit (0);void Int2 ( )printf(“child

7、 process 2 is killed ! by parentn”);exit (0 );main ( )int exitpid;signal (SIGINT,SIG_IGN);signal(SIGQUIT,SIG_IGN);while (pid1fork ( ) -1 );if (pid0)signal ( SIGUSRl,Intl );signal (SIGINT,SIG_IGN);pause( );exit(0);elsewhile (pid = fork ( ) = -1);if(pid2 = 0 )signal(SIGUSRl,Intl);signal(SIGINT,SIG_IGN

8、);pause ( );exit(0);elsesignal (SIGINT,IntDelete);waitpid ( -1,&exitcode,0);printf(“parent process is killed n”);exit (0); 实验四 进程的管道通信实验目的:1 了解系统调用pipe( )的功能。2 掌握进程的管道通信的实现。3. 进一步理解进程通信的基本原理实验内容:# includeunistd ( )int fd2;char OutPipel00,InPipel00; pipe(fd);while (pidl = fork ( ) = = -1);if (pidl =

9、=0)lockf ( fd1,1,0);sprintf (OutPipe,“child 1 process is sending message!”);write (fd1,OutPipe,50);sleep (5);lockf (fd 1,0,0);exit(0);elsewhile (pid2 = fork ( ) = = -1);if (pid2 = =0)1ockf (fd1,1,0);sprintf (OutPipe,“child 2 process is sending message!“);write (fd1,OutPipe,50);sleep (5);lockf (fdl,0

10、,0);exit(0);elsewait (0);read (fd0 ,InPipe,50);printf(“sn”,InPipe);wait(0);read(fd0,InPipe,50);printf(“%sn”,InPipe);exit(0);实验五 使用动态优先权的进程调度算法模拟一、实验目的 通过动态优先权算法的模拟加深对进程概念进程调度过程的理解。二、实验内容(1)用C语言来实现对N个进程采用动态优先权优先算法的进程调度。(2)每个用来标识进程的进程控制块PCB用结构来描述,包括以下字段:1,进程标识数 ID。2,进程优先数 PRIORITY,并规定优先数越大的进程,其优先权越高。3

11、,进程已占用的CPU时间CPUTIME。4,进程还需占用的CPU时间ALLTIME。当进程运行完毕时,ALLTIME变为0。5,进程的阻塞时间STARTBLOCK,表示当进程再运行STARTBLOCK个时间片后,将进入阻塞状态。6,进程被阻塞的时间BLOCKTIME,表示已足赛的进程再等待BLOCKTIME个时间片后,将转换成就绪状态。7,进程状态START。8,队列指针NEXT,用来将PCB排成队列。(3)优先数改变的原则:1,进程在就绪队列中呆一个时间片,优先数加1。2,进程每运行一个时间片,优先数减3。(4)假设在调度前,系统中有5个进程,它们的初始状态如下:ID01234PRIORIT

12、Y93830290CPUTIME00000ALLTIME33634STARTBLOCK2-1-1-1-1BLOCKTIME30000STATEREADYREADYREADYREADYREADY(3) 为了清楚的观察各进程的调度过程,程序应将每个时间片内的情况显示出来,参照的具体格式如下:RUNNING PROG:iREADY-QUEUE:-id1-id2BLOCK-QUEUE:-id3-id4= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =ID 0 1 2 3 4PRIOR

13、ITY P0 P1 P2 P3 P4CUPTIME C0 C1 C2 C3 C4ALLTIME A0 A1 A2 A3 A4STARTBLOCK T0 T1 T2 T3 T4BLOCKTIME B0 B1 B2 B3 B4STATE S0 S1 S2 S3 S4三,实验步骤:#include stdio.(int time);enum STATEReady,Run,Block,RunOut;struct PROCESSint ID;int Priority;int Cputime;int Alltime;int Startblock;int Blocktime;enum STATE State

14、;ProcessN;int READYN;int BLOCKN;int RUNOUTN2;int main()int Time=0;init();printf(Time:%dn,Time);sort();print();while(1) Time+;getchar(); printf(Time:%dn,Time);if(run(Time)break; sort(); print(Time);return 0;void init()int i; printf(Input properties of %d process(PRIORITY,ALLTIME,STARTBLOCK,BLOCKTIME)

15、:n, N);for(i=0;i=0)printf(tRUNNING PROG: %dn,getRunning();printf(tREADY_QUEUE:);for(i=0;i=0)printf(-%d,ProcessREADYi.ID);elsebreak; printf(ntBLOCK_QUEUE:);for(i=0;i=0)printf(-%d,ProcessBLOCKi.ID);elsebreak;printf(n=n);printf(IDt);for(i=0;iN;+i)printf(t%d,Processi.ID);printf(nPRIORITY);for(i=0;iN;+i)

16、printf(t%d,Processi.Priority);printf(nCPUTIMEt);for(i=0;iN;+i)printf(t%d,Processi.Cputime);printf(nALLTIMEt);for(i=0;iN;+i)printf(t%d,Processi.Alltime);printf(nSTARTBLOCK);for(i=0;iN;+i)printf(t%d,Processi.Startblock);printf(nBLOCKTIME);for(i=0;iN;+i)printf(t%d,Processi.Blocktime);printf(nSTATEt);fo

17、r(i=0;iN;+i)switch(Processi.State)case 0:printf(tReady);break;case 1:printf(tRun); if(Processi.Alltime=0)Processi.State=RunOut;else Processi.State=Ready; break;case 2:printf(tBlock);break;case 3:printf(tRunOut);break;printf(n);printf(tRUNOUT LIST:);for(i=0;i=0)printf(-%d(%d),ProcessRUNOUTi0.ID,RUNOU

18、Ti1);elseprintf(n);break; printf(n);int getRunning()int i;for(i=0;iN;+i)if(Processi.State=Run)return i;for(i=0;iN;+i)if(Processi.Startblock=0)return i;return -1;void sort()int i,j,k;for(i=0;iN;+i)READYi=-1;BLOCKi=-1;for(i=0;iN;+i)if(Processi.State=Ready|Processi.State=Run) Processi.State=Ready;if(Pr

19、ocessi.Alltime=0)continue;for(j=0;jN;+j)if(READYj0)READYj=i;break;else if(Processi.Priorityj;-k)READYk=READYk-1;READYj=i;break;else if(Processi.State=Block)for(j=0;jN;+j)if(BLOCKj=ProcessBLOCKj.Blocktime) continue; elsefor(k=N-1;kj;-k)BLOCKk=BLOCKk-1;BLOCKj=i;break;int run(int time)int i,runNum;runN

20、um=READY0;if(runNum0&BLOCK0=0)ProcessrunNum.Priority-=3;ProcessrunNum.Alltime-=1;ProcessrunNum.Cputime+=1;ProcessrunNum.State=Run;for(i=0;iN;+i)if(i!=runNum)if(Processi.State=Ready)Processi.Priority+=1;else if(Processi.State=Block)Processi.Blocktime-=1;if(Processi.Blocktime=0)Processi.State=Ready;pr

21、int();if(ProcessrunNum.Alltime=0)ProcessrunNum.State=RunOut;for(i=0;iN;+i)if(RUNOUTi0=0)ProcessrunNum.Startblock-=1;if(ProcessrunNum.Startblock=0)ProcessrunNum.State=Block; ProcessrunNum.Startblock-=1;else if(BLOCK0=0)for(i=0;iN;+i)if(Processi.State=Block)Processi.Startblock=-1;Processi.Blocktime-=1

22、;if(Processi.Blocktime=0)Processi.State=Ready; print();sort();print();return 0;四,实验总结: 通过操作系统的实验,我学到了很多,我学会了学以致用,但这还不足,还应该继续努力,多动手多用脑,把知识用于实践中去,学习是无止境的,即使操作系统结课了,但我依旧会在以后的时间尽量去多学点有关操作系统的知识。实验目的:3 了解系统调用pipe( )的功能。4 掌握进程的管道通信的实现。进一步理解进程通信的基本原理实验六 使用动态分区分配方式的模拟实验目的了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态分区存储

23、管理方式及其实现过程的理解。实验内容1.用C语言分别实现采用首次适应算法和最佳适应算法的动态分区分配过程alloc()和回收过程free()。其中,空闲分区通过空闲分区链来管理:在进行内存分配时,系统优先使用空闲区低端的空间。2.假设初始状态下,可用的内存空间为640KB,并有下列的请求序列:作业1申请130KB。作业2申请60KB。作业3申请100KB。作业2释放60KB。作业4申请200KB。作业3释放100KB。作业1释放130KB。作业5申请140KB。作业6申请60KB。作业7申请50KB。作业6释放60KB。请分别采用首次适应算法和最佳适应算法,对内存块进行分配和回收,要求每次分配和回收后显示出空闲分区链的情况。【实验结果】#include stdio.; int End; int Space; struct MEMORY *next;struct WORK int ID; enum ACTIO

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1